|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ${{ matrix.os }}-latest |
| 14 | + needs: [publish] |
| 15 | + |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + os: [ubuntu, macos, windows] |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Set up Rust |
| 25 | + uses: ATiltedTree/setup-rust@v1 |
| 26 | + with: |
| 27 | + rust-version: stable |
| 28 | + |
| 29 | + - name: Build application |
| 30 | + run: cargo build --profile dist |
| 31 | + |
| 32 | + - name: Upload Release Asset (Linux & macOS) |
| 33 | + if: matrix.os != 'windows' |
| 34 | + run: |
| 35 | + mv target/dist/dsp-calculator dsp-calculator-${{ matrix.os }} && |
| 36 | + gh release upload ${{ github.ref_name }} dsp-calculator-${{ matrix.os }} --clobber |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Upload Release Asset (Windows) |
| 41 | + if: matrix.os == 'windows' |
| 42 | + run: |
| 43 | + mv target/dist/dsp-calculator.exe dsp-calculator-${{ matrix.os }}.exe && |
| 44 | + gh release upload ${{ github.ref_name }} dsp-calculator-${{ matrix.os }}.exe --clobber |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + |
| 48 | + publish: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + ref: ${{ github.ref }} |
| 55 | + fetch-depth: 1 |
| 56 | + |
| 57 | + - name: Check if pre-release |
| 58 | + id: prerelease_check |
| 59 | + run: | |
| 60 | + MAJOR_VERSION=$(echo "${{ github.ref }}" | sed -E 's/^refs\/tags\/v([0-9]+)\..*$/\1/') |
| 61 | + if [[ $MAJOR_VERSION == "0" ]]; then |
| 62 | + echo "Pre-release" |
| 63 | + echo "::set-output name=is_prerelease::--prerelease" |
| 64 | + else |
| 65 | + echo "Not a pre-release" |
| 66 | + echo "::set-output name=is_prerelease:: " |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Create Release |
| 70 | + id: create_release |
| 71 | + run: | |
| 72 | + gh release create ${{ github.ref }} \ |
| 73 | + --title "${{ github.ref_name }}" \ |
| 74 | + --generate-notes \ |
| 75 | + ${{ steps.prerelease_check.outputs.is_prerelease }} |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments