forked from ipitio/backage
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (136 loc) · 4.91 KB
/
Copy pathupdate.yml
File metadata and controls
158 lines (136 loc) · 4.91 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: update
on:
schedule:
- cron: "0 0 * * *"
defaults:
run:
# GitHub Actions run without a TTY device. This is a workaround to get one,
# based on https://github.com/actions/runner/issues/241#issuecomment-2019042651
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_OWNER: ${{ github.repository_owner }}
GITHUB_REPO: ${{ github.event.repository.name }}
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
BKG_HANDOFF_CONTROL_REF: refs/heads/bkg-control
BKG_HANDOFF_POLL_SECONDS: 60
jobs:
prepare:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
handoff_baseline: ${{ steps.handoff.outputs.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Capture queue handoff baseline
id: handoff
run: |
baseline=$(PYTHONPATH=src python -m bkg_py handoff baseline)
echo "sha=$baseline" >> "$GITHUB_OUTPUT"
update:
needs: prepare
runs-on: ubuntu-latest
concurrency:
group: ${{ github.repository }}-database-publication
cancel-in-progress: false
queue: max
permissions:
actions: read
contents: write
packages: read
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Check queued update freshness
id: gate
env:
GH_TOKEN: ${{ github.token }}
QUEUED_HANDOFF_BASELINE: ${{ needs.prepare.outputs.handoff_baseline }}
run: |
if ! current_baseline=$(PYTHONPATH=src python -m bkg_py handoff baseline); then
echo "Could not refresh the handoff baseline; allowing this serialized update" >&2
current_baseline=$QUEUED_HANDOFF_BASELINE
fi
latest_scheduled_run_id=
active_manual_run_id=
if runs=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs?per_page=100"); then
if freshness=$(PYTHONPATH=src python -m bkg_py handoff workflow-runs <<<"$runs"); then
IFS='|' read -r latest_scheduled_run_id active_manual_run_id \
<<<"$freshness"
else
echo "Could not parse workflow freshness; allowing this serialized update" >&2
latest_scheduled_run_id=
active_manual_run_id=
fi
else
echo "Could not read workflow freshness; allowing this serialized update" >&2
fi
run_update=false
if PYTHONPATH=src python -m bkg_py handoff should-run \
"$QUEUED_HANDOFF_BASELINE" \
"$current_baseline" \
"$GITHUB_RUN_ID" \
"$latest_scheduled_run_id" \
"$active_manual_run_id"; then
run_update=true
fi
echo "run=$run_update" >> "$GITHUB_OUTPUT"
- name: Check for release
if: ${{ steps.gate.outputs.run == 'true' }}
id: release
continue-on-error: true
uses: cardinalby/git-get-release-action@v1
with:
latest: true
- name: Fetch all data
if: ${{ steps.gate.outputs.run == 'true' && steps.release.outcome == 'success' }}
continue-on-error: true
uses: robinraju/release-downloader@v1
with:
latest: true
fileName: "*.db"
tarBall: false
zipBall: false
out-file-path: ".bkg/.snapshot"
- name: Update
if: ${{ steps.gate.outputs.run == 'true' }}
id: update
run: |
set +e
run_date=$(date -u +%F)
docker run -v $PWD:/app -v /var/run/docker.sock:/var/run/docker.sock \
-e BKG_DOCKER_SIZE_FALLBACK=true \
--env-file <(env | grep -E '^(GITHUB|BKG_HANDOFF_)') \
ghcr.io/ipitio/backage:master \
bkg workflow-update -C /app -D "$run_date"
code=$?
echo "updated=$code" >> "$GITHUB_OUTPUT"
echo "run_date=$run_date" >> "$GITHUB_OUTPUT"
exit "$code"
- name: Get date
if: ${{ steps.gate.outputs.run == 'true' }}
id: date
env:
RUN_DATE: ${{ steps.update.outputs.run_date }}
run: |
release_tag=$(PYTHONPATH=src python -m bkg_py release-tag -D "$RUN_DATE")
echo "tag=$release_tag" >> "$GITHUB_OUTPUT"
- name: Save database
if: ${{ steps.gate.outputs.run == 'true' && steps.update.outputs.updated == '0' }}
uses: ncipollo/release-action@v1
with:
artifacts: "bkg/.snapshot/*"
bodyFile: "bkg/CHANGELOG.md"
tag: "${{ steps.date.outputs.tag }}"
commit: "master"
allowUpdates: true