Skip to content

Commit f8f6e32

Browse files
committed
GH Actions: automate release verification steps
While the actual releasing can not be fully automated (due to security concerns related to signing releases in a GHA workflow), there are a number of verification checks which are part of the release workflow, which _can_ be automated. These checks were previously done as manual spot-checks. With the new workflow, they will now be executed structurally and automatically whenever a release is published on GitHub. The checks which are automated via this workflow are as follows: * For the PHAR files which can be downloaded from the GH "releases" page, the (unversioned) PHAR files published on the GH Pages website and the versioned PHAR files published on the GH Pages website for Phive (but which can also be downloaded manually), the following checks will now be run automatically: - Is the PHAR file available and can it be downloaded ? - Is the ASC (detached signature) file available and can it be downloaded ? - Verify the PHAR file via the attestation (which was created when the PHAR was created for a tag). - Verify the PHAR file is GPG signed and the signature matches. - Verify the PHAR file is functional (simple command runs without problems). - Verify the version with which the PHAR file identifies itself is the expected version. * For Phive: - Install via Phive. This will automatically also check the PHAR file is signed and the signature matches. - Verify the Phive installed PHAR file via the attestation. - Verify the Phive installed PHAR file is functional (simple command runs without problems). - Verify the version with which the PHAR file identifies itself is the expected version.
1 parent 0d969c9 commit f8f6e32

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Verify release
2+
3+
on:
4+
# Run whenever a release is published.
5+
release:
6+
types: [published]
7+
# And whenever this workflow is updated.
8+
push:
9+
paths:
10+
- '.github/workflows/verify-release.yml'
11+
# And whenever this workflow is updated.
12+
pull_request:
13+
paths:
14+
- '.github/workflows/verify-release.yml'
15+
# Allow manually triggering the workflow.
16+
workflow_dispatch:
17+
18+
# Cancels all previous workflow runs for the same branch that have not yet completed.
19+
concurrency:
20+
# The concurrency group contains the workflow name and the branch name.
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
##################################################################################
26+
# Verify the release is available in all the right places and works as expected. #
27+
##################################################################################
28+
verify-available-downloads:
29+
runs-on: ubuntu-latest
30+
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
download_flavour:
35+
- "Release assets"
36+
- "Unversioned web"
37+
- "Versioned web"
38+
pharfile:
39+
- 'phpcs'
40+
- 'phpcbf'
41+
42+
name: "${{ matrix.download_flavour }}: ${{ matrix.pharfile }}"
43+
44+
steps:
45+
- name: Retrieve latest release info
46+
uses: octokit/[email protected]
47+
id: get_latest_release
48+
with:
49+
route: GET /repos/PHPCSStandards/PHP_CodeSniffer/releases/latest
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: "DEBUG: Show API request failure status"
54+
if: ${{ failure() }}
55+
run: "echo No release found. Request failed with status ${{ steps.get_latest_release.outputs.status }}"
56+
57+
- name: Grab latest tag name from API response
58+
id: version
59+
run: |
60+
echo "TAG=${{ fromJson(steps.get_latest_release.outputs.data).tag_name }}" >> "$GITHUB_OUTPUT"
61+
62+
- name: "DEBUG: Show tag name found in API response"
63+
run: "echo ${{ steps.version.outputs.TAG }}"
64+
65+
- name: Set source URL and file name
66+
id: source
67+
shell: bash
68+
run: |
69+
if [[ "${{ matrix.download_flavour }}" == "Release assets" ]]; then
70+
echo 'SRC=https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/latest/download/' >> "$GITHUB_OUTPUT"
71+
echo "FILE=${{ matrix.pharfile }}.phar" >> "$GITHUB_OUTPUT"
72+
elif [[ "${{ matrix.download_flavour }}" == "Unversioned web" ]]; then
73+
echo 'SRC=https://phars.phpcodesniffer.com/' >> "$GITHUB_OUTPUT"
74+
echo "FILE=${{ matrix.pharfile }}.phar" >> "$GITHUB_OUTPUT"
75+
else
76+
echo 'SRC=https://phars.phpcodesniffer.com/phars/' >> "$GITHUB_OUTPUT"
77+
echo "FILE=${{ matrix.pharfile }}-${{ steps.version.outputs.TAG }}.phar" >> "$GITHUB_OUTPUT"
78+
fi
79+
80+
- name: Verify PHAR file is available and download
81+
run: "wget -O ${{ steps.source.outputs.FILE }} ${{ steps.source.outputs.SRC }}${{ steps.source.outputs.FILE }}"
82+
83+
- name: Verify signature file is available and download
84+
run: "wget -O ${{ steps.source.outputs.FILE }}.asc ${{ steps.source.outputs.SRC }}${{ steps.source.outputs.FILE }}.asc"
85+
86+
- name: "DEBUG: List files"
87+
run: ls -Rlh
88+
89+
- name: Verify attestation of the PHAR file
90+
run: gh attestation verify ${{ steps.source.outputs.FILE }} -o PHPCSStandards
91+
env:
92+
GH_TOKEN: ${{ github.token }}
93+
94+
- name: Download public key
95+
env:
96+
FINGERPRINT: "0x689DAD778FF08760E046228BA978220305CD5C32"
97+
run: gpg --keyserver "hkps://keys.openpgp.org" --recv-keys "$FINGERPRINT"
98+
99+
- name: Verify signature of the PHAR file
100+
run: gpg --verify ${{ steps.source.outputs.FILE }}.asc ${{ steps.source.outputs.FILE }}
101+
102+
- name: Setup PHP
103+
uses: shivammathur/setup-php@v2
104+
with:
105+
php-version: 'latest'
106+
ini-values: error_reporting=-1, display_errors=On
107+
coverage: none
108+
109+
# Note: the `.` is in the command to make it work for both PHPCS as well PHPCBF.
110+
- name: Verify the PHAR is nominally functional
111+
run: php ${{ steps.source.outputs.FILE }} . -e --standard=PSR12
112+
113+
- name: Grab the version
114+
id: asset_version
115+
env:
116+
FILE_NAME: ${{ steps.source.outputs.FILE }}
117+
# yamllint disable-line rule:line-length
118+
run: echo "VERSION=$(php "$FILE_NAME" --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+(\.[0-9]+)+')" >> "$GITHUB_OUTPUT"
119+
120+
- name: "DEBUG: Show grabbed version"
121+
run: echo ${{ steps.asset_version.outputs.VERSION }}
122+
123+
- name: Fail the build if the PHAR is not the correct version
124+
if: ${{ steps.asset_version.outputs.VERSION != steps.version.outputs.TAG }}
125+
run: exit 1
126+
127+
# #########################################
128+
# Verify install via PHIVE.
129+
# #########################################
130+
verify-phive:
131+
runs-on: ubuntu-latest
132+
133+
strategy:
134+
fail-fast: false
135+
matrix:
136+
pharfile:
137+
- 'phpcs'
138+
- 'phpcbf'
139+
140+
name: "PHIVE: ${{ matrix.pharfile }}"
141+
142+
steps:
143+
- name: Retrieve latest release info
144+
uses: octokit/[email protected]
145+
id: get_latest_release
146+
with:
147+
route: GET /repos/PHPCSStandards/PHP_CodeSniffer/releases/latest
148+
env:
149+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150+
151+
- name: "DEBUG: Show API request failure status"
152+
if: ${{ failure() }}
153+
run: "echo No release found. Request failed with status ${{ steps.get_latest_release.outputs.status }}"
154+
155+
- name: Grab latest tag name from API response
156+
id: version
157+
run: |
158+
echo "TAG=${{ fromJson(steps.get_latest_release.outputs.data).tag_name }}" >> "$GITHUB_OUTPUT"
159+
160+
- name: "DEBUG: Show tag name found in API response"
161+
run: "echo ${{ steps.version.outputs.TAG }}"
162+
163+
- name: Setup PHP
164+
uses: shivammathur/setup-php@v2
165+
with:
166+
php-version: 'latest'
167+
ini-values: error_reporting=-1, display_errors=On
168+
coverage: none
169+
tools: phive
170+
171+
- name: Install
172+
run: phive install ${{ matrix.pharfile }} --copy --trust-gpg-keys 689DAD778FF08760E046228BA978220305CD5C32
173+
174+
- name: "DEBUG: List files"
175+
run: ls -R
176+
177+
- name: Verify attestation of the PHAR file
178+
run: gh attestation verify ./tools/${{ matrix.pharfile }} -o PHPCSStandards
179+
env:
180+
GH_TOKEN: ${{ github.token }}
181+
182+
# Note: the `.` is in the command to make it work for both PHPCS as well PHPCBF.
183+
- name: Verify the PHAR is nominally functional
184+
run: php ./tools/${{ matrix.pharfile }} . -e --standard=PSR12
185+
186+
- name: Grab the version
187+
id: asset_version
188+
env:
189+
FILE_NAME: ./tools/${{ matrix.pharfile }}
190+
# yamllint disable-line rule:line-length
191+
run: echo "VERSION=$(php "$FILE_NAME" --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+(\.[0-9]+)+')" >> "$GITHUB_OUTPUT"
192+
193+
- name: "DEBUG: Show grabbed version"
194+
run: echo ${{ steps.asset_version.outputs.VERSION }}
195+
196+
- name: Fail the build if the PHAR is not the correct version
197+
if: ${{ steps.asset_version.outputs.VERSION != steps.version.outputs.TAG }}
198+
run: exit 1

0 commit comments

Comments
 (0)