Skip to content

Events + Community Page X contentful github workflow #2883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/update-contentful-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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);
}
Loading