|
| 1 | +--- |
| 2 | +name: Release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + |
| 9 | +jobs: |
| 10 | + preflight: |
| 11 | + name: Preflight checks |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - name: Check that tag matches version in Cargo.toml |
| 16 | + run: | |
| 17 | + version=$(cargo pkgid | cut -d'#' -f2) |
| 18 | + if [ "$version" != "${{ github.ref_name }}" ]; then |
| 19 | + echo "Tag version does not match Cargo.toml version" |
| 20 | + echo "Tag: ${{ github.ref_name }}, Cargo.toml: $version" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | +
|
| 24 | + ci: |
| 25 | + name: Run CI |
| 26 | + needs: preflight |
| 27 | + uses: ./.github/workflows/ci-reusable.yml |
| 28 | + |
| 29 | + release: |
| 30 | + needs: ci |
| 31 | + runs-on: ${{ matrix.runs-on }} |
| 32 | + timeout-minutes: 15 |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + include: |
| 37 | + - runs-on: windows-latest |
| 38 | + target: x86_64-pc-windows-msvc |
| 39 | + |
| 40 | + - runs-on: windows-latest |
| 41 | + target: i686-pc-windows-msvc |
| 42 | + |
| 43 | + - runs-on: windows-latest |
| 44 | + target: aarch64-pc-windows-msvc |
| 45 | + |
| 46 | + - runs-on: ubuntu-latest |
| 47 | + target: x86_64-unknown-linux-musl |
| 48 | + |
| 49 | + - runs-on: ubuntu-latest |
| 50 | + target: i686-unknown-linux-musl |
| 51 | + |
| 52 | + - runs-on: ubuntu-latest |
| 53 | + target: aarch64-unknown-linux-musl |
| 54 | + |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 59 | + with: |
| 60 | + components: clippy, rustfmt |
| 61 | + rustflags: "" |
| 62 | + target: ${{ matrix.target }} |
| 63 | + |
| 64 | + - name: Install cross |
| 65 | + if: ${{ matrix.runs-on == 'ubuntu-latest' }} |
| 66 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 67 | + |
| 68 | + # This step seems absolutely necessary for 'cross' to work. |
| 69 | + - name: Clean build cache |
| 70 | + run: cargo clean |
| 71 | + |
| 72 | + - name: Build (Windows) |
| 73 | + if: ${{ matrix.runs-on == 'windows-latest' }} |
| 74 | + run: cargo build --release --all-features --target=${{ matrix.target }} |
| 75 | + |
| 76 | + - name: Build (Linux, cross compile) |
| 77 | + if: ${{ matrix.runs-on == 'ubuntu-latest' }} |
| 78 | + run: cross build --release --all-features --target=${{ matrix.target }} |
| 79 | + |
| 80 | + - name: Create a zip (windows) |
| 81 | + id: create-zip |
| 82 | + if: ${{ matrix.runs-on == 'windows-latest' }} |
| 83 | + run: | |
| 84 | + mkdir release |
| 85 | + cp LICENSE release/ |
| 86 | + cp target/${{ matrix.target }}/release/csm.exe release/ |
| 87 | + Compress-Archive -Path release/ -DestinationPath csm-${{ github.ref_name }}-${{ matrix.target }}.zip |
| 88 | +
|
| 89 | + - name: Create a tar.gz (linux) |
| 90 | + id: create-tar |
| 91 | + if: ${{ matrix.runs-on == 'ubuntu-latest' }} |
| 92 | + run: | |
| 93 | + mkdir release |
| 94 | + cp LICENSE release/ |
| 95 | + cp target/${{ matrix.target }}/release/csm release/ |
| 96 | + tar -czvf csm-${{ github.ref_name }}-${{ matrix.target }}.tar.gz release/ |
| 97 | +
|
| 98 | + - name: Release |
| 99 | + uses: softprops/action-gh-release@v2 |
| 100 | + if: github.ref_type == 'tag' |
| 101 | + with: |
| 102 | + files: | |
| 103 | + csm*.zip |
| 104 | + csm*.tar.gz |
| 105 | +
|
| 106 | + test-release: |
| 107 | + name: Post-release test |
| 108 | + needs: release |
| 109 | + runs-on: ${{ matrix.runs-on }} |
| 110 | + timeout-minutes: 15 |
| 111 | + strategy: |
| 112 | + fail-fast: false |
| 113 | + matrix: |
| 114 | + include: |
| 115 | + - runs-on: windows-latest |
| 116 | + - runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - name: Try latest release (linux) |
| 119 | + if: ${{ matrix.runs-on == 'ubuntu-latest' }} |
| 120 | + run: | |
| 121 | + wget https://github.com/${{ github.repository }}/releases/${{ github.ref_name }}/csm-${{ github.ref_name }}-x86_64-unknown-linux-musl.tar.gz |
| 122 | + tar -xvf csm-*.tar.gz |
| 123 | + ./release/csm --version |
| 124 | +
|
| 125 | + - name: Try latest release (windows) |
| 126 | + if: ${{ matrix.runs-on == 'windows-latest' }} |
| 127 | + run: | |
| 128 | + Invoke-WebRequest -Uri https://github.com/${{ github.repository }}/releases/${{ github.ref_name }}/csm-${{ github.ref_name }}-x86_64-pc-windows-msvc.zip -OutFile csm-${{ github.ref_name }}-x86_64-pc-windows-msvc.zip |
| 129 | + Expand-Archive -Path csm-${{ github.ref_name }}-x86_64-pc-windows-msvc.zip -DestinationPath release |
| 130 | + .\release\csm.exe --version |
0 commit comments