@@ -2,14 +2,16 @@ name: Build and Release
22
33on :
44 push :
5- tags :
6- - ' v*'
5+ branches : [ "main" ]
76 workflow_dispatch :
87
8+ permissions :
9+ contents : write
10+
911jobs :
10- build :
12+ release :
1113 runs-on : windows-latest
12-
14+
1315 steps :
1416 - name : Checkout code
1517 uses : actions/checkout@v4
@@ -19,47 +21,80 @@ jobs:
1921 - name : Setup .NET
2022 uses : actions/setup-dotnet@v4
2123 with :
22- dotnet-version : ' 10.0.x'
24+ dotnet-version : ' 10.0.x'
2325 dotnet-quality : ' preview'
2426
27+ - name : Get Version
28+ id : get_version
29+ shell : pwsh
30+ run : |
31+ $path = "src/LightSteamAccountSwitcher/LightSteamAccountSwitcher.csproj"
32+ [xml]$xml = Get-Content $path
33+ # Prioritize Version, then AssemblyVersion, then 1.0.0
34+ $ver = $xml.Project.PropertyGroup.Version
35+ if ([string]::IsNullOrWhiteSpace($ver)) { $ver = $xml.Project.PropertyGroup.AssemblyVersion }
36+ if ([string]::IsNullOrWhiteSpace($ver)) { $ver = "1.0.0" }
37+
38+ echo "Detected Version: $ver"
39+ echo "version=$ver" >> $env:GITHUB_OUTPUT
40+
41+ - name : Check and Tag
42+ id : tag_check
43+ shell : bash
44+ env :
45+ VERSION : ${{ steps.get_version.outputs.version }}
46+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
47+ run : |
48+ TAG="v$VERSION"
49+ if git rev-parse "$TAG" >/dev/null 2>&1; then
50+ echo "Tag $TAG already exists. Skipping release."
51+ echo "new_tag=false" >> "$GITHUB_OUTPUT"
52+ else
53+ echo "Tag $TAG does not exist. Creating..."
54+ git config user.name "github-actions[bot]"
55+ git config user.email "github-actions[bot]@users.noreply.github.com"
56+ git tag "$TAG"
57+ git push origin "$TAG"
58+ echo "new_tag=true" >> "$GITHUB_OUTPUT"
59+ fi
60+
2561 - name : Restore dependencies
62+ if : steps.tag_check.outputs.new_tag == 'true'
2663 run : dotnet restore LightSteamAccountSwitcher.slnx
2764
28- - name : Build
29- run : dotnet build LightSteamAccountSwitcher.slnx --configuration Release --no-restore
30-
3165 - name : Publish
66+ if : steps.tag_check.outputs.new_tag == 'true'
3267 run : |
33- dotnet publish src/LightSteamAccountSwitcher/LightSteamAccountSwitcher.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o ./publish
68+ dotnet publish src/LightSteamAccountSwitcher/LightSteamAccountSwitcher.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=None - o ./publish
3469
3570 - name : Generate Changelog
71+ if : steps.tag_check.outputs.new_tag == 'true'
3672 id : changelog
3773 shell : bash
3874 run : |
39- # Get the previous tag
40- PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
75+ TAG="v${{ steps.get_version.outputs.version }}"
76+ # Find the tag before the current one
77+ PREV_TAG=$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || echo "")
4178
4279 if [ -z "$PREV_TAG" ]; then
43- echo "No previous tag found. Summarizing all commits."
44- SUMMARY=$(git log --pretty=format:"- %s (%h)" --no-merges)
80+ echo "No previous tag found. Summarizing all commits up to $TAG ."
81+ SUMMARY=$(git log --pretty=format:"- %s (%h)" --no-merges "$TAG" )
4582 else
46- echo "Summarizing commits since $PREV_TAG"
47- SUMMARY=$(git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges)
83+ echo "Summarizing commits between $PREV_TAG and $TAG "
84+ SUMMARY=$(git log " $PREV_TAG..$TAG" --pretty=format:"- %s (%h)" --no-merges)
4885 fi
4986
50- {
51- echo "summary<<EOF"
52- echo "$SUMMARY"
53- echo "EOF"
54- } >> "$GITHUB_OUTPUT"
87+ echo "summary<<EOF" >> "$GITHUB_OUTPUT"
88+ echo "$SUMMARY" >> "$GITHUB_OUTPUT"
89+ echo "EOF" >> "$GITHUB_OUTPUT"
5590
5691 - name : Create Release
57- uses : softprops/action-gh-release@v1
92+ if : steps.tag_check.outputs.new_tag == 'true'
93+ uses : softprops/action-gh-release@v2
5894 with :
59- files : |
60- ./publish/LightSteamAccountSwitcher.exe
61- ./publish/*.dll
62- ./publish/*.json
95+ tag_name : v${{ steps.get_version.outputs.version }}
96+ name : Release v${{ steps.get_version.outputs.version }}
97+ files : ./publish/LightSteamAccountSwitcher.exe
6398 body : |
6499 ## Changes
65100 ${{ steps.changelog.outputs.summary }}
0 commit comments