-
Notifications
You must be signed in to change notification settings - Fork 2
181 lines (154 loc) · 6.1 KB
/
Copy pathrelease.yml
File metadata and controls
181 lines (154 loc) · 6.1 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 1.0.0 or 1.0.0-rc.2). The leading "v" is added automatically.'
required: true
type: string
permissions:
contents: write
env:
PACKAGE_PATH: Aspid.FastTools/Packages/tech.aspid.fasttools
CHANGELOG_PATH: CHANGELOG.md
GENERATORS_SOLUTION_DIR: Aspid.FastTools.Generators
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Determine version
id: version
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF_NAME}"
fi
VERSION="${VERSION#v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Version '$VERSION' is not a valid SemVer string."
exit 1
fi
TAG="v$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "Releasing $TAG"
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Check tag does not already exist
if: github.event_name == 'workflow_dispatch'
run: |
set -euo pipefail
TAG="${{ steps.version.outputs.tag }}"
if git rev-parse --verify --quiet "refs/tags/$TAG" >/dev/null; then
echo "::error::Tag $TAG already exists locally. Delete it or pick another version."
exit 1
fi
if git ls-remote --exit-code --tags origin "$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists on origin."
exit 1
fi
- name: Validate package.json version
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
PKG_VERSION=$(jq -r .version "$PACKAGE_PATH/package.json")
if [[ "$PKG_VERSION" != "$VERSION" ]]; then
echo "::error file=$PACKAGE_PATH/package.json::package.json version ($PKG_VERSION) does not match release version ($VERSION). Bump it before tagging."
exit 1
fi
echo "package.json version matches: $PKG_VERSION"
- name: Extract CHANGELOG section
id: changelog
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
NOTES=$(awk -v ver="$VERSION" '
BEGIN { capture = 0 }
/^## \[/ {
if (capture) { exit }
if ($0 ~ "^## \\[" ver "\\]([^0-9A-Za-z.-]|$)") { capture = 1; next }
}
capture { print }
' "$CHANGELOG_PATH")
if [[ -z "$(echo "$NOTES" | tr -d '[:space:]')" ]]; then
echo "::error file=$CHANGELOG_PATH::No CHANGELOG section found for version $VERSION. Add a '## [$VERSION] — YYYY-MM-DD' heading before releasing."
exit 1
fi
{
echo "notes<<__CHANGELOG_EOF__"
echo "$NOTES"
echo "__CHANGELOG_EOF__"
} >> "$GITHUB_OUTPUT"
echo "CHANGELOG section for $VERSION extracted ($(echo "$NOTES" | wc -l) lines)."
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Build generators
run: dotnet build -c Release
working-directory: ${{ env.GENERATORS_SOLUTION_DIR }}
- name: Verify deployed generator DLL is present
run: |
set -euo pipefail
DEPLOYED="$PACKAGE_PATH/Aspid.FastTools.Generators.dll"
if [[ ! -s "$DEPLOYED" ]]; then
echo "::error file=$DEPLOYED::Generator DLL is missing from the package. Run 'dotnet build -c Release' in $GENERATORS_SOLUTION_DIR and commit the updated DLL before releasing."
exit 1
fi
echo "Deployed generator DLL: $(stat -c '%s bytes' "$DEPLOYED")"
- name: Create and push release tag
if: github.event_name == 'workflow_dispatch'
run: |
set -euo pipefail
TAG="${{ steps.version.outputs.tag }}"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
- name: Checkout release tag
run: |
set -euo pipefail
git fetch origin "refs/tags/${{ steps.version.outputs.tag }}:refs/tags/${{ steps.version.outputs.tag }}" || true
git checkout "${{ steps.version.outputs.tag }}"
- name: Publish UPM subtree
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
PRERELEASE="${{ steps.version.outputs.prerelease }}"
if [[ "$PRERELEASE" == "true" ]]; then
UPM_BRANCH="upm-preview"
else
UPM_BRANCH="upm"
fi
UPM_TAG="$UPM_BRANCH/$VERSION"
if git ls-remote --exit-code --tags origin "$UPM_TAG" >/dev/null 2>&1; then
echo "::error::Tag $UPM_TAG already exists on origin. Refusing to overwrite a published UPM tag."
exit 1
fi
SPLIT_SHA=$(git subtree split --prefix="$PACKAGE_PATH" HEAD)
echo "Subtree split SHA: $SPLIT_SHA"
git push --force origin "$SPLIT_SHA:refs/heads/$UPM_BRANCH"
git tag "$UPM_TAG" "$SPLIT_SHA"
git push origin "$UPM_TAG"
echo "Published $UPM_TAG and updated $UPM_BRANCH branch."
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
body: ${{ steps.changelog.outputs.notes }}
prerelease: ${{ steps.version.outputs.prerelease == 'true' }}