-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (70 loc) · 2.79 KB
/
Copy pathrefresh.yml
File metadata and controls
79 lines (70 loc) · 2.79 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
name: refresh
# This job publishes the file everything else reads, so it is pinned by commit
# SHA and holds no permission beyond writing this repository.
on:
schedule:
# Every six hours. GitHub runs scheduled workflows on a best-effort basis
# and delays them under load; nothing here depends on the exact minute.
- cron: "17 */6 * * *"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: refresh
cancel-in-progress: false
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# A push authenticated with GITHUB_TOKEN does not count as repository
# activity for the 60-day scheduled-workflow cutoff, so the schedule
# would eventually switch itself off. REFRESH_TOKEN is a fine-grained
# PAT with contents:write on this repository only; without it the job
# still works and the keepalive step below warns.
token: ${{ secrets.REFRESH_TOKEN || github.token }}
fetch-depth: 0
- name: Show tool versions
run: node --version
- name: Test the transform
run: node --test scripts/*.test.mjs
- name: Generate
run: node scripts/generate.mjs
- name: Keep the schedule alive
# GitHub disables scheduled workflows after 60 days without repository
# activity. Prices can plausibly sit unchanged for longer than that, so
# a commit-free stretch is refreshed deliberately rather than left to
# chance.
env:
# Only whether the secret is set crosses into the shell, never its
# value.
HAS_REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN != '' }}
run: |
if [ "$HAS_REFRESH_TOKEN" != "true" ]; then
echo "::warning::REFRESH_TOKEN is unset; pushes will not reset the 60-day scheduled-workflow cutoff"
fi
last=$(git log -1 --format=%ct)
age=$(( ( $(date +%s) - last ) / 86400 ))
echo "days since last commit: $age"
if [ "$age" -ge 20 ]; then
date -u +%Y-%m-%dT%H:%M:%SZ > .keepalive
fi
- name: Commit
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "nothing to publish"
exit 0
fi
git config user.name "model-prices[bot]"
git config user.email "noreply@cloudstack.llc"
git add -A
# A keepalive-only run must not claim prices moved; the history is
# read as a price-change log.
if git diff --cached --quiet -- v1; then
git commit -m "chore: keep the refresh schedule alive"
else
git commit -m "chore: refresh prices from models.dev"
fi
git push