Repository navigation
92 lines (81 loc) · 3.25 KB
/
Copy pathsync-github.yml
File metadata and controls
92 lines (81 loc) · 3.25 KB
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
name: Sync GitHub
on:
schedule:
- cron: '25 21,03,11 * * *'
pull_request: # a dry run, which reports what would change in the data
paths:
- 'tools/sync/**'
- 'src/data/**'
- 'src/absent.js'
- 'src/persistable-cache.js'
- '.github/workflows/sync-github.yml'
workflow_dispatch:
defaults:
run:
shell: bash
concurrency:
group: uses-github-api # share the group with the site build, so they do not fight for the github rate limit
jobs:
sync:
if: github.repository == 'quarkusio/extensions' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write # to commit the synced data
steps:
# Pushes made with the default GITHUB_TOKEN do not trigger other workflows, so committing the data does not start a site build;
# the scheduled site builds pick the data up
- uses: actions/checkout@v6
with:
ref: ${{ github.event_name != 'pull_request' && 'main' || '' }}
- name: Restoring cached GitHub API results
uses: actions/cache/restore@v5
with:
path: |
.cache-github-api
key: sync-github-queries-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: | # the second prefix lets the first run pick up the cache the site build used to save
sync-github-queries-
gatsby-build-github-queries-
- uses: actions/setup-node@v6
with:
node-version: '18'
cache: "npm"
- run: npm ci --prefer-offline
- name: Run sync
run: npm run sync:github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Dry runs on pull requests read the cache but never write one, as the cache is large
- name: Caching GitHub API results
if: github.event_name != 'pull_request'
uses: actions/cache/save@v5
with:
path: |
.cache-github-api
key: sync-github-queries-${{ github.run_id }}-${{ github.run_attempt }}
- name: Show dry-run diff
if: github.event_name == 'pull_request'
run: |
# New files are invisible to git diff until they are known to git
# (the directory may not exist, if the sync was skipped)
if [ -d data/synced ]; then git add --intent-to-add data/synced/; fi
{
echo "### Dry run: changes that would be committed"
echo '```diff'
git diff --stat -- data/synced/
# head closes the pipe early on a big diff, which makes git diff fail with SIGPIPE, so ignore the exit code
git diff -- data/synced/ | head -n 500 || true
git diff --quiet -- data/synced/ && echo "No changes to the data."
echo '```'
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Commit and push
if: github.event_name != 'pull_request'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add data/synced/source-control-info.json data/synced/contributing-companies.json
if [ -n "$(git status --porcelain)" ]; then
git commit -m "Sync GitHub data"
git pull origin main --rebase
git push origin main
fi