11name : CI
22
33on :
4+ push :
5+ branches : [ master ]
6+ tags :
7+ - ' v*'
8+
49 pull_request :
510 branches : [ master ]
611
@@ -27,58 +32,76 @@ jobs:
2732 - name : Install UPX
2833 run : brew install upx
2934
30- - name : Prepare version strings
31- if : ${{ github.event.inputs.version != '' }}
35+ - name : Determine version from tag or input
3236 id : version
3337 run : |
34- VERSION="${{ github.event.inputs.version }}"
35- # Remove 'v' prefix if present
36- VERSION_NO_V="${VERSION#v}"
37- echo "nuget_version=${VERSION_NO_V}" >> $GITHUB_OUTPUT
38- echo "git_tag=v${VERSION_NO_V}" >> $GITHUB_OUTPUT
39- echo "NuGet Version: ${VERSION_NO_V}"
40- echo "Git Tag: v${VERSION_NO_V}"
38+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
39+ # Triggered by tag push
40+ VERSION="${{ github.ref_name }}"
41+ echo "Triggered by tag: ${VERSION}"
42+ elif [[ -n "${{ github.event.inputs.version }}" ]]; then
43+ # Triggered by workflow_dispatch
44+ VERSION="${{ github.event.inputs.version }}"
45+ echo "Triggered by workflow_dispatch: ${VERSION}"
46+ else
47+ # Triggered by push to master or PR
48+ VERSION=""
49+ echo "Triggered by push/PR: No version"
50+ fi
51+
52+ if [[ -n "${VERSION}" ]]; then
53+ # Remove 'v' prefix if present for NuGet
54+ VERSION_NO_V="${VERSION#v}"
55+ echo "nuget_version=${VERSION_NO_V}" >> $GITHUB_OUTPUT
56+ echo "git_tag=v${VERSION_NO_V}" >> $GITHUB_OUTPUT
57+ echo "should_release=true" >> $GITHUB_OUTPUT
58+ echo "NuGet Version: ${VERSION_NO_V}"
59+ echo "Git Tag: v${VERSION_NO_V}"
60+ else
61+ echo "should_release=false" >> $GITHUB_OUTPUT
62+ echo "No release will be created"
63+ fi
4164
42- - name : Build Package (CI)
43- if : ${{ github.event.inputs.version == ' ' }}
65+ - name : Build Package (CI - No Release )
66+ if : ${{ steps.version.outputs.should_release != 'true ' }}
4467 run : |
4568 dotnet build -t:Pack src/PublishAotCompressed.macOS.nuproj
4669
4770 - name : Test - Build for macOS (should skip UPX)
48- if : ${{ github.event.inputs.version == ' ' }}
71+ if : ${{ steps.version.outputs.should_release != 'true ' }}
4972 run : |
5073 dotnet publish -r osx-arm64 -c Release test/Hello.csproj
5174 ls -lh test/bin/Release/net9.0/osx-arm64/publish/
5275
53- - name : Build Package (CD )
54- if : ${{ github.event.inputs.version != ' ' }}
76+ - name : Build Package (Release )
77+ if : ${{ steps.version.outputs.should_release == 'true ' }}
5578 run : dotnet build -t:Pack src/PublishAotCompressed.macOS.nuproj -p:Version=${{ steps.version.outputs.nuget_version }}
5679
5780 - name : Archive NuGet Package
58- if : ${{ github.event.inputs.version != ' ' }}
81+ if : ${{ steps.version.outputs.should_release == 'true ' }}
5982 uses : actions/upload-artifact@v4
6083 with :
6184 name : PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg
6285 path : src/bin/Debug/PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg
6386
6487 - name : Publish to NuGet.org
65- if : ${{ github.event.inputs.version != ' ' }}
88+ if : ${{ steps.version.outputs.should_release == 'true ' }}
6689 run : |
6790 dotnet nuget push src/bin/Debug/PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg \
6891 --api-key ${{ secrets.NUGET_API_KEY }} \
6992 --source https://api.nuget.org/v3/index.json \
7093 --skip-duplicate
7194
7295 - name : Create Release Tag
73- if : ${{ github.event.inputs.version != ' ' }}
96+ if : ${{ steps.version.outputs.should_release == 'true' && github.event_name == 'workflow_dispatch ' }}
7497 run : |
7598 git config user.name github-actions
7699 git config user.email github-actions@github.com
77100 git tag ${{ steps.version.outputs.git_tag }}
78101 git push origin ${{ steps.version.outputs.git_tag }}
79102
80103 - name : Create GitHub Release
81- if : ${{ github.event.inputs.version != ' ' }}
104+ if : ${{ steps.version.outputs.should_release == 'true ' }}
82105 uses : softprops/action-gh-release@v1
83106 with :
84107 tag_name : ${{ steps.version.outputs.git_tag }}
0 commit comments