-
Notifications
You must be signed in to change notification settings - Fork 1
214 lines (173 loc) · 6.76 KB
/
release.yml
File metadata and controls
214 lines (173 loc) · 6.76 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
208
209
210
211
212
213
214
name: Build and Release
on:
push:
workflow_dispatch:
concurrency:
group: release
cancel-in-progress: true
jobs:
build-and-release:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[build]')
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from PluginMetadata
id: version
run: |
# Find Version = "x.y.z" in any .cs file
VERSION=$(grep -roh 'Version *= *"[^"]*"' --include="*.cs" | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ -z "$VERSION" ]; then
echo "::error::Could not find PluginMetadata Version"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
cache: true
cache-dependency-path: "**/*.csproj"
- name: Restore and Publish
run: |
# Find all csproj files with CreateZip target (these produce release artifacts)
PROJECTS=$(grep -l "CreateZip" $(find . -name "*.csproj") 2>/dev/null || true)
if [ -z "$PROJECTS" ]; then
echo "::error::No projects with CreateZip target found"
exit 1
fi
echo "Found projects to build:"
echo "$PROJECTS"
# Build each project (dependencies like shared API will be built automatically)
for PROJECT in $PROJECTS; do
echo "Building: $PROJECT"
dotnet restore "$PROJECT"
dotnet publish "$PROJECT" -c Release
done
- name: Find and prepare release zips
id: zip
run: |
VERSION="${{ steps.version.outputs.version }}"
# Find all zip files created by build
ZIP_FILES=$(find . -name "*.zip" -type f)
ZIP_COUNT=$(echo "$ZIP_FILES" | wc -l | tr -d ' ')
if [ -z "$ZIP_FILES" ] || [ "$ZIP_COUNT" -eq 0 ]; then
echo "::error::No .zip files found after build"
exit 1
fi
echo "Found $ZIP_COUNT zip file(s)"
# Prepare output directory
mkdir -p release-artifacts
# If only one zip, it's the main plugin - no identification needed
if [ "$ZIP_COUNT" -eq 1 ]; then
ZIP_FILE=$(echo "$ZIP_FILES" | head -1)
BASENAME=$(basename "$ZIP_FILE" .zip)
NEW_NAME="${BASENAME}-v${VERSION}.zip"
mv "$ZIP_FILE" "release-artifacts/$NEW_NAME"
echo "Single plugin: $NEW_NAME"
else
# Multiple zips - must identify main plugin via ConfigureSharedInterface
MAIN_CS=$(grep -rl "ConfigureSharedInterface" --include="*.cs" . 2>/dev/null | head -1)
if [ -z "$MAIN_CS" ]; then
echo "::error::Multiple plugins found but cannot identify main plugin (no ConfigureSharedInterface found)"
exit 1
fi
MAIN_DIR=$(dirname "$MAIN_CS")
echo "Main plugin identified in: $MAIN_DIR"
MAIN_FOUND=false
for ZIP_FILE in $ZIP_FILES; do
BASENAME=$(basename "$ZIP_FILE" .zip)
NEW_NAME="${BASENAME}-v${VERSION}.zip"
# Check if this zip is from the main plugin directory
ZIP_DIR=$(dirname "$ZIP_FILE")
if [[ "$ZIP_DIR" == *"src-plugin"* ]] || [[ "$ZIP_DIR" == "$MAIN_DIR"* ]] || [[ "$MAIN_DIR" == *"$BASENAME"* ]]; then
echo "Main plugin: $NEW_NAME"
MAIN_FOUND=true
else
echo "Perk plugin: $NEW_NAME"
fi
mv "$ZIP_FILE" "release-artifacts/$NEW_NAME"
done
if [ "$MAIN_FOUND" = false ]; then
echo "::error::Could not match main plugin to any zip file"
exit 1
fi
fi
echo "all_zips=$(ls release-artifacts/*.zip | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Determine release tag
id: tag
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
REPO_NAME="${{ github.event.repository.name }}"
# Find next available tag/build number
BASE_TAG="v${VERSION}"
TAG="$BASE_TAG"
TITLE="${REPO_NAME} | ${BASE_TAG}"
BUILD_NUM=1
while gh release view "$TAG" &>/dev/null; do
BUILD_NUM=$((BUILD_NUM + 1))
TAG="${BASE_TAG}-${BUILD_NUM}"
TITLE="${REPO_NAME} | ${BASE_TAG}#${BUILD_NUM}"
echo "Tag $BASE_TAG exists, trying: $TAG"
done
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "Determined tag: $TAG (Title: $TITLE)"
- name: Extract changelog
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
NEW_TAG="${{ steps.tag.outputs.tag }}"
CHANGELOG=""
# Extract changelog section if file exists (matches both [v1.0.1] and [1.0.1])
if [ -f "CHANGELOG.md" ]; then
CHANGELOG=$(awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if ($0 ~ "\\[v?" ver "\\]") { found=1; next }
}
found { print }
' CHANGELOG.md)
fi
if [ -z "$CHANGELOG" ]; then
CHANGELOG="Release v$VERSION"
fi
# Get the most recent existing tag
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
# Build release body
{
echo "body<<EOF"
echo "$CHANGELOG"
echo ""
if [ -n "$PREV_TAG" ]; then
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${NEW_TAG}"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
TAG="${{ steps.tag.outputs.tag }}"
TITLE="${{ steps.tag.outputs.title }}"
# Auto-detect pre-release (contains -)
PRERELEASE_FLAG=""
if [[ "$VERSION" == *-* ]]; then
PRERELEASE_FLAG="--prerelease"
echo "Detected pre-release version"
fi
echo "Creating release: $TAG (Title: $TITLE)"
gh release create "$TAG" \
--title "$TITLE" \
--notes "${{ steps.changelog.outputs.body }}" \
$PRERELEASE_FLAG \
release-artifacts/*.zip
echo "Release $TAG created successfully!"