-
Notifications
You must be signed in to change notification settings - Fork 10
172 lines (148 loc) · 6.39 KB
/
create-release.yml
File metadata and controls
172 lines (148 loc) · 6.39 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
name: Create Release
on:
workflow_dispatch:
inputs:
rc_tag:
description: 'The prerelease tag to use as a base (e.g., v0.1.0-rc.1 or v0.1.0-beta.1)'
required: true
type: string
jobs:
build_and_release:
runs-on: windows-latest
permissions:
contents: write
outputs:
final_version_tag: ${{ steps.create_final_tag.outputs.final_version_tag }}
final_version_number: ${{ steps.extract_final_version.outputs.final_version_number }}
steps:
- name: Get Prerelease Tag Input
id: get_rc_tag_input
shell: bash
run: echo "rc_tag_name=${{ github.event.inputs.rc_tag }}" >> $GITHUB_OUTPUT
- name: Validate Prerelease Tag Format
id: validate_rc_tag
shell: bash
run: |
rc_tag="${{ steps.get_rc_tag_input.outputs.rc_tag_name }}"
if [[ ! "$rc_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-(rc|beta)\.[0-9]+$ ]]; then
echo "::error::Invalid prerelease tag format: $rc_tag. Expected format: vX.Y.Z-rc.N or vX.Y.Z-beta.N"
exit 1
fi
echo "Prerelease tag $rc_tag is valid."
- name: Extract Final Version from Prerelease Tag
id: extract_final_version
shell: bash
run: |
rc_tag="${{ steps.get_rc_tag_input.outputs.rc_tag_name }}"
final_version_tag=$(echo "$rc_tag" | sed -E 's/-(rc|beta)\.[0-9]+$//')
final_version_number=$(echo "$final_version_tag" | sed 's/^v//')
echo "final_version_tag=$final_version_tag" >> $GITHUB_OUTPUT
echo "final_version_number=$final_version_number" >> $GITHUB_OUTPUT
echo "Extracted final version tag: $final_version_tag"
echo "Extracted final version number: $final_version_number"
- name: Checkout Code at Prerelease Tag
uses: actions/checkout@v6
with:
token: ${{ secrets.PAT_TOKEN }}
ref: ${{ steps.get_rc_tag_input.outputs.rc_tag_name }} # Checkout the specific prerelease tag
submodules: recursive
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Cache Bun dependencies
uses: actions/cache@v5
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ hashFiles('Frontend/bun.lock') }}
restore-keys: bun-${{ runner.os }}-
- name: Cache NuGet packages
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/packages.lock.json') }}
restore-keys: nuget-${{ runner.os }}-
- name: Configure Git User
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
shell: pwsh
- name: Update Frontend package.json with Final Version
id: update_frontend_version
working-directory: ./Frontend
shell: pwsh
run: |
$finalVersion = "${{ steps.extract_final_version.outputs.final_version_number }}"
Write-Host "Updating Frontend package.json to version: $finalVersion"
$packageJson = Get-Content package.json -Raw | ConvertFrom-Json
$packageJson.version = $finalVersion
$packageJson | ConvertTo-Json -Depth 100 | Set-Content package.json -NoNewline
Write-Host "Updated Frontend version in package.json: $(Select-String -Path package.json -Pattern 'version')"
- name: Install Frontend dependencies
working-directory: ./Frontend
run: bun install --frozen-lockfile
- name: Build Frontend
working-directory: ./Frontend
run: bun run build
- name: Move Frontend Build to Resources/wwwroot
run: |
$source = "./Frontend/dist"
$destination = "./Resources/wwwroot"
if (-Not (Test-Path -Path $destination)) { New-Item -ItemType Directory -Path $destination -Force }
Remove-Item -Path "$destination\*" -Recurse -Force
Copy-Item -Path "$source\*" -Destination $destination -Recurse -Force
shell: pwsh
- name: Install vpk as .NET Global Tool
run: |
dotnet tool install -g vpk
$env:PATH += ";$env:USERPROFILE\.dotnet\tools"
shell: pwsh
- name: Publish the App
run: dotnet publish -c Release --self-contained -r win-x64 -o publish
shell: pwsh
- name: Package with vpk for Final Release
run: vpk pack -u Segra -v ${{ steps.extract_final_version.outputs.final_version_number }} -p ./publish -e Segra.exe -o ./output --packTitle "Segra" --noPortable
shell: pwsh
- name: Create Final Git Tag
id: create_final_tag
shell: pwsh
env:
GH_PAT: ${{ secrets.PAT_TOKEN }}
run: |
$final_tag = "${{ steps.extract_final_version.outputs.final_version_tag }}"
Write-Host "Creating final Git tag: $final_tag"
# Override the default remote to use the PAT
git remote set-url origin https://x-access-token:${env:GH_PAT}@github.com/${{ github.repository }}.git
git tag $final_tag
git push origin $final_tag
echo "final_version_tag=$final_tag" >> $env:GITHUB_OUTPUT
Write-Host "Final Git tag $final_tag created and pushed."
- name: Upload Final Release Artifact (for release job)
uses: actions/upload-artifact@v7
with:
name: Segra-Final-Build
path: ./output
retention-days: 1
create_github_release:
needs: build_and_release
runs-on: ubuntu-latest
permissions:
contents: write # Required to create a release
steps:
- name: Download Final Build Artifact
uses: actions/download-artifact@v8
with:
name: Segra-Final-Build
- name: Create Final GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.build_and_release.outputs.final_version_tag }}
name: "Release ${{ needs.build_and_release.outputs.final_version_tag }}"
prerelease: false
generate_release_notes: false
files: |
./Segra-win-Setup.exe
./RELEASES
./releases.win.json
./assets.win.json
./Segra-${{ needs.build_and_release.outputs.final_version_number }}-full.nupkg