feat(ci): Add automatic release on tag push #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ master ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ master ] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version to create (e.g., v1.0.0-preview or 1.0.0-preview)' | |
| required: true | |
| jobs: | |
| build_and_test: | |
| runs-on: macos-latest | |
| name: Build and test on macOS | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' | |
| include-prerelease: true | |
| - name: Install UPX | |
| run: brew install upx | |
| - name: Determine version from tag or input | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| # Triggered by tag push | |
| VERSION="${{ github.ref_name }}" | |
| echo "Triggered by tag: ${VERSION}" | |
| elif [[ -n "${{ github.event.inputs.version }}" ]]; then | |
| # Triggered by workflow_dispatch | |
| VERSION="${{ github.event.inputs.version }}" | |
| echo "Triggered by workflow_dispatch: ${VERSION}" | |
| else | |
| # Triggered by push to master or PR | |
| VERSION="" | |
| echo "Triggered by push/PR: No version" | |
| fi | |
| if [[ -n "${VERSION}" ]]; then | |
| # Remove 'v' prefix if present for NuGet | |
| VERSION_NO_V="${VERSION#v}" | |
| echo "nuget_version=${VERSION_NO_V}" >> $GITHUB_OUTPUT | |
| echo "git_tag=v${VERSION_NO_V}" >> $GITHUB_OUTPUT | |
| echo "should_release=true" >> $GITHUB_OUTPUT | |
| echo "NuGet Version: ${VERSION_NO_V}" | |
| echo "Git Tag: v${VERSION_NO_V}" | |
| else | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| echo "No release will be created" | |
| fi | |
| - name: Build Package (CI - No Release) | |
| if: ${{ steps.version.outputs.should_release != 'true' }} | |
| run: | | |
| dotnet build -t:Pack src/PublishAotCompressed.macOS.nuproj | |
| - name: Test - Build for macOS (should skip UPX) | |
| if: ${{ steps.version.outputs.should_release != 'true' }} | |
| run: | | |
| dotnet publish -r osx-arm64 -c Release test/Hello.csproj | |
| ls -lh test/bin/Release/net9.0/osx-arm64/publish/ | |
| - name: Build Package (Release) | |
| if: ${{ steps.version.outputs.should_release == 'true' }} | |
| run: dotnet build -t:Pack src/PublishAotCompressed.macOS.nuproj -p:Version=${{ steps.version.outputs.nuget_version }} | |
| - name: Archive NuGet Package | |
| if: ${{ steps.version.outputs.should_release == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg | |
| path: src/bin/Debug/PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg | |
| - name: Publish to NuGet.org | |
| if: ${{ steps.version.outputs.should_release == 'true' }} | |
| run: | | |
| dotnet nuget push src/bin/Debug/PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| - name: Create Release Tag | |
| if: ${{ steps.version.outputs.should_release == 'true' && github.event_name == 'workflow_dispatch' }} | |
| run: | | |
| git config user.name github-actions | |
| git config user.email github-actions@github.com | |
| git tag ${{ steps.version.outputs.git_tag }} | |
| git push origin ${{ steps.version.outputs.git_tag }} | |
| - name: Create GitHub Release | |
| if: ${{ steps.version.outputs.should_release == 'true' }} | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.version.outputs.git_tag }} | |
| name: ${{ steps.version.outputs.git_tag }} | |
| body: | | |
| ## PublishAotCompressed.macOS ${{ steps.version.outputs.git_tag }} | |
| Automatic UPX compression for .NET Native AOT cross-compilation from macOS. | |
| ### Installation | |
| ```xml | |
| <PackageReference Include="PublishAotCompressed.macOS" Version="${{ steps.version.outputs.nuget_version }}" /> | |
| ``` | |
| ### Quick Start | |
| ```bash | |
| dotnet publish -r win-x64 -c Release | |
| ``` | |
| See [README.md](https://github.com/interface95/PublishAotCompressed.macOS/blob/master/README.md) for details. | |
| files: src/bin/Debug/PublishAotCompressed.macOS.${{ steps.version.outputs.nuget_version }}.nupkg | |
| prerelease: ${{ contains(steps.version.outputs.nuget_version, 'preview') || contains(steps.version.outputs.nuget_version, 'alpha') || contains(steps.version.outputs.nuget_version, 'beta') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |