This repository was archived by the owner on Mar 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
190 lines (165 loc) · 7.77 KB
/
ReleaseVersion.yml
File metadata and controls
190 lines (165 loc) · 7.77 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
name: Release on PR Merge
on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
tagName:
description: "Tag Name"
required: true
default: "vX.X.X.X"
createArtifact:
description: "Create Artifact"
required: false
default: false
type: boolean
betaRelease:
description: "Beta Release"
required: false
default: false
type: boolean
permissions:
contents: write
packages: write
jobs:
validate-tag:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Validate Tag Name
shell: bash
run: |
if [[ ! "${{ github.event.inputs.tagName }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid tag name format. Please use the format vX.X.X.X"
exit 1
fi
release:
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) }}
runs-on: windows-latest
needs: [validate-tag]
environment: Release
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set Release Variables
id: set_vars
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
TAG_NAME_INPUT: ${{ github.event.inputs.tagName }}
BETA_RELEASE_INPUT: ${{ github.event.inputs.betaRelease }}
CREATE_ARTIFACT_INPUT: ${{ github.event.inputs.createArtifact }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref || '' }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref || '' }}
run: |
# Initialize variables
IS_BETA="false"
UPLOAD_ARTIFACT="false"
if [ "$EVENT_NAME" == "workflow_dispatch" ]; then
TAG_NAME="$TAG_NAME_INPUT"
IS_BETA="$BETA_RELEASE_INPUT"
if [ "$CREATE_ARTIFACT_INPUT" == "true" ]; then
UPLOAD_ARTIFACT="true"
fi
elif [ "$EVENT_NAME" == "pull_request" ]; then
TAG_NAME="$PR_HEAD_REF"
if [ "$PR_BASE_REF" == "beta" ]; then
IS_BETA="true"
fi
# Check if 'create-artifact' label is present
if grep -q '"name": "create-artifact"' "$GITHUB_EVENT_PATH"; then
UPLOAD_ARTIFACT="true"
fi
else
echo "Unsupported event type: $EVENT_NAME"
exit 1
fi
# Append '-b' to tag name if beta release
if [ "$IS_BETA" == "true" ]; then
TAG_NAME="${TAG_NAME}-b"
fi
# Validate Tag Name
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(-b)?$ ]]; then
echo "Tag name does not match version pattern. Skipping release."
echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "is_beta=$IS_BETA" >> "$GITHUB_OUTPUT"
echo "upload_artifact=$UPLOAD_ARTIFACT" >> "$GITHUB_OUTPUT"
fi
- name: Build and Publish
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
uses: ./.github/templates/ReleaseAndPublish
- name: Generate SHA256 and MD5 hashes for .zip
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
shell: bash
run: |
sha256sum ./publish/PenumbraModForwarder.zip > ./publish/PenumbraModForwarder.zip.sha256
md5sum ./publish/PenumbraModForwarder.zip > ./publish/PenumbraModForwarder.zip.md5
- name: Read SHA256 and MD5 hashes
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
id: read_hashes
shell: bash
run: |
echo "sha256=$(cut -d ' ' -f1 ./publish/PenumbraModForwarder.zip.sha256)" >> "$GITHUB_ENV"
echo "md5=$(cut -d ' ' -f1 ./publish/PenumbraModForwarder.zip.md5)" >> "$GITHUB_ENV"
- name: Get latest commit message
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
id: get_commit_message
shell: bash
run: |
# Fetch the 'master' branch without tags
git fetch --no-tags origin master
# Get the latest commit message from 'origin/master'
latest_commit=$(git log origin/master -1 --pretty=%B)
# Set the commit_message as an output
echo "commit_message<<EOF" >> "$GITHUB_OUTPUT"
echo "$latest_commit" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Upload Artifact
if: ${{ steps.set_vars.outputs.should_release == 'true' && steps.set_vars.outputs.upload_artifact == 'true' }}
uses: actions/upload-artifact@v4
with:
path: ./publish/PenumbraModForwarder.zip
retention-days: 3
name: "artifact"
- name: Prepare Release Assets
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
id: prepare_assets
shell: bash
env:
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
TAG_NAME: ${{ steps.set_vars.outputs.tag_name }}
run: |
BODY="## Release Notes
${{ steps.get_commit_message.outputs.commit_message }}
## Hashes:
- **SHA256 Hash**: \`${{ env.sha256 }}\`
- **MD5 Hash**: \`${{ env.md5 }}\`
## Download Link
[Download the zip](https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${TAG_NAME}/PenumbraModForwarder.zip)
"
FILES="./publish/PenumbraModForwarder.zip
./publish/PenumbraModForwarder.zip.sha256
./publish/PenumbraModForwarder.zip.md5"
echo "body<<EOF" >> "$GITHUB_OUTPUT"
echo "$BODY" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$FILES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create Release
if: ${{ steps.set_vars.outputs.should_release == 'true' }}
uses: softprops/action-gh-release@v2.0.8
with:
tag_name: ${{ steps.set_vars.outputs.tag_name }}
body: ${{ steps.prepare_assets.outputs.body }}
files: ${{ steps.prepare_assets.outputs.files }}
prerelease: ${{ steps.set_vars.outputs.is_beta }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}