|
| 1 | +name: release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + tags: |
| 7 | + - v*.*.* |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + include: |
| 15 | + - { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, suffix: .tar.gz } |
| 16 | + - { target: x86_64-apple-darwin, os: macos-latest, suffix: .tar.gz } |
| 17 | + - { target: aarch64-apple-darwin, os: macos-latest, suffix: .tar.gz } |
| 18 | + - { target: x86_64-pc-windows-msvc, os: windows-latest, suffix: .zip } |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - uses: actions-rs/toolchain@v1 |
| 23 | + with: |
| 24 | + toolchain: stable |
| 25 | + profile: minimal |
| 26 | + target: ${{ matrix.target }} |
| 27 | + override: true |
| 28 | + - name: Cache Dependencies |
| 29 | + uses: Swatinem/rust-cache@v1 |
| 30 | + with: |
| 31 | + key: ${{ matrix.target }} |
| 32 | + - uses: actions-rs/cargo@v1 |
| 33 | + with: |
| 34 | + command: build |
| 35 | + args: --target ${{ matrix.target }} --release |
| 36 | + |
| 37 | + - name: (Not Windows) Move executables and compress |
| 38 | + if: ${{ matrix.os != 'windows-latest' }} |
| 39 | + run: | |
| 40 | + mkdir ${{ matrix.target }} |
| 41 | + for bin in src/bin/*.rs; do |
| 42 | + mv target/${{ matrix.target }}/release/$(basename $bin .rs) ${{ matrix.target }}; |
| 43 | + done |
| 44 | + tar -zcvf ${{ matrix.target }}.tar.gz ${{ matrix.target }} |
| 45 | +
|
| 46 | + - name: (Windows) Move executables and compress |
| 47 | + if: ${{ matrix.os == 'windows-latest' }} |
| 48 | + run: | |
| 49 | + mkdir ${{ matrix.target }} |
| 50 | + $bins = Get-ChildItem -Path src/bin -Recurse -Filter "*.rs" |
| 51 | + foreach ($b in $bins) { |
| 52 | + Move-Item -Path ("target/${{ matrix.target }}/release/" + $b.BaseName + ".exe") -Destination "${{ matrix.target }}/" |
| 53 | + } |
| 54 | + Compress-Archive -Path ${{ matrix.target }} -DestinationPath ${{ matrix.target }}.zip |
| 55 | +
|
| 56 | + - uses: actions/upload-artifact@v3 |
| 57 | + with: |
| 58 | + name: ${{ matrix.target }} |
| 59 | + path: ${{ matrix.target }}${{ matrix.suffix }} |
| 60 | + |
| 61 | + release: |
| 62 | + name: release |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [build] |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v3 |
| 67 | + - uses: actions/download-artifact@v3 |
| 68 | + with: |
| 69 | + path: artifacts |
| 70 | + - run: ls -R ./artifacts |
| 71 | + |
| 72 | + - name: Set current date as environment variable |
| 73 | + run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV |
| 74 | + |
| 75 | + - id: changelog-reader |
| 76 | + |
| 77 | + with: |
| 78 | + version: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }} |
| 79 | + |
| 80 | + - uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + tag_name: ${{ steps.changelog-reader.outputs.version }} |
| 83 | + name: ${{ (github.ref_type == 'tag' && steps.changelog-reader.outputs.version) || format('Prereleased {0}', env.CURRENT_DATE) }} |
| 84 | + body: ${{ steps.changelog-reader.outputs.changes }} |
| 85 | + prerelease: ${{ steps.changelog-reader.outputs.status == 'unreleased' }} |
| 86 | + files: | |
| 87 | + artifacts/**/* |
0 commit comments