generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 39
180 lines (165 loc) · 6.97 KB
/
github-release.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
name: Create GitHub Release
on:
workflow_dispatch:
inputs:
version-name:
description: 'Version Name - E.g. "2024.11.1"'
required: true
type: string
version-number:
description: 'Version Number - E.g. "123456"'
required: true
type: string
artifact-run-id:
description: 'GitHub Action Run ID containing artifacts'
required: true
type: string
draft:
description: 'Create as draft release'
type: boolean
default: true
prerelease:
description: 'Mark as pre-release'
type: boolean
default: true
make-latest:
description: 'Set as the latest release'
type: boolean
branch-protection-type:
description: 'Branch protection type'
type: choice
options:
- Branch Name
- GitHub API
default: Branch Name
env:
ARTIFACTS_PATH: artifacts
jobs:
create-release:
runs-on: ubuntu-24.04
permissions:
contents: write
actions: read
steps:
- name: Check out repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Get branch from workflow run
id: get_release_branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_RUN_ID: ${{ inputs.artifact-run-id }}
BRANCH_PROTECTION_TYPE: ${{ inputs.branch-protection-type }}
run: |
release_branch=$(gh run view $ARTIFACT_RUN_ID --json headBranch -q .headBranch)
case "$BRANCH_PROTECTION_TYPE" in
"Branch Name")
if [[ "$release_branch" != "main" && ! "$release_branch" =~ ^release/ ]]; then
echo "::error::Branch '$release_branch' is not 'main' or a release branch starting with 'release/'. Releases must be created from protected branches."
exit 1
fi
;;
"GitHub API")
#NOTE requires token with "administration:read" scope
if ! gh api "repos/${{ github.repository }}/branches/$release_branch/protection" | grep -q "required_status_checks"; then
echo "::error::Branch '$release_branch' is not protected. Releases must be created from protected branches. If that's not correct, confirm if the github token user has the 'administration:read' scope."
exit 1
fi
;;
*)
echo "::error::Unsupported branch protection type: $BRANCH_PROTECTION_TYPE"
exit 1
;;
esac
echo "release_branch=$release_branch" >> $GITHUB_OUTPUT
- name: Get last release tag
id: get_last_tag
run: |
last_release_tag=$(git tag -l --sort=-authordate | head -n 1)
echo "last_release_tag=$last_release_tag" >> $GITHUB_OUTPUT
- name: Download artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_RUN_ID: ${{ inputs.artifact-run-id }}
run: ./Scripts/download-artifacts.sh $ARTIFACTS_PATH $ARTIFACT_RUN_ID
- name: Parse version info
id: version_info
run: |
unzip -o "$ARTIFACTS_PATH/version-info.zip" -d "tmp"
filepath="tmp/version-info/version_info.json"
version_name=$(jq -r '.version_name' "$filepath")
version_number=$(jq -r '.version_number' "$filepath")
echo "version_number=$version_number" >> $GITHUB_OUTPUT
echo "version_name=$version_name" >> $GITHUB_OUTPUT
rm -rf tmp
# - name: Create Release Notes
# id: release_notes
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# if [ -n "${{ steps.get_last_tag.outputs.last_release_tag }}" ]; then
# # Generate release notes from last tag to HEAD
# gh api \
# --method POST \
# -H "Accept: application/vnd.github+json" \
# /repos/${{ github.repository }}/releases/generate-notes \
# -f tag_name="v${{ steps.version_info.outputs.version_name }}" \
# -f target_commitish="${{ steps.get_release_branch.outputs.release_branch }}" \
# -f previous_tag_name="${{ steps.get_last_tag.outputs.last_release_tag }}" \
# -q .body > release_notes.txt
# else
# # If no previous tag exists, just add a basic note
# echo "Initial release" > release_notes.txt
# fi
- name: Create GitHub Release
id: create_gh_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create release with generated notes
gh release create "v${{ steps.version_info.outputs.version_name }}" \
--title "${{ steps.version_info.outputs.version_name }} (${{ steps.version_info.outputs.version_number }})" \
--target ${{ steps.get_release_branch.outputs.release_branch }} \
--generate-notes \
--notes-start-tag "${{ steps.get_last_tag.outputs.last_release_tag }}" \
--prerelease=${{ inputs.prerelease }} \
--draft=${{ inputs.draft }} \
'$ARTIFACTS_PATH/*'
#--latest=${{ inputs.make-latest }} \
# # Upload all artifacts
# for file in $ARTIFACTS_PATH/*; do
# if [ -f "$file" ]; then
# gh release upload "v${{ steps.version_info.outputs.version_name }}" "$file"
# fi
done
- name: Create Release
id: create_release
uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # v2.0.9
with:
tag_name: "v${{ steps.version_info.outputs.version_name }}"
name: "${{ steps.version_info.outputs.version_name }} (${{ steps.version_info.outputs.version_number }})"
prerelease: ${{ inputs.prerelease }}
draft: ${{ inputs.draft }}
make_latest: ${{ inputs.make-latest }}
target_commitish: ${{ steps.get_release_branch.outputs.release_branch }}
generate_release_notes: true
files: |
artifacts/**/*
- name: Update Release Description
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ steps.create_release.outputs.id }}
RELEASE_URL: ${{ steps.create_release.outputs.url }}
ARTIFACT_RUN_ID: ${{ inputs.artifact-run-id }}
run: |
# Get current release body
current_body=$(gh api /repos/${{ github.repository }}/releases/$RELEASE_ID --jq .body)
# Append build source to the end
updated_body="${current_body}
**Builds Source:** https://github.com/${{ github.repository }}/actions/runs/$ARTIFACT_RUN_ID"
# Update release
gh api --method PATCH /repos/${{ github.repository }}/releases/$RELEASE_ID \
-f body="$updated_body"
echo "# :rocket: Release ready at:" >> $GITHUB_STEP_SUMMARY
echo "$RELEASE_URL" >> $GITHUB_STEP_SUMMARY