Skip to content

Commit 8f18c18

Browse files
authored
Merge pull request #139 from asgrim/consolidate-release-pipelines
Use GH attestation and organise workflows better
2 parents 3c6b6a0 + 41a9bd4 commit 8f18c18

7 files changed

Lines changed: 103 additions & 94 deletions

File tree

.github/workflows/build-phar.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Invoking this pipeline requires additional permissions, so must be invoked
2+
# in a way to pass those permissions on, e.g.:
3+
#
4+
# build-phar:
5+
# permissions:
6+
# contents: read
7+
# id-token: write
8+
# attestations: write
9+
# uses: ./.github/workflows/build-phar.yml
10+
11+
name: "Build the PIE PHAR"
12+
13+
on:
14+
workflow_call:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
build-phar:
21+
runs-on: ${{ matrix.operating-system }}
22+
strategy:
23+
matrix:
24+
operating-system:
25+
- ubuntu-latest
26+
php-versions:
27+
- '8.1'
28+
permissions:
29+
# id-token:write is required for build provenance attestation.
30+
id-token: write
31+
# attestations:write is required for build provenance attestation.
32+
attestations: write
33+
steps:
34+
- name: Setup PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
coverage: none
38+
tools: composer, box
39+
php-version: "${{ matrix.php-version }}"
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
# Ensure some kind of previous tag exists, otherwise box fails
44+
- run: git describe --tags HEAD || git tag 0.0.0
45+
- uses: ramsey/composer-install@v3
46+
- name: Build PHAR
47+
run: box compile
48+
- name: Check the PHAR executes
49+
run: php pie.phar --version
50+
- name: Generate build provenance attestation
51+
# It does not make sense to do this for PR builds, nor do contributors
52+
# have permission to do. We can't write attestations to `php/pie` in an
53+
# unprivileged context, otherwise anyone could send a PR with malicious
54+
# code, which would store attestation that `php/pie` built the PHAR, and
55+
# it would look genuine. So this should NOT run for PR builds.
56+
if: github.event_name != 'pull_request'
57+
uses: actions/attest-build-provenance@v1
58+
with:
59+
subject-path: '${{ github.workspace }}/pie.phar'
60+
- uses: actions/upload-artifact@v4
61+
with:
62+
name: pie-${{ github.sha }}.phar
63+
path: pie.phar

.github/workflows/continuous-integration.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ jobs:
109109
- unit-tests
110110
- coding-standards
111111
- static-analysis
112-
uses: ./.github/workflows/release-unsigned-phar.yml
112+
# See build-phar.yml for a list of the permissions and why they are needed
113+
permissions:
114+
contents: read
115+
id-token: write
116+
attestations: write
117+
uses: ./.github/workflows/build-phar.yml

.github/workflows/docs.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ concurrency:
1919

2020
jobs:
2121
build-phar:
22-
uses: ./.github/workflows/release-unsigned-phar.yml
22+
# See build-phar.yml for a list of the permissions and why they are needed
23+
permissions:
24+
contents: read
25+
id-token: write
26+
attestations: write
27+
uses: ./.github/workflows/build-phar.yml
2328

24-
# Build job
25-
build:
29+
build-docs-package:
2630
runs-on: ubuntu-latest
2731
needs:
2832
- build-phar
@@ -35,20 +39,23 @@ jobs:
3539
uses: actions/download-artifact@v4
3640
with:
3741
name: pie-${{ github.sha }}.phar
42+
- name: Verify the PHAR
43+
env:
44+
GH_TOKEN: ${{ github.token }}
45+
run: gh attestation verify pie.phar --repo ${{ github.repository }}
3846
- name: Copy PHAR into docs
3947
run: cp pie.phar docs-package/pie-nightly.phar
4048
- name: Upload artifact
4149
uses: actions/upload-pages-artifact@v3
4250
with:
4351
path: docs-package
4452

45-
# Deployment job
4653
deploy:
4754
environment:
4855
name: github-pages
4956
url: ${{ steps.deployment.outputs.page_url }}
5057
runs-on: ubuntu-latest
51-
needs: build
58+
needs: build-docs-package
5259
permissions:
5360
contents: read
5461
# pages:write is required to deploy to GitHub pages.

.github/workflows/release-unsigned-phar.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Release"
1+
name: "Publish the PHAR for Releases"
22

33
on:
44
release:
@@ -9,58 +9,32 @@ permissions:
99
contents: read
1010

1111
jobs:
12+
build-phar:
13+
# See build-phar.yml for a list of the permissions and why they are needed
14+
permissions:
15+
contents: read
16+
id-token: write
17+
attestations: write
18+
uses: ./.github/workflows/build-phar.yml
19+
1220
release-phar:
13-
runs-on: ${{ matrix.operating-system }}
14-
strategy:
15-
matrix:
16-
operating-system:
17-
- ubuntu-latest
18-
php-versions:
19-
- '8.1'
21+
runs-on: ubuntu-latest
22+
needs:
23+
- build-phar
2024
permissions:
2125
# contents:write is required to upload the binaries to the release.
2226
contents: write
23-
# id-token:write is required for build provenance attestation.
24-
id-token: write
25-
# attestations:write is required for build provenance attestation.
26-
attestations: write
2727
steps:
28-
- name: Setup PHP
29-
uses: shivammathur/setup-php@v2
30-
with:
31-
coverage: none
32-
tools: composer, box
33-
php-version: "${{ matrix.php-version }}"
34-
- uses: actions/checkout@v4
35-
with:
36-
fetch-depth: 0
37-
- uses: ramsey/composer-install@v3
38-
- name: Build PHAR
39-
run: box compile
40-
- name: Check the PHAR executes
41-
run: php pie.phar --version
42-
- name: Import GPG key
43-
uses: crazy-max/ghaction-import-gpg@v6
44-
with:
45-
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
46-
passphrase: ${{ secrets.GPG_SIGNING_KEY_PASSPHRASE }}
47-
- name: Sign the PHAR
48-
run: |
49-
gpg --local-user asgrim+pie-releases@php.net \
50-
--batch \
51-
--yes \
52-
--passphrase="${{ secrets.GPG_SIGNING_KEY_PASSPHRASE }}" \
53-
--detach-sign \
54-
--output pie.phar.asc \
55-
pie.phar
56-
- name: Generate build provenance attestation
57-
uses: actions/attest-build-provenance@v1
28+
- name: Fetch built PHAR from artifacts
29+
uses: actions/download-artifact@v4
5830
with:
59-
subject-path: '${{ github.workspace }}/pie.phar'
31+
name: pie-${{ github.sha }}.phar
32+
- name: Verify the PHAR
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
run: gh attestation verify pie.phar --repo ${{ github.repository }}
6036
- name: Upload binaries to release
6137
uses: softprops/action-gh-release@v2
6238
if: ${{startsWith(github.ref, 'refs/tags/') }}
6339
with:
64-
files: |
65-
pie.phar
66-
pie.phar.asc
40+
files: pie.phar

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ please read [extension-maintainers](./docs/extension-maintainers.md).
1313
- Download `pie.phar` either:
1414
- [latest stable release](https://github.com/php/pie/releases)
1515
- [latest unstable nightly](https://php.github.io/pie/pie-nightly.phar)
16-
- Validate the signature in `pie.phar.asc`
16+
- Verify the PHAR's source with `gh attestation verify pie.phar --repo php/pie`
1717
- You may then invoke PIE with `php pie.phar <command>`
1818

1919
Further installation details can be found in the [usage](./docs/usage.md) docs.

docs/usage.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ order: 2
99
### Manual installation
1010

1111
- Download `pie.phar` from the [latest releases](https://github.com/php/pie/releases)
12-
- Validate the signature in `pie.phar.asc`
13-
- You can fetch the public key with `gpg --recv-key 343F8427AD6B48FF`
14-
- Then you can verify the release with `gpg --verify pie.phar.asc pie.phar`
12+
- Verify the PHAR's source with `gh attestation verify pie.phar --repo php/pie`
1513
- You may then invoke PIE with `php pie.phar <command>`
1614
- Optionally, copy `pie.phar` into your `$PATH`, e.g. `cp pie.phar /usr/local/bin/pie`
1715
- If you copy PIE into your `$PATH`, you may then invoke PIE with `pie <command>`

0 commit comments

Comments
 (0)