105 lines (94 loc) · 3.43 KB
/
fetch-swiftype-content.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Fetch Swiftype content
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1,4' # start of the day on Monday and Thursday
env:
BOT_NAME: nr-opensource-bot
BOT_EMAIL: opensource+bot@newrelic.com
NODE_OPTIONS: '--max-old-space-size=4096'
CHOKIDAR_USEPOLLING: 1
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: 12
- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Fetch related resources
run: yarn run fetch-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/swiftype-resources/
git diff-index --quiet HEAD ./src/data/swiftype-resources/ || git commit -m 'chore(related-content): updated swiftype 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/github-push-action@v0.6.0
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 - docs-website',
'unpaired translations removed'
]
},
restrictions: {
users: [],
teams: ['developer-enablement']
},
enforce_admins: true,
required_pull_request_reviews: null
})
console.log("Result:", result)