-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (59 loc) · 2.34 KB
/
Copy pathrefresh-asset-data.yml
File metadata and controls
67 lines (59 loc) · 2.34 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
name: Refresh asset observatory data
on:
pull_request:
types:
- closed
permissions:
contents: write
jobs:
update-asset-data:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
- name: Detect dataset changes
id: changes
env:
GH_TOKEN: ${{ github.token }}
run: |
files=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path')
printf '%s\n' "$files" > changed-files.txt
echo "Files changed in #${{ github.event.pull_request.number }}:"
if [ -n "$files" ]; then
printf '%s\n' "$files"
else
echo "(none reported)"
fi
if printf '%s\n' "$files" | grep -Eq '^(apps/|data/|tools/generate-asset-report\.js)'; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
fi
- name: Skip refresh when no relevant files changed
if: steps.changes.outputs.should_run != 'true'
run: echo "No dataset or tooling changes detected; skipping asset observatory refresh."
- name: Set up Node.js
if: steps.changes.outputs.should_run == 'true'
uses: actions/setup-node@v4
with:
node-version: 20
- name: Generate asset observatory snapshot
if: steps.changes.outputs.should_run == 'true'
run: node tools/generate-asset-report.js
- name: Commit asset data update
if: steps.changes.outputs.should_run == 'true'
run: |
if git diff --quiet -- apps/asset-observatory/asset-data.js; then
echo "Asset data already up to date; nothing to commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add apps/asset-observatory/asset-data.js
git commit -m "chore: refresh asset observatory data for #${{ github.event.pull_request.number }}"
git pull --rebase origin ${{ github.event.pull_request.base.ref }}
git push origin HEAD:${{ github.event.pull_request.base.ref }}