Repository navigation
119 lines (101 loc) · 3.96 KB
/
Copy pathrelease.yml
File metadata and controls
119 lines (101 loc) · 3.96 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
name: Create Release
on: # zizmor: ignore[concurrency-limits]
workflow_dispatch:
inputs:
version:
description: 'Release version, without the v prefix (e.g. 1.2.0)'
required: true
type: string
permissions: {}
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
environment: Releases
permissions: {} # all writes go through the App token; GITHUB_TOKEN needs no scopes
steps:
- name: Resolve and validate version
env:
INPUT_VERSION: ${{ inputs.version }}
BRANCH: ${{ github.ref_name }}
run: |
version="${INPUT_VERSION#v}"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
echo "::error::Version must look like 1.2.0 (got: $INPUT_VERSION)"
exit 1
fi
if [[ "$BRANCH" =~ ^[0-9]+\.x$ ]] && [ "${version%%.*}" != "${BRANCH%%.*}" ]; then
echo "::error::Version $version does not belong on the $BRANCH branch"
exit 1
fi
echo "TAG=v$version" >> "$GITHUB_ENV"
- name: Get release bot token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.RELEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
permission-contents: write
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true # zizmor: ignore[artipacked] App token is needed to push the tag
- name: Assert tag does not already exist
run: |
existing="$(git ls-remote --tags origin "$TAG")"
[ -z "$existing" ] || { echo "::error::Tag $TAG already exists on remote. Aborting."; exit 1; }
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
- name: Use Node.js 20.19.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 20.19.0
package-manager-cache: false
- name: Install Composer dependencies
uses: nick-invision/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
with:
timeout_minutes: 5
max_attempts: 5
command: composer install --no-interaction --prefer-dist
- name: Install NPM dependencies
run: npm ci
- name: Build release assets
run: npm run build
- name: Create the build commit
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
run: |
USER_ID="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
git config user.name "${APP_SLUG}[bot]"
git config user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
git add --force resources/dist
git commit -m "Build assets for $TAG"
- name: Tag and push the build commit
run: |
git tag "$TAG"
git push origin "$TAG"
- name: Get Changelog
id: changelog
uses: statamic/changelog-action@5d112d0d790cdeeb5adca3e584e37edc474ab51b # v1.0.2
with:
version: ${{ env.TAG }}
- name: Create release
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RELEASE_NOTES: ${{ steps.changelog.outputs.text }}
IS_DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
run: |
latest="$IS_DEFAULT_BRANCH"
prerelease=false
case "$TAG" in
*-*) prerelease=true; latest=false ;;
esac
gh release create "$TAG" \
--title "$TAG" \
--notes "$RELEASE_NOTES" \
--latest="$latest" \
--prerelease="$prerelease"