This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78949fa
commit b7e07e9
Showing
2 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
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@v2 | ||
with: | ||
ref: main | ||
|
||
- name: Setup node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- uses: actions/cache@v2 | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-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@v1 | ||
with: | ||
github-token: ${{ secrets.OPENSOURCE_BOT_TOKEN }} | ||
previews: luke-cage-preview | ||
script: | | ||
const result = await github.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 "::set-output name=commit::true" | ||
# 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.OPENSOURCE_BOT_TOKEN }} | ||
branch: main | ||
|
||
- name: Re-enable branch protection | ||
id: enable-branch-protection | ||
if: always() | ||
uses: actions/github-script@v1 | ||
with: | ||
github-token: ${{ secrets.OPENSOURCE_BOT_TOKEN }} | ||
previews: luke-cage-preview | ||
script: | | ||
const result = await github.repos.updateBranchProtection({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
branch: 'main', | ||
required_status_checks: { | ||
strict: false, | ||
contexts: [ | ||
'Gatsby Build Service - instant-observability-website' | ||
] | ||
}, | ||
restrictions: null, | ||
enforce_admins: true, | ||
required_pull_request_reviews: { | ||
dismiss_stale_reviews: true, | ||
required_approving_review_count: 1 | ||
} | ||
}) | ||
console.log("Result:", result) |
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