|
| 1 | +# Build on push and pull request. |
| 2 | +# create a draft release with built binaries and changelog, when a tag like "v0.1.0" is pushed. |
| 3 | + |
| 4 | +name: Build |
| 5 | + |
| 6 | +on: [push, pull_request, workflow_dispatch] |
| 7 | + |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-draft-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + release_upload_url: ${{ steps.create-draft-release.outputs.upload_url }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Create draft release |
| 19 | + id: create-draft-release |
| 20 | + uses: ncipollo/release-action@v1 |
| 21 | + if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') |
| 22 | + with: |
| 23 | + draft: true |
| 24 | + generateReleaseNotes: true |
| 25 | + |
| 26 | + build-and-upload-artifact: |
| 27 | + needs: create-draft-release |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - os: ubuntu-latest |
| 34 | + target: x86_64-unknown-linux-gnu |
| 35 | + artifact-name: ubuntu-x86_64-gnu |
| 36 | + prebuild-config: | |
| 37 | + sudo apt-get update |
| 38 | + sudo apt-get install -y libasound2-dev |
| 39 | +
|
| 40 | + - os: windows-latest |
| 41 | + target: x86_64-pc-windows-msvc |
| 42 | + artifact-name: windows-x86_64-msvc |
| 43 | + |
| 44 | + - os: macos-latest |
| 45 | + target: x86_64-apple-darwin |
| 46 | + artifact-name: macos-x86_64 |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + |
| 51 | + - name: Set exe extension for Windows |
| 52 | + run: echo "EXE=.exe" >> $env:GITHUB_ENV |
| 53 | + if: startsWith(matrix.os, 'windows') |
| 54 | + |
| 55 | + - name: Install `rust` toolchain |
| 56 | + uses: actions-rs/toolchain@v1 |
| 57 | + with: |
| 58 | + toolchain: stable |
| 59 | + override: true |
| 60 | + profile: minimal |
| 61 | + target: ${{ matrix.target }} |
| 62 | + |
| 63 | + - name: Prebuild config |
| 64 | + run: ${{ matrix.prebuild-config }} |
| 65 | + |
| 66 | + - name: Build |
| 67 | + run: cargo build --release --target=${{ matrix.target }} |
| 68 | + |
| 69 | + - name: Run tests |
| 70 | + run: cargo test --release |
| 71 | + |
| 72 | + - name: Upload artifact |
| 73 | + uses: actions/upload-artifact@v3 |
| 74 | + with: |
| 75 | + name: ${{ matrix.artifact-name }} |
| 76 | + path: target/${{ matrix.target }}/release/mfp${{ env.EXE }} |
| 77 | + |
| 78 | + - name: Get version from tag |
| 79 | + id: extract-version |
| 80 | + run: | |
| 81 | + echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT |
| 82 | + shell: bash |
| 83 | + |
| 84 | + - name: Upload artifact to release |
| 85 | + uses: shogo82148/actions-upload-release-asset@v1 |
| 86 | + if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') |
| 87 | + with: |
| 88 | + upload_url: ${{ needs.create-draft-release.outputs.release_upload_url }} |
| 89 | + asset_name: mfp-${{ steps.extract-version.outputs.version }}-${{ matrix.artifact-name }}${{ env.EXE }} |
| 90 | + asset_path: target/${{ matrix.target }}/release/mfp${{ env.EXE }} |
0 commit comments