Repository navigation
157 lines (139 loc) · 7.76 KB
/
Copy pathrelease.yml
File metadata and controls
157 lines (139 loc) · 7.76 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: Release
# Publishes a GitHub Release for a version tag, carrying one asset: plugin-tracker-sdk.zip.
#
# The asset is `git archive` output, not a build -- same bytes as the source archive GitHub generates
# for the tag, repackaged under a fixed root folder and a fixed file name so the dashboard can link
# to /releases/latest/download/plugin-tracker-sdk.zip without resolving anything.
#
# WHY THIS EXISTS
#
# Nothing published this repository's tags. v1.2.0 existed on the remote with no release, so there was
# no archive for the dashboard to hand an author and tagging was a local act with no consequence
# anywhere.
#
# WHAT THIS DELIBERATELY DOES NOT DO
#
# It does not notify Packagist, because nothing needs it to. The repository is already connected
# there through Packagist's GitHub integration, which picks up a pushed tag on its own -- verified by
# resolving `composer require codexpertio/plugin-tracker-sdk:^1.2`, which locks v1.2.0. An API call
# from here would be a second, weaker copy of a hook that already works, plus two secrets to hold.
#
# WHY THERE IS NO BUILD STEP
#
# There used to be one: bin/build-dist.sh rewrote the SDK into a per-version namespace so two
# plugins could bundle different copies on one site without their class declarations colliding. That
# scoping was dropped deliberately, which leaves nothing to assemble -- .gitattributes already trims
# the archive to the runtime files (src/, views/, languages/, composer.json, LICENSE, README.md,
# autoload.php), and `git archive` is what produces both a GitHub source zip and a Composer
# --prefer-dist download. The two routes now ship identical bytes, which they never did before.
#
# THE CHECK THAT MATTERS
#
# The tag and Tracker::VERSION must agree, and this refuses to publish when they do not.
#
# The consuming dashboard picks its integration snippet from its own
# Telemetry_Provisioning::DEFAULT_SDK_VERSION and hands out this archive alongside it. When those
# disagree the failure is silent: the snippet requires autoload.php and calls the class name it
# returns, so an archive that predates a method the snippet relies on fails at a call site rather
# than at load, on somebody else's site. A mismatched publish is worse than a failed one.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to publish (e.g. v1.2.0)'
required: true
defaults:
run:
shell: bash
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout the tag
uses: actions/checkout@v5
with:
ref: ${{ github.event.inputs.tag || github.ref }}
fetch-depth: 0
- name: Refuse a tag that disagrees with Tracker::VERSION
id: version
run: |
tag="${{ github.event.inputs.tag || github.ref_name }}"
source_version="$(grep -oE "const VERSION = '[^']+'" src/Tracker.php | grep -oE "[0-9][0-9A-Za-z.+_-]*")"
if [ -z "${source_version}" ]; then
echo "::error::Could not read const VERSION from src/Tracker.php"
exit 1
fi
# The tag carries a leading v by convention; the constant does not.
if [ "${tag#v}" != "${source_version}" ]; then
echo "::error::Tag ${tag} does not match Tracker::VERSION ${source_version}. Publishing this would hand consumers an archive whose version the integration snippet does not expect, and that failure is silent -- see the header."
exit 1
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "Tag ${tag} agrees with Tracker::VERSION ${source_version}"
# autoload.php is the one file a consumer cannot integrate without: the snippet requires it and
# calls the class name it returns. It used to be generated by the build, so a release without it
# is exactly the regression this move could introduce -- checked here rather than discovered by
# the first author who unzips it.
- name: Refuse an archive that a consumer cannot integrate
run: |
# Listed once into a file, then grepped, rather than re-piped per path.
#
# The pipe was wrong, not just wasteful. This step runs under `set -o pipefail`, and
# `grep -q` exits the moment it matches -- which hands `tar` a SIGPIPE, fails the pipeline,
# and reports a file as ABSENT precisely when it is PRESENT. The first run of this workflow
# flagged composer.json that way while correctly flagging autoload.php, which is how a guard
# earns the wrong kind of reputation.
git archive --format=tar HEAD > /tmp/release-archive.tar
tar -tf /tmp/release-archive.tar > /tmp/release-archive.list
missing=0
# The views are the ones whose absence is FATAL rather than quiet: they are `include`d
# from disk, not autoloaded, and the consent prompt's include runs on a site owner's
# admin screen. .gitattributes warns about exactly this; nothing checked it.
for path in autoload.php src/Tracker.php composer.json \
views/consent/prompt.php views/consent/server-notice.php \
views/feedback/modal.php views/feedback/behaviour.php \
languages/plugin-tracker-sdk.pot; do
if ! grep -qx -- "${path}" /tmp/release-archive.list; then
echo "::error::${path} is absent from the release archive. Check .gitattributes -- export-ignore governs what git archive emits, and it is what GitHub serves."
missing=1
fi
done
[ "${missing}" -eq 0 ] || exit 1
echo "Archive carries autoload.php, src/Tracker.php and composer.json"
# One asset, with a STABLE name, and that is the whole point of it.
#
# GitHub's own source archives cannot be fetched from a fixed address: the only stable download
# URL it offers is /releases/latest/download/<asset-name>, and that serves uploaded assets only.
# Publishing one asset under an unchanging name gives the dashboard a URL it can hard-code --
# no API call to resolve a tag, no JSON to parse, no rate limit to think about, and no cache to
# invalidate.
#
# It also fixes the folder name, which the source archive gets wrong for our purposes. GitHub
# names its archive's root after the repository AND tag (plugin-tracker-sdk-1.2.0/), while the
# integration snippet requires plugin-tracker-sdk/ -- so every author had to rename the folder
# after unzipping, a step people miss and one that 1.1.0 had already removed once. `git archive
# --prefix` sets it directly, and honours .gitattributes exactly as the source archive does, so
# the contents are identical and only the root differs.
- name: Package the archive under a stable name
run: |
git archive --format=zip --prefix=plugin-tracker-sdk/ -o plugin-tracker-sdk.zip HEAD
echo "Packaged $(unzip -Z1 plugin-tracker-sdk.zip | wc -l) entries under plugin-tracker-sdk/"
# Idempotent on purpose: re-running for an existing tag replaces the asset rather than failing,
# which is what makes workflow_dispatch a usable recovery path when a publish half-succeeded.
- name: Publish the release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
if gh release view "${TAG}" >/dev/null 2>&1; then
echo "Release ${TAG} exists; replacing its asset."
gh release upload "${TAG}" plugin-tracker-sdk.zip --clobber
else
gh release create "${TAG}" plugin-tracker-sdk.zip --title "${TAG}" --generate-notes
fi
echo "Stable download: https://github.com/${GITHUB_REPOSITORY}/releases/latest/download/plugin-tracker-sdk.zip"