-
Notifications
You must be signed in to change notification settings - Fork 3
235 lines (222 loc) · 10 KB
/
release-on-milestone-closed-triggering-release-event.yml
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Alternate workflow example.
# This one is identical to the one in release-on-milestone.yml, with one change:
# the Release step uses the ORGANIZATION_ADMIN_TOKEN instead, to allow it to
# trigger a release workflow event. This is useful if you have other actions
# that intercept that event.
name: "Automatic Releases"
on:
milestone:
types:
- "closed"
jobs:
release_parameters:
runs-on: ubuntu-latest
outputs:
version_to_tag: ${{ steps.version_to_tag_step.outputs.version_to_tag }}
previous_semver_version: ${{ steps.previous_semver_version_step.outputs.previous_semver_version }}
ref_for_version_to_tag: ${{ steps.ref_for_version_to_tag_step.outputs.ref_for_version_to_tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Version we are making
id: version_to_tag_step
run: |
echo "milestone title = ${{ github.event.milestone.title }}"
echo "version_to_tag=${{ github.event.milestone.title }}" >> $GITHUB_OUTPUT
- name: Previous semver version
id: previous_semver_version_step
run: |
PREVIOUS_SEMVER_VERSION=$(./.github/workflows/get-previous-semver-version.sh ${{ steps.version_to_tag_step.outputs.version_to_tag }})
echo "previous semver version = $PREVIOUS_SEMVER_VERSION"
echo "previous_semver_version=$PREVIOUS_SEMVER_VERSION" >> $GITHUB_OUTPUT
- name: Get the git ref
id: ref_for_version_to_tag_step
run: |
BRANCH_EXTRACT_REGEX="([0-9]+\.[0-9]+)\.[0-9]+"
EXPECTED_BRANCH_NAME="$(echo "${{ steps.version_to_tag_step.outputs.version_to_tag }}" | sed -r -e "s/$BRANCH_EXTRACT_REGEX/\1/").x"
echo "expected branch name = $EXPECTED_BRANCH_NAME"
RELEASE_GIT_SHA=$(git rev-parse origin/$EXPECTED_BRANCH_NAME)
echo "ref for version to be tagged = $RELEASE_GIT_SHA"
echo "ref_for_version_to_tag=$RELEASE_GIT_SHA" >> $GITHUB_OUTPUT
windows-release-build:
needs: [ "release_parameters" ]
strategy:
fail-fast: false
matrix:
php: [ "8.2", "8.1", "8.0", "7.4", "7.3", "7.2", "7.1" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- uses: dawidd6/action-download-artifact@v2
with:
workflow: ci-build.yaml
workflow_conclusion: success
commit: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
name: DLL only ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}
- name: Get the release version
id: win_get_release_version
run: |
HEADER_RELEASE="$(cat zend_scoutapm.h | grep "PHP_SCOUTAPM_VERSION" | awk '{print $3}' | tr -d '"')"
echo "version=$HEADER_RELEASE" >> $GITHUB_OUTPUT
- name: Prepare zip
run: zip php_scoutapm-${{steps.win_get_release_version.outputs.version}}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}.zip php_scoutapm.dll LICENSE README.md CREDITS
- name: Add zipped DLL as artifact for ${{ needs.release_parameters.outputs.version_to_tag }}
uses: actions/upload-artifact@v3
with:
name: DLL ${{ needs.release_parameters.outputs.version_to_tag }}
path: php_scoutapm-${{steps.win_get_release_version.outputs.version}}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}.zip
pre-verify-release:
name: "Pre-verify release"
needs: [ "release_parameters", "windows-release-build" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- name: "Fetch previous release tag from Github API"
uses: octokit/request-action@v2.x
id: get_previous_release_step
with:
route: GET /repos/scoutapp/scout-apm-php-ext/releases/tags/${{ needs.release_parameters.outputs.previous_semver_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Verify that PHP_SCOUTAPM_VERSION has been changed"
run: |
PREVIOUS_RELEASE="${{ fromJson(steps.get_previous_release_step.outputs.data).tag_name }}"
HEADER_RELEASE="$(cat zend_scoutapm.h | grep "PHP_SCOUTAPM_VERSION" | awk '{print $3}' | tr -d '"')"
echo "Previous release: $PREVIOUS_RELEASE"
echo "PHP_SCOUTAPM_VERSION in header: $HEADER_RELEASE"
if [[ "$PREVIOUS_RELEASE" = "$HEADER_RELEASE" ]]
then
echo "PHP_SCOUTAPM_VERSION in zend_scoutapm.h has NOT been changed, cannot release"
exit 1
else
echo "Version in zend_scoutapm.h HAS been changed."
exit 0
fi
- name: "Extract latest version from package.xml"
uses: QwerMike/xpath-action@v1
id: get_package_xml_version
with:
filename: 'package.xml'
expression: "//*[local-name()='package']/*[local-name()='version']/*[local-name()='release']/text()"
- name: "Check package.xml version release has been changed"
run: |
PREVIOUS_RELEASE="${{ fromJson(steps.get_previous_release_step.outputs.data).tag_name }}"
XML_RELEASE="${{ steps.get_package_xml_version.outputs.result }}"
echo "Previous release: $PREVIOUS_RELEASE"
echo "package.xml version: $XML_RELEASE"
if [[ "$PREVIOUS_RELEASE" = "$XML_RELEASE" ]]
then
echo "package.xml version has NOT been changed, cannot release"
exit 1
else
echo "Version in package.xml HAS been changed."
exit 0
fi
release:
name: "Tag, release & create merge-up PR"
needs: [ "pre-verify-release" ]
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: "Release"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Fetch rate limit stats"
uses: octokit/request-action@v2.x
id: get_latest_release
with:
route: GET /rate_limit
env:
GITHUB_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
- name: "Display rate limit stats"
run: echo "${{ steps.get_latest_release.outputs.data }}"
- name: "Create Merge-Up Pull Request"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create and/or Switch to new Release Branch"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:switch-default-branch-to-next-minor"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create new milestones"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
post-release-assets:
name: "Create assets post-release"
needs: [ "release_parameters", "release" ]
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "8.0"
tools: pecl
- name: "Build PECL Package"
run: pecl package
- name: "Fetch new release from Github API"
uses: octokit/request-action@v2.x
id: get_new_release_step
with:
route: GET /repos/scoutapp/scout-apm-php-ext/releases/tags/${{ needs.release_parameters.outputs.version_to_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Upload PECL package to latest release"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ fromJson(steps.get_new_release_step.outputs.data).upload_url }}
asset_path: ./scoutapm-${{ fromJson(steps.get_new_release_step.outputs.data).tag_name }}.tgz
asset_name: scoutapm-${{ fromJson(steps.get_new_release_step.outputs.data).tag_name }}.tgz
asset_content_type: application/gzip
- uses: actions/download-artifact@v3
with:
name: DLL ${{ needs.release_parameters.outputs.version_to_tag }}
- name: "Upload Windows DLLs to latest release"
# sauce: https://github.com/actions/upload-release-asset/issues/28#issuecomment-675297045
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ls -l php_scoutapm-*.zip
RELEASE="${{ needs.release_parameters.outputs.version_to_tag }}"
ASSETS=$(find . -type f -name "php_scoutapm-*.zip" -printf "-a %p ")
echo "release = $RELEASE"
echo "assets = $ASSETS"
hub release edit $ASSETS -m "" "$RELEASE"