Files
xrpl-dev-portal/.github/workflows/update-contentful-data.yml

80 lines
2.6 KiB
YAML

name: Update Contentful Data
on:
repository_dispatch:
types: [contentful_update]
jobs:
update-data:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install Dependencies
run: npm install
- name: Set Branch Name with Date
id: set-branch-name
run: echo "BRANCH_NAME=contentful-updates-$(date +'%Y-%m-%d-%H-%M')" >> $GITHUB_ENV
- name: Fetch Data from Contentful
env:
CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}
CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
run: node scripts/fetchContentfulData.cjs
- name: Check for changes
id: check_changes
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "no_changes=true" >> $GITHUB_OUTPUT
else
echo "no_changes=false" >> $GITHUB_OUTPUT
fi
- name: No changes found
if: steps.check_changes.outputs.no_changes == 'true'
run: echo "No changes found. Skipping commit and pull request steps."
- name: Commit and Push Changes
if: steps.check_changes.outputs.no_changes == 'false'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Update data from Contentful'
branch: ${{ env.BRANCH_NAME }}
create_branch: true
- name: Create Pull Request
if: steps.check_changes.outputs.no_changes == 'false'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: existingPulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${process.env.BRANCH_NAME}`,
state: 'open',
});
if (existingPulls.length === 0) {
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: process.env.BRANCH_NAME,
base: 'master',
title: 'Update data from Contentful',
body: 'Automated update of data from Contentful.',
});
console.log(`Pull request created: ${pullRequest.html_url}`);
} else {
console.log('Pull request already exists:', existingPulls[0].html_url);
}