Repository navigation
159 lines (141 loc) · 6.42 KB
/
Copy pathdiff.yml
File metadata and controls
159 lines (141 loc) · 6.42 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
159
on:
workflow_dispatch:
repository_dispatch:
types: [release_event]
name: Diff Data
concurrency:
group: diff-data
cancel-in-progress: false
permissions:
contents: read
jobs:
diff_data:
name: Diff and Release
runs-on: ubuntu-latest
# ncipollo/release-action creates a release + tag via GITHUB_TOKEN,
# which requires contents: write (top-level default is contents: read).
permissions:
contents: write
env:
TZ: Europe/London
steps:
- uses: clusterflick/.github/setup@main
- name: Get release tags
id: tags
run: |
set -euo pipefail
RELEASES=$(gh api repos/clusterflick/data-transformed/releases?per_page=10 \
--jq 'sort_by(.published_at) | reverse')
CURRENT=$(echo "$RELEASES" | jq -r '.[0].tag_name')
PREVIOUS=$(echo "$RELEASES" | jq -r '.[1].tag_name')
# The diff is anchored to when the current release was published rather
# than to the wall clock, so a re-run — or a run repeated months later —
# reproduces the same blob instead of quietly reclassifying everything
# that has happened since as past
CURRENT_PUBLISHED_AT=$(echo "$RELEASES" | jq -r '.[0].published_at')
echo "Current: $CURRENT ($CURRENT_PUBLISHED_AT), Previous: $PREVIOUS"
# data-transformed has published daily for years, so anything short of
# two releases means the API answered wrong rather than that there is
# nothing to diff. Treating that as "nothing to do" would make a blip
# indistinguishable from a quiet day; failing lets rerun-on-failure trigger
for value in "$CURRENT" "$PREVIOUS" "$CURRENT_PUBLISHED_AT"; do
if [ -z "$value" ] || [ "$value" = "null" ]; then
echo "::error::Expected two data-transformed releases to compare"
exit 1
fi
done
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "previous=$PREVIOUS" >> "$GITHUB_OUTPUT"
echo "current_published_at=$CURRENT_PUBLISHED_AT" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.PAT }}
- name: Download current release
uses: clusterflick/release-downloader@v3
with:
token: ${{ secrets.PAT }}
repository: "clusterflick/data-transformed"
tag: ${{ steps.tags.outputs.current }}
fileName: "*"
out-file-path: "transformed-data/current"
- name: Download previous release
uses: clusterflick/release-downloader@v3
with:
token: ${{ secrets.PAT }}
repository: "clusterflick/data-transformed"
tag: ${{ steps.tags.outputs.previous }}
fileName: "*"
out-file-path: "transformed-data/previous"
- name: Diff Data
run: npm run diff -- ${{ steps.tags.outputs.current }} ${{ steps.tags.outputs.previous }} ${{ steps.tags.outputs.current_published_at }}
# The registry carries forward from its own last publication, not from
# the previous transformed release. Absent on the first run, and whenever
# the latest release predates the registry - both leave it starting from
# whatever is showing today, which is correct rather than merely tolerable.
- name: Download previous seen registry
uses: clusterflick/release-downloader@v3
with:
token: ${{ secrets.PAT }}
repository: "clusterflick/data-diffed"
latest: true
fileName: "seen-registry.json"
out-file-path: "previous-registry"
# Downloaded separately from the seen registry: the two have different
# retention rules and different consumers, and only this one is safe for a
# backfill to rewrite.
- name: Download previous venue registry
uses: clusterflick/release-downloader@v3
with:
token: ${{ secrets.PAT }}
repository: "clusterflick/data-diffed"
latest: true
fileName: "venue-registry.json"
out-file-path: "previous-registry"
- name: Build seen registry
run: npm run registry -- ${{ steps.tags.outputs.current }}
# The diff only writes its output when something actually changed, so its
# absence is how a no-op run reports itself. The seen registry is written
# either way but rides along in the same release: a run with no changes
# has nothing departing, so the previous registry is still current and
# the next run carries forward from it.
- name: Check for changes
id: changes
run: |
if [ -f diffed-data/diffed-data.json ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "No changes between releases; skipping release."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate Tag
if: steps.changes.outputs.has_changes == 'true'
run: echo "TAG=$(TZ=Europe/London date +'%Y%m%d.%H%M%S')" >> $GITHUB_ENV
- uses: ncipollo/release-action@v1
if: steps.changes.outputs.has_changes == 'true'
id: release
with:
allowUpdates: false
artifactErrorsFailBuild: true
artifacts: "diffed-data/*"
makeLatest: true
tag: ${{ env.TAG }}
commit: main
body: |
Changes between data-transformed ${{ steps.tags.outputs.previous }} and ${{ steps.tags.outputs.current }}
⚠️ **Internal build artifact — not licensed.** This exists so the website can render its New Listings feed and RSS without recomputing the diff, and it inherits the third-party metadata the transformed releases carry. No schema guarantees; changes without notice. For data you can use, see https://clusterflick.com/data-licence
Created by job ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Output summary
if: steps.changes.outputs.has_changes == 'true'
run: |
echo "🔖 New release - ${{ steps.release.outputs.html_url }}" >> $GITHUB_STEP_SUMMARY
trigger_downstream:
name: Trigger downstream
runs-on: ubuntu-latest
needs: diff_data
if: ${{ always() && !failure() && !cancelled() }}
steps:
- name: Repository Dispatch for data-cached
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.PAT }}
repository: clusterflick/data-cached
event-type: release_event