|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-release: |
| 13 | + name: Build and Release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup .NET |
| 23 | + uses: actions/setup-dotnet@v4 |
| 24 | + with: |
| 25 | + dotnet-version: '8.0.x' |
| 26 | + |
| 27 | + - name: Get version from tag |
| 28 | + id: get_version |
| 29 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 30 | + |
| 31 | + - name: Restore dependencies |
| 32 | + run: dotnet restore |
| 33 | + |
| 34 | + - name: Build |
| 35 | + run: dotnet build --configuration Release --no-restore |
| 36 | + |
| 37 | + - name: Run tests |
| 38 | + run: dotnet test --configuration Release --no-build --verbosity normal |
| 39 | + |
| 40 | + - name: Publish Linux x64 |
| 41 | + run: | |
| 42 | + dotnet publish src/TaskManager.CLI/TaskManager.CLI.csproj \ |
| 43 | + -c Release \ |
| 44 | + -r linux-x64 \ |
| 45 | + --self-contained \ |
| 46 | + -p:PublishSingleFile=true \ |
| 47 | + -p:PublishTrimmed=true \ |
| 48 | + -o ./publish/linux-x64 |
| 49 | +
|
| 50 | + - name: Publish Windows x64 |
| 51 | + run: | |
| 52 | + dotnet publish src/TaskManager.CLI/TaskManager.CLI.csproj \ |
| 53 | + -c Release \ |
| 54 | + -r win-x64 \ |
| 55 | + --self-contained \ |
| 56 | + -p:PublishSingleFile=true \ |
| 57 | + -p:PublishTrimmed=true \ |
| 58 | + -o ./publish/win-x64 |
| 59 | +
|
| 60 | + - name: Publish macOS x64 |
| 61 | + run: | |
| 62 | + dotnet publish src/TaskManager.CLI/TaskManager.CLI.csproj \ |
| 63 | + -c Release \ |
| 64 | + -r osx-x64 \ |
| 65 | + --self-contained \ |
| 66 | + -p:PublishSingleFile=true \ |
| 67 | + -p:PublishTrimmed=true \ |
| 68 | + -o ./publish/osx-x64 |
| 69 | +
|
| 70 | + - name: Publish macOS ARM64 |
| 71 | + run: | |
| 72 | + dotnet publish src/TaskManager.CLI/TaskManager.CLI.csproj \ |
| 73 | + -c Release \ |
| 74 | + -r osx-arm64 \ |
| 75 | + --self-contained \ |
| 76 | + -p:PublishSingleFile=true \ |
| 77 | + -p:PublishTrimmed=true \ |
| 78 | + -o ./publish/osx-arm64 |
| 79 | +
|
| 80 | + - name: Create archives |
| 81 | + run: | |
| 82 | + cd publish |
| 83 | + tar -czf taskman-linux-x64-${{ steps.get_version.outputs.VERSION }}.tar.gz -C linux-x64 . |
| 84 | + zip -r taskman-win-x64-${{ steps.get_version.outputs.VERSION }}.zip win-x64 |
| 85 | + tar -czf taskman-macos-x64-${{ steps.get_version.outputs.VERSION }}.tar.gz -C osx-x64 . |
| 86 | + tar -czf taskman-macos-arm64-${{ steps.get_version.outputs.VERSION }}.tar.gz -C osx-arm64 . |
| 87 | +
|
| 88 | + - name: Generate checksums |
| 89 | + run: | |
| 90 | + cd publish |
| 91 | + sha256sum *.tar.gz *.zip > SHA256SUMS |
| 92 | +
|
| 93 | + - name: Extract changelog |
| 94 | + id: changelog |
| 95 | + run: | |
| 96 | + # Extract changelog for this version |
| 97 | + VERSION=${{ steps.get_version.outputs.VERSION }} |
| 98 | + sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$ d' > RELEASE_NOTES.md |
| 99 | + if [ ! -s RELEASE_NOTES.md ]; then |
| 100 | + echo "Release $VERSION" > RELEASE_NOTES.md |
| 101 | + echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> RELEASE_NOTES.md |
| 102 | + fi |
| 103 | +
|
| 104 | + - name: Create Release |
| 105 | + uses: softprops/action-gh-release@v1 |
| 106 | + with: |
| 107 | + name: Release ${{ steps.get_version.outputs.VERSION }} |
| 108 | + body_path: RELEASE_NOTES.md |
| 109 | + files: | |
| 110 | + publish/taskman-linux-x64-${{ steps.get_version.outputs.VERSION }}.tar.gz |
| 111 | + publish/taskman-win-x64-${{ steps.get_version.outputs.VERSION }}.zip |
| 112 | + publish/taskman-macos-x64-${{ steps.get_version.outputs.VERSION }}.tar.gz |
| 113 | + publish/taskman-macos-arm64-${{ steps.get_version.outputs.VERSION }}.tar.gz |
| 114 | + publish/SHA256SUMS |
| 115 | + draft: false |
| 116 | + prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }} |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Build NuGet package |
| 121 | + run: dotnet pack src/TaskManager.CLI/TaskManager.CLI.csproj -c Release -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} |
| 122 | + |
| 123 | + - name: Publish to NuGet (optional) |
| 124 | + if: ${{ !contains(github.ref, '-rc') && !contains(github.ref, '-beta') && !contains(github.ref, '-alpha') }} |
| 125 | + run: dotnet nuget push src/TaskManager.CLI/bin/Release/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |
| 126 | + continue-on-error: true |
0 commit comments