Fetch related pages from Swiftype #1097
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Fetch related pages from Swiftype | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' # start of every day | |
env: | |
BOT_NAME: nr-opensource-bot | |
BOT_EMAIL: [email protected] | |
jobs: | |
fetch-swiftype-results: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
- name: Setup node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 17 | |
cache: 'yarn' | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Gatsby Build | |
run: yarn run build:related-content | |
- name: Temporarily disable branch protection | |
id: disable-branch-protection | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.DEVEX_OPENSOURCE_BOT_TOKEN }} | |
previews: luke-cage-preview | |
script: | | |
const result = await github.rest.repos.updateBranchProtection({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
branch: 'main', | |
required_status_checks: null, | |
restrictions: null, | |
enforce_admins: null, | |
required_pull_request_reviews: null | |
}) | |
console.log("Result:", result) | |
- name: Commit changes | |
id: commit-changes | |
run: | | |
git config --local user.email "${{ env.BOT_EMAIL }}" | |
git config --local user.name "${{ env.BOT_NAME }}" | |
git add ./src/data/related-pages.json | |
git commit -m 'chore(related-content): updated related content data' | |
echo "commit=true" >> $GITHUB_OUTPUT | |
# Push directly to `main` branch because we want updates to the related | |
# content to trigger a deploy. If we commit directly to the `develop` | |
# branch, it would require a PR from the team to deploy the changes. | |
- name: Push Commit | |
if: steps.commit-changes.outputs.commit == 'true' | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.DEVEX_OPENSOURCE_BOT_TOKEN }} | |
branch: main | |
- name: Re-enable branch protection | |
id: enable-branch-protection | |
if: always() | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.DEVEX_OPENSOURCE_BOT_TOKEN }} | |
previews: luke-cage-preview | |
script: | | |
const result = await github.rest.repos.updateBranchProtection({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
branch: 'main', | |
required_status_checks: { | |
strict: false, | |
contexts: [ | |
'Gatsby Build Service - developer-website' | |
] | |
}, | |
restrictions: null, | |
enforce_admins: true, | |
required_pull_request_reviews: null | |
}) | |
console.log("Result:", result) |