-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (99 loc) · 4.16 KB
/
Copy pathdiff.yml
File metadata and controls
111 lines (99 loc) · 4.16 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
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: |
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" >> "$GITHUB_OUTPUT"
echo "previous=$PREVIOUS" >> "$GITHUB_OUTPUT"
echo "current_published_at=$CURRENT_PUBLISHED_AT" >> "$GITHUB_OUTPUT"
echo "Current: $CURRENT ($CURRENT_PUBLISHED_AT), Previous: $PREVIOUS"
# The very first release has nothing to be diffed against
if [ -z "$PREVIOUS" ] || [ "$PREVIOUS" = "null" ]; then
echo "No previous release to diff against. Skipping."
echo "has_previous=false" >> "$GITHUB_OUTPUT"
else
echo "has_previous=true" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.PAT }}
- name: Download current release
if: steps.tags.outputs.has_previous == 'true'
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
if: steps.tags.outputs.has_previous == 'true'
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
if: steps.tags.outputs.has_previous == 'true'
run: npm run diff -- ${{ steps.tags.outputs.current }} ${{ steps.tags.outputs.previous }} ${{ steps.tags.outputs.current_published_at }}
# The diff only writes its output when something actually changed, so its
# absence is how a no-op run reports itself.
- 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 }}
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