-
Notifications
You must be signed in to change notification settings - Fork 8
235 lines (225 loc) · 8.79 KB
/
create-release.yaml
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
name: (R) Create Release
on:
workflow_dispatch:
inputs:
commit-id:
description: "commit-id: CommitId to create release & tag."
required: false
type: string
dry-run:
description: "dry-run: true = no upload. false = dry run changes && delete release after 60s."
required: true
type: boolean
require-validation:
description: "require-validation: true require validation must pass, false to keep going even validation failed."
required: false
type: boolean
default: true
tag:
description: "tag: Git tag to create. (sample 1.0.0)"
required: true
type: string
# nuget
nuget-push:
description: "nuget-push: true = upload nuget package. false = not upload"
required: false
type: boolean
default: false
# release
release-asset-path:
description: "release assets path to upload. This is a list of paths separated by a newline."
required: false
type: string
release-format: # see: https://docs.github.com/en/actions/learn-github-actions/expressions#format
description: "release-format: if 'Ver.{0}' is specified, the release title will be 'Ver.1.0.0'. set '{0}' if no prefix is preferred."
required: false
type: string
default: 'Ver.{0}'
release-upload:
description: "release-upload: true = upload assets. false = not upload"
required: false
type: boolean
default: false
workflow_call:
inputs:
commit-id:
description: "CommitId to create release & tag."
required: true
type: string
dry-run:
description: "true = no upload. false = dry run changes && delete release after 60s."
required: true
type: boolean
require-validation:
description: "true require validation must pass, false to keep going even validation failed."
required: false
type: boolean
default: true
tag:
description: "Git tag to create. (sample 1.0.0)"
required: true
type: string
# nuget
nuget-path:
description: "nuget path to upload."
required: false
type: string
default: |
./nuget/*.nupkg
./nuget/*.snupkg
nuget-push:
description: "true = upload nuget package. false = not upload"
required: false
type: boolean
default: false
# release
release-asset-path:
description: "release assets path to upload. This is a list of paths separated by a newline."
required: false
type: string
release-format: # see: https://docs.github.com/en/actions/learn-github-actions/expressions#format
description: "Release format. (if 'Ver.{0}' is specified, the release title will be 'Ver.1.0.0'. set '{0}' if no prefix is preferred.)"
required: false
type: string
default: 'Ver.{0}'
release-upload:
description: "true = upload assets. false = not upload"
required: false
type: boolean
default: false
jobs:
validate:
uses: Cysharp/Actions/.github/workflows/validate-tag.yaml@main
with:
tag: ${{ inputs.tag }}
require-validation: ${{ inputs.require-validation }}
secrets: inherit
create-release:
needs: [validate]
name: Create Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # auto generated token
GH_REPO: ${{ github.repository }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Validate inputs - unitypackage
shell: bash
if: ${{ inputs.release-upload && inputs.release-asset-path == '' }}
run: |
echo "Validation error! 'inputs.release-asset-path' cannot be blank when 'inputs.release-upload' is true."
exit 1
- name: Load secrets
id: op-load-secret
uses: 1password/load-secrets-action@v2
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
NUGET_KEY: "op://GitHubActionsPublic/NUGET_KEY/credential"
- uses: actions/checkout@v4
with:
ref: ${{ inputs.commit-id }}
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
if: ${{ inputs.nuget-push }}
# Download(All) Artifacts to current directory
- uses: Cysharp/Actions/.github/actions/download-artifact@main
- name: Show download aritifacts
run: ls -lR
- name: Validate package exists in artifact - release assets
if: ${{ inputs.release-upload }}
run: |
while read -r asset_path; do
if [[ "${asset_path}" == "" ]]; then continue; fi
# is it a wildcard?
# shellcheck disable=SC2086
if [[ "$asset_path" == *\** || "$asset_path" == *\?* ]]; then
# shellcheck disable=SC2086
if ! ls -l ${asset_path}; then
echo "Specified nuget package not found. path: $asset_path"
if [[ "${asset_path}" == *.nupkg ]]; then
echo ".nupkg must be included in the artifact."
exit 1
fi
fi
continue
fi
# is it a file?
if [[ ! -f "${asset_path}" ]]; then
echo "Specified asset not found. path: ${asset_path}"
exit 1
fi
done <<< "${{ inputs.release-asset-path }}"
- name: Validate package exists in artifact - NuGet
if: ${{ inputs.nuget-push }}
run: |
while read -r nuget_path; do
if [[ "${nuget_path}" == "" ]]; then continue; fi
# shellcheck disable=SC2086
if ! ls -l ${nuget_path}; then
echo "Specified nuget package not found. path: $nuget_path"
if [[ "${nuget_path}" == *.nupkg ]]; then
echo ".nupkg must be included in the artifact."
exit 1
fi
fi
done <<< "${{ inputs.nuget-path }}"
# Create Releases
- name: Create Tag
run: |
git tag ${{ inputs.tag }}
git push origin ${{ inputs.tag }}
- name: Create Release
run: gh release create ${{ inputs.tag }} --draft --verify-tag --title "${{ format(inputs.release-format, inputs.tag) }}" --generate-notes
- name: Wait and Verify Release Name is expected
run: |
sleep 5s
actual=$(gh api --paginate /repos/${{ github.repository }}/releases?per_page=100 --jq '.[] | select(.tag_name == "${{ inputs.tag }}") | .name')
expected="${{ format(inputs.release-format, inputs.tag) }}"
if [[ "$actual" != "$expected" ]]; then
echo "Release name is not as expected. expected: $expected, actual: $actual"
exit 1
else
echo "Release name is expected! expected: $expected, actual: $actual"
fi
- name: Upload asset files to release
run: |
while read -r asset_path; do
if [[ "${asset_path}" == "" ]]; then continue; fi
# is it a wildcard?
# shellcheck disable=SC2086
if [[ "$asset_path" == *\** || "$asset_path" == *\?* ]]; then
for file in ${asset_path}; do
gh release upload ${{ inputs.tag }} "${file}"
done
continue
fi
# is it a file?
gh release upload ${{ inputs.tag }} "${asset_path}"
done <<< "${{ inputs.release-asset-path }}"
if: ${{ inputs.release-upload }}
# Upload to NuGet
- name: Upload to NuGet (DryRun=${{ inputs.dry-run }})
if: ${{ inputs.nuget-push }}
run: |
while read -r nuget_path; do
if [[ "$nuget_path" == "" ]]; then continue; fi
# shellcheck disable=SC2086
if ! ls -l ${nuget_path} >/dev/null 2>&1;then
echo "skipping nuget push, $nuget_path not found."
continue
fi
if [[ "${{ inputs.dry-run }}" == "true" ]]; then
echo "(dry run) dotnet nuget push \"${nuget_path}\" --skip-duplicate -s https://api.nuget.org/v3/index.json -k \"${{ steps.op-load-secret.outputs.NUGET_KEY }}\""
else
dotnet nuget push "${nuget_path}" --skip-duplicate -s https://api.nuget.org/v3/index.json -k "${{ steps.op-load-secret.outputs.NUGET_KEY }}"
fi
done <<< "${{ inputs.nuget-path }}"
# Clean up
- name: Clean up. Wait 60s and delete release if dry-run or failure. (dry-run=${{ inputs.dry-run }}})
if: ${{ inputs.dry-run || failure() }}
run: |
if gh release list | grep Draft | grep ${{ inputs.tag }}; then
sleep 60
gh release delete ${{ inputs.tag }} --yes --cleanup-tag
fi