Skip to content

Commit 3cee266

Browse files
committed
Add support for immutable releases
1 parent 5286a4d commit 3cee266

File tree

6 files changed

+267
-13
lines changed

6 files changed

+267
-13
lines changed

README.md

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This project provides PowerShell packages and GitHub Actions to build PHP and it
1616
- [PHP Version Support](#php-version-support)
1717
- [Release](#release)
1818
- [Inputs](#inputs-3)
19-
- [Example workflow to build and release an extension](#example-workflow-to-build-and-release-an-extension)
19+
- [Example workflow for non-immutable releases](#example-workflow-for-non-immutable-releases)
20+
- [Example workflow for immutable releases](#example-workflow-for-immutable-releases)
2021

2122
- [Local Setup](#local-setup)
2223
- [PHP](#php)
@@ -180,10 +181,14 @@ Upload the artifacts to a release.
180181

181182
#### Inputs
182183

183-
- `release` (required) - The release to upload the artifacts.
184-
- `token` (required) - The GitHub token to authenticate with.
184+
- `release` (required) - The release/tag to upload the artifacts.
185+
- `token` (optional) - The GitHub token to authenticate with. Defaults to `GITHUB_TOKEN` secret.
186+
- `draft` (optional) - Whether to create a draft release if the release does not exist. Defaults to `false`.
185187

186-
#### Example workflow to build and release an extension
188+
#### Example workflow for non-immutable releases
189+
190+
Follow this if you are creating the release and they are not immutable (This is the default).
191+
For non-immutable releases, you can publish them, and the workflow will upload the extension builds to the release.
187192

188193
```yaml
189194
name: Build extension
@@ -195,10 +200,8 @@ on:
195200
# create: # Uncomment this to run on tag/branch creation
196201
# pull_request: # Uncomment this to run on pull requests
197202
198-
# This may be needed to be able to upload the assets to the release
199-
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
200-
#permissions:
201-
# contents: write
203+
permissions:
204+
contents: write
202205
203206
jobs:
204207
# This job generates a matrix of PHP versions, architectures, and thread safety options
@@ -248,6 +251,75 @@ jobs:
248251
token: ${{ secrets.GITHUB_TOKEN }}
249252
```
250253

254+
#### Example workflow for immutable releases
255+
256+
Follow this if you are using immutable releases.
257+
For immutable releases, please do not create a new release using the GitHub UI, you can push a new tag, and the workflow will create a new release, build the extension, and upload the builds to the release.
258+
It publishes the release by default, and then you can edit the release notes as needed, If you want to create a draft release, set the `draft` input to `true` in the `release` job.
259+
260+
```yaml
261+
name: Build extension
262+
on:
263+
# When a new tag is pushed, we can build, and upload the DLLs to it.
264+
push:
265+
# branches: ['**'] # Uncomment this to run on push to a branch
266+
tags: ['*']
267+
# create: # Uncomment this to run on tag/branch creation
268+
# pull_request: # Uncomment this to run on pull requests
269+
270+
permissions:
271+
contents: write
272+
273+
jobs:
274+
# This job generates a matrix of PHP versions, architectures, and thread safety options
275+
# This is done by reading the constraints from composer.json or the package.xml file.
276+
# Please refer to https://github.com/php/php-windows-builder#get-the-job-matrix-to-build-a-php-extension
277+
get-extension-matrix:
278+
runs-on: ubuntu-latest
279+
outputs:
280+
matrix: ${{ steps.extension-matrix.outputs.matrix }}
281+
steps:
282+
- name: Checkout
283+
uses: actions/checkout@v5
284+
285+
- name: Get the extension matrix
286+
id: extension-matrix
287+
uses: php/php-windows-builder/extension-matrix@v1
288+
289+
# This job builds the extension on Windows using the matrix generated from the previous job.
290+
build:
291+
needs: get-extension-matrix
292+
runs-on: ${{ matrix.os }}
293+
strategy:
294+
matrix: ${{fromJson(needs.get-extension-matrix.outputs.matrix)}}
295+
steps:
296+
- name: Checkout
297+
uses: actions/checkout@v5
298+
299+
- name: Build the extension
300+
uses: php/php-windows-builder/extension@v1
301+
with:
302+
# Always specify the php-version, arch, and ts as they are required inputs.
303+
# Please refer to https://github.com/php/php-windows-builder#build-a-php-extension
304+
php-version: ${{ matrix.php-version }}
305+
arch: ${{ matrix.arch }}
306+
ts: ${{ matrix.ts }}
307+
308+
# This job uploads the build artifacts to the immutable GitHub release it creates.
309+
release:
310+
runs-on: ubuntu-latest
311+
needs: build
312+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
313+
steps:
314+
- name: Upload artifact to the release
315+
uses: php/php-windows-builder/release@v1
316+
with:
317+
release: ${{ github.ref }}
318+
token: ${{ secrets.GITHUB_TOKEN }}
319+
# Uncomment the line below to create a draft release
320+
# draft: 'true'
321+
```
322+
251323
For more example workflows, please refer to the [examples](./examples) directory.
252324

253325
## Local Setup
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This workflow assumes that it is in a repository that contains the imagick extension source code.
2+
name: Build and Test Imagick on Windows
3+
on:
4+
push:
5+
tags: ['*']
6+
branches: ['**']
7+
pull_request:
8+
permissions:
9+
contents: write
10+
jobs:
11+
# This job generates a matrix of PHP versions, architectures, and thread safety options
12+
# This is done by reading the constraints from composer.json or the package.xml file.
13+
# Please refer to https://github.com/php/php-windows-builder#get-the-job-matrix-to-build-a-php-extension
14+
get-extension-matrix:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.extension-matrix.outputs.matrix }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v5
21+
22+
- name: Get the extension matrix
23+
id: extension-matrix
24+
uses: php/php-windows-builder/extension-matrix@v1
25+
26+
# This job builds the extension on Windows using the matrix generated from the previous job.
27+
build:
28+
needs: get-extension-matrix
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
matrix: ${{fromJson(needs.get-extension-matrix.outputs.matrix)}}
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v5
35+
36+
- name: Build the extension
37+
uses: php/php-windows-builder/extension@v1
38+
with:
39+
# Always specify the php-version, arch, and ts as they are required inputs.
40+
# Please refer to https://github.com/php/php-windows-builder#build-a-php-extension
41+
php-version: ${{ matrix.php-version }}
42+
arch: ${{ matrix.arch }}
43+
ts: ${{ matrix.ts }}
44+
45+
# Refer to your config.w32 file to find the libraries you need.
46+
# Refer to the following directories to see if we support the libraries you need.
47+
# https://downloads.php.net/~windows/pecl/deps
48+
# https://downloads.php.net/~windows/php-sdk/deps
49+
libs: ImageMagick-7
50+
51+
# This job uploads the build artifacts to the immutable GitHub release it creates.
52+
release:
53+
runs-on: ubuntu-latest
54+
needs: build
55+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
56+
steps:
57+
- name: Upload artifact to the release
58+
uses: php/php-windows-builder/release@v1
59+
with:
60+
release: ${{ github.ref }}
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
# Uncomment the line below to create a draft release
63+
# draft: 'true'
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This workflow assumes that it is in a repository that contains the Xdebug extension source code.
2+
name: Build and Test Xdebug on Windows
3+
on:
4+
push:
5+
tags: ['*']
6+
branches: ['**']
7+
pull_request:
8+
permissions:
9+
contents: write
10+
jobs:
11+
# This job generates a matrix of PHP versions, architectures, and thread safety options
12+
# This is done by reading the constraints from composer.json or the package.xml file.
13+
# Please refer to https://github.com/php/php-windows-builder#get-the-job-matrix-to-build-a-php-extension
14+
get-extension-matrix:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.extension-matrix.outputs.matrix }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v5
21+
22+
- name: Get the extension matrix
23+
id: extension-matrix
24+
uses: php/php-windows-builder/extension-matrix@v1
25+
26+
# This job builds the extension on Windows using the matrix generated from the previous job.
27+
build:
28+
needs: get-extension-matrix
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
matrix: ${{fromJson(needs.get-extension-matrix.outputs.matrix)}}
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v5
35+
36+
- name: Build the extension
37+
uses: php/php-windows-builder/extension@v1
38+
with:
39+
# Always specify the php-version, arch, and ts as they are required inputs.
40+
# Please refer to https://github.com/php/php-windows-builder#build-a-php-extension
41+
php-version: ${{ matrix.php-version }}
42+
arch: ${{ matrix.arch }}
43+
ts: ${{ matrix.ts }}
44+
45+
# Refer to your config.w32 file to find the libraries you need.
46+
# Refer to the following directories to see if we support the libraries you need.
47+
# https://downloads.php.net/~windows/pecl/deps
48+
# https://downloads.php.net/~windows/php-sdk/deps
49+
libs: zlib
50+
51+
# Refer to your config.w32 file to find the arguments you need to pass to the ./configure step.
52+
# It will add the --enable-<extension> or --with-<extension> argument if configured in the composer.json file.
53+
# In this case, we need to add the --with-xdebug argument manually.
54+
args: --with-xdebug
55+
56+
# This job uploads the build artifacts to the immutable GitHub release it creates.
57+
release:
58+
runs-on: ubuntu-latest
59+
needs: build
60+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
61+
steps:
62+
- name: Upload artifact to the release
63+
uses: php/php-windows-builder/release@v1
64+
with:
65+
release: ${{ github.ref }}
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
# Uncomment the line below to create a draft release
68+
# draft: 'true'

examples/imagick.yml renamed to examples/non-immutable-releases/imagick.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
# When a new release is created, we can build, and upload the DLLs to it.
77
release:
88
types: [created]
9+
permissions:
10+
contents: write
911
jobs:
1012
# This job generates a matrix of PHP versions, architectures, and thread safety options
1113
# This is done by reading the constraints from composer.json or the package.xml file.
@@ -57,4 +59,4 @@ jobs:
5759
uses: php/php-windows-builder/release@v1
5860
with:
5961
release: ${{ github.event.release.tag_name }}
60-
token: ${{ secrets.GITHUB_TOKEN }}
62+
token: ${{ secrets.GITHUB_TOKEN }}

examples/xdebug.yml renamed to examples/non-immutable-releases/xdebug.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
# When a new release is created, we can build, and upload the DLLs to it.
77
release:
88
types: [created]
9+
permissions:
10+
contents: write
911
jobs:
1012
# This job generates a matrix of PHP versions, architectures, and thread safety options
1113
# This is done by reading the constraints from composer.json or the package.xml file.
@@ -62,4 +64,4 @@ jobs:
6264
uses: php/php-windows-builder/release@v1
6365
with:
6466
release: ${{ github.event.release.tag_name }}
65-
token: ${{ secrets.GITHUB_TOKEN }}
67+
token: ${{ secrets.GITHUB_TOKEN }}

release/action.yml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,69 @@ inputs:
1212
required: true
1313
token:
1414
description: 'GitHub token'
15-
required: true
15+
required: false
16+
default: ${{ github.token }}
17+
draft:
18+
description: 'Whether the release is a draft'
19+
required: false
20+
default: 'false'
1621

1722
runs:
1823
using: composite
1924
steps:
2025
- name: Checkout
2126
uses: actions/checkout@v5
2227

28+
- name: Get Ref
29+
id: ref
30+
env:
31+
REF: ${{ inputs.release }}
32+
shell: bash
33+
run: |
34+
REF="${REF#refs/tags/}"
35+
echo "ref=$REF" >> "$GITHUB_OUTPUT"
36+
2337
- name: Get artifacts
2438
uses: actions/download-artifact@v5
2539
with:
2640
path: artifacts
2741
merge-multiple: true
2842

43+
- name: Create release
44+
shell: bash
45+
env:
46+
GH_TOKEN: ${{ inputs.token }}
47+
REF: ${{ steps.ref.outputs.ref }}
48+
run: |
49+
if ! gh release view "$REF" >/dev/null 2>&1; then
50+
gh release create "$REF" --draft --title "${{ steps.ref.outputs.ref }}" --notes ""
51+
else
52+
echo "Release $REF already exists"
53+
fi
54+
2955
- name: Upload artifacts
3056
shell: bash
3157
env:
32-
GITHUB_TOKEN: ${{ inputs.token }}
33-
run: gh release upload ${{ inputs.release }} artifacts/php* --clobber
58+
GH_TOKEN: ${{ inputs.token }}
59+
REF: ${{ steps.ref.outputs.ref }}
60+
run: |
61+
if gh release verify $REF > /dev/null 2>&1; then
62+
link="https://github.com/php/php-windows-builder#example-workflow-for-immutable-releases"
63+
error="Release $REF already exists, and it is immutable. For using immutable releases please refer to $link"
64+
[[ "${GITHUB_ACTIONS:-}" == "true" ]] && echo "::error::$error" || echo "$error"
65+
exit 1
66+
else
67+
gh release upload $REF artifacts/php* --clobber
68+
fi
69+
70+
- name: Publish release
71+
if: ${{ inputs.draft == 'false' }}
72+
shell: bash
73+
env:
74+
GH_TOKEN: ${{ inputs.token }}
75+
REF: ${{ steps.ref.outputs.ref }}
76+
run: |
77+
IS_DRAFT="$(gh release view "$REF" --json isDraft --jq '.isDraft' || echo true)"
78+
if [[ "$IS_DRAFT" == "true" ]]; then
79+
gh release edit "$REF" --draft=false
80+
fi

0 commit comments

Comments
 (0)