Skip to content

Fetch related pages from Swiftype #1129

Fetch related pages from Swiftype

Fetch related pages from Swiftype #1129

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: opensource+bot@newrelic.com
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/github-push-action@v0.6.0
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)