forked from ipitio/backage
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (133 loc) · 4.88 KB
/
Copy pathupdate.yml
File metadata and controls
157 lines (133 loc) · 4.88 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
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: Capture queue handoff baseline
id: handoff
run: |
baseline=$(bash src/lib/handoff.sh 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: Check queued update freshness
id: gate
env:
GH_TOKEN: ${{ github.token }}
QUEUED_HANDOFF_BASELINE: ${{ needs.prepare.outputs.handoff_baseline }}
run: |
source src/lib/handoff.sh
if ! current_baseline=$(current_workflow_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 latest_scheduled_run_id=$(jq -r \
'[.workflow_runs[] | select(.event == "schedule" and ((.path // "") | endswith("/update.yml")))] | max_by(.id) | .id // empty' \
<<<"$runs") && active_manual_run_id=$(jq -r \
'[.workflow_runs[] | select(((.path // "") | endswith("/manual.yml")) and .status != "completed")] | max_by(.id) | .id // empty' \
<<<"$runs"); then
:
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 scheduled_update_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: Tune dpkg
if: ${{ steps.gate.outputs.run == 'true' }}
uses: abbbi/github-actions-tune@v1
- name: Set dpkg
if: ${{ steps.gate.outputs.run == 'true' }}
run: sudo rm -f /usr/local/bin/dpkg
- name: Tune apt
if: ${{ steps.gate.outputs.run == 'true' }}
uses: firebuild/apt-eatmydata-action@v1
- 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: Dry run
if: ${{ steps.gate.outputs.run == 'true' }}
id: update
run: |
set +e
docker run -v $PWD:/app --env-file <(env | grep -E '^(GITHUB|BKG_HANDOFF_)') \
ghcr.io/ipitio/backage:master \
src/update.sh bkg
code=$?
echo "updated=$code" >> "$GITHUB_OUTPUT"
exit "$code"
- name: Get date
if: ${{ steps.gate.outputs.run == 'true' }}
id: date
run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/14))" >> "$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: "v${{ steps.date.outputs.tag }}"
commit: "master"
allowUpdates: true