-
Notifications
You must be signed in to change notification settings - Fork 1
207 lines (180 loc) · 7.12 KB
/
Copy pathrelease.yml
File metadata and controls
207 lines (180 loc) · 7.12 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
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
name: Release package
on:
workflow_dispatch:
inputs:
platform:
description: Platform to release
required: true
type: choice
options:
- iOS
- Android
- Embedded Checkout Protocol
- React Native
version:
description: Expected package version. Must match the checked-in version for the selected platform.
required: true
type: string
mode:
description: Release mode
required: false
type: choice
default: Dry run
options:
- Dry run
- Draft release
- Production release
permissions:
contents: write
actions: write
concurrency:
group: release-${{ inputs.platform }}
cancel-in-progress: false
jobs:
release:
name: Release ${{ inputs.platform }} ${{ inputs.version }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Validate requested release
id: release
env:
PLATFORM: ${{ inputs.platform }}
EXPECTED_VERSION: ${{ inputs.version }}
run: .github/scripts/validate-release-version "$PLATFORM" "$EXPECTED_VERSION" >> "$GITHUB_OUTPUT"
- name: Require main branch for stable releases
if: steps.release.outputs.prerelease == 'false' && github.ref != 'refs/heads/main'
env:
REF: ${{ github.ref }}
run: |
echo "::error::Stable releases must be created from the main branch. Current ref: $REF"
exit 1
- name: Check tag and release do not already exist
env:
TAG: ${{ steps.release.outputs.tag }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "::error::Tag '${TAG}' already exists. Refusing to create a duplicate release."
exit 1
fi
if gh release view "$TAG" >/dev/null 2>&1; then
echo "::error::GitHub Release '${TAG}' already exists."
exit 1
fi
echo "::notice::Tag '${TAG}' and release '${TAG}' do not exist yet."
- name: Print release plan
env:
MODE: ${{ inputs.mode }}
DISPLAY_PLATFORM: ${{ steps.release.outputs.display_platform }}
VERSION: ${{ steps.release.outputs.version }}
TAG: ${{ steps.release.outputs.tag }}
RELEASE_TITLE: ${{ steps.release.outputs.release_title }}
PRERELEASE: ${{ steps.release.outputs.prerelease }}
PUBLISH_WORKFLOW: ${{ steps.release.outputs.publish_workflow }}
ANDROID_PROTOCOL_VERSION: ${{ steps.release.outputs.android_protocol_version }}
run: |
set -euo pipefail
echo "Release plan:"
echo " Platform: ${DISPLAY_PLATFORM}"
echo " Version: ${VERSION}"
if [ -n "$ANDROID_PROTOCOL_VERSION" ]; then
echo " Embedded Checkout Protocol version: ${ANDROID_PROTOCOL_VERSION}"
fi
echo " Tag: ${TAG}"
echo " Title: ${RELEASE_TITLE}"
echo " Prerelease: ${PRERELEASE}"
echo " Publish workflow: ${PUBLISH_WORKFLOW}"
echo " Mode: ${MODE}"
if [ "$MODE" = "Dry run" ]; then
echo " Release creation: skipped"
echo " Publish dispatch: skipped"
elif [ "$MODE" = "Draft release" ]; then
echo " Release creation: draft GitHub Release"
echo " Publish dispatch: skipped until the draft release is manually published"
else
echo " Release creation: published GitHub Release"
echo " Publish dispatch: ${PUBLISH_WORKFLOW} will be dispatched after release creation"
fi
- name: Create GitHub Release
if: ${{ inputs.mode != 'Dry run' }}
env:
TAG: ${{ steps.release.outputs.tag }}
RELEASE_TITLE: ${{ steps.release.outputs.release_title }}
PRERELEASE: ${{ steps.release.outputs.prerelease }}
DRAFT: ${{ inputs.mode == 'Draft release' && 'true' || 'false' }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
args=("$TAG" --target "$GITHUB_SHA" --title "$RELEASE_TITLE" --generate-notes)
if [ "$DRAFT" = "true" ]; then
args+=(--draft)
fi
if [ "$PRERELEASE" = "true" ]; then
args+=(--prerelease --latest=false)
elif [ "$DRAFT" = "false" ]; then
args+=(--latest)
fi
gh release create "${args[@]}"
- name: Dispatch publish workflow
if: ${{ inputs.mode == 'Production release' }}
env:
TAG: ${{ steps.release.outputs.tag }}
PUBLISH_WORKFLOW: ${{ steps.release.outputs.publish_workflow }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh workflow run "$PUBLISH_WORKFLOW" --ref "$TAG"
echo "::notice::Dispatched ${PUBLISH_WORKFLOW} at ${TAG}."
- name: Summary
env:
MODE: ${{ inputs.mode }}
DISPLAY_PLATFORM: ${{ steps.release.outputs.display_platform }}
VERSION: ${{ steps.release.outputs.version }}
TAG: ${{ steps.release.outputs.tag }}
RELEASE_TITLE: ${{ steps.release.outputs.release_title }}
PUBLISH_WORKFLOW: ${{ steps.release.outputs.publish_workflow }}
ANDROID_PROTOCOL_VERSION: ${{ steps.release.outputs.android_protocol_version }}
REF_NAME: ${{ github.ref_name }}
PLATFORM: ${{ inputs.platform }}
run: |
set -euo pipefail
WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/workflows/release.yml"
cat >> "$GITHUB_STEP_SUMMARY" <<SUMMARY
## Release plan
- Mode: \`${MODE}\`
- Platform: ${DISPLAY_PLATFORM}
- Version: ${VERSION}
- Tag: \`${TAG}\`
- Title: ${RELEASE_TITLE}
- Publish workflow: \`${PUBLISH_WORKFLOW}\`
SUMMARY
if [ -n "$ANDROID_PROTOCOL_VERSION" ]; then
cat >> "$GITHUB_STEP_SUMMARY" <<SUMMARY
- Embedded Checkout Protocol version: \`${ANDROID_PROTOCOL_VERSION}\`
SUMMARY
fi
if [ "$MODE" = "Dry run" ]; then
cat >> "$GITHUB_STEP_SUMMARY" <<SUMMARY
## Continue to draft release
GitHub does not currently support pre-filled \`workflow_dispatch\`
form inputs via URL. To avoid retyping the validated version, run this
GitHub CLI command:
\`\`\`bash
gh workflow run release.yml \\
--repo "${GITHUB_REPOSITORY}" \\
--ref "${REF_NAME}" \\
-f platform="${PLATFORM}" \\
-f version="${VERSION}" \\
-f mode="Draft release"
\`\`\`
Or open the [Release package workflow](${WORKFLOW_URL}) and enter the
same values manually.
SUMMARY
echo "::notice::GitHub CLI draft release command written to the job summary."
fi