diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27e4fa1..9002af7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,9 +6,13 @@ name: .NET on: push: branches: [ "main" ] + tags: [ "v*" ] pull_request: branches: [ "main" ] +env: + VERSION: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && github.ref_name || '0.0.0-local' }} + jobs: test: runs-on: ubuntu-latest @@ -21,22 +25,16 @@ jobs: - name: Restore run: dotnet restore - name: Build - run: dotnet build --no-restore -c Release + run: dotnet build --no-restore -c Release /p:Version=${{ env.VERSION }} - name: Test run: dotnet test -c Release --no-build --verbosity normal publish: needs: test - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: matrix: - include: - - os: ubuntu-latest - rid: linux-x64 - - os: macos-latest - rid: osx-x64 - - os: windows-latest - rid: win-x64 + rid: [ linux-x64, osx-x64, win-x64 ] steps: - uses: actions/checkout@v4 - name: Setup .NET @@ -44,9 +42,38 @@ jobs: with: dotnet-version: 8.0.x - name: Publish self-contained single file - run: dotnet publish src/CsvToOfx.Cli/CsvToOfx.Cli.csproj -c Release -r ${{ matrix.rid }} --self-contained true /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true + run: dotnet publish src/CsvToOfx.Cli/CsvToOfx.Cli.csproj -c Release -r ${{ matrix.rid }} --self-contained true /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true /p:Version=${{ env.VERSION }} + - name: Archive artifact + run: | + cd src/CsvToOfx.Cli/bin/Release/net8.0/${{ matrix.rid }}/publish + zip -r ../../csv2ofx-${{ env.VERSION }}-${{ matrix.rid }}.zip . - name: Upload artifact uses: actions/upload-artifact@v4 with: name: csv2ofx-${{ matrix.rid }} path: src/CsvToOfx.Cli/bin/Release/net8.0/${{ matrix.rid }}/publish/ + - name: Upload release zip + uses: actions/upload-artifact@v4 + with: + name: csv2ofx-zip-${{ matrix.rid }} + path: src/CsvToOfx.Cli/bin/Release/net8.0/csv2ofx-${{ env.VERSION }}-${{ matrix.rid }}.zip + + release: + needs: publish + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + path: ./artifacts + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ github.ref_name }} + tag_name: ${{ github.ref_name }} + files: | + artifacts/csv2ofx-zip-linux-x64/csv2ofx-${{ env.VERSION }}-linux-x64.zip + artifacts/csv2ofx-zip-osx-x64/csv2ofx-${{ env.VERSION }}-osx-x64.zip + artifacts/csv2ofx-zip-win-x64/csv2ofx-${{ env.VERSION }}-win-x64.zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}