|
| 1 | +name: Test and release |
| 2 | + |
| 3 | +# ref. https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - "*" |
| 10 | + pull_request: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + static_analysis: |
| 17 | + name: Static analysis |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v3 |
| 22 | + - name: Install Rust |
| 23 | + uses: actions-rs/toolchain@v1 |
| 24 | + with: |
| 25 | + toolchain: nightly |
| 26 | + profile: minimal |
| 27 | + components: rustfmt, clippy |
| 28 | + override: true |
| 29 | + - name: Check Rust version |
| 30 | + run: rustc --version |
| 31 | + - uses: Swatinem/rust-cache@v1 |
| 32 | + with: |
| 33 | + cache-on-failure: true |
| 34 | + - name: Run static analysis tests |
| 35 | + shell: bash |
| 36 | + run: scripts/static-analysis.sh |
| 37 | + |
| 38 | + check_cargo_unused: |
| 39 | + name: Check Cargo unused |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v3 |
| 44 | + - name: Install Rust |
| 45 | + uses: actions-rs/toolchain@v1 |
| 46 | + with: |
| 47 | + toolchain: nightly |
| 48 | + profile: minimal |
| 49 | + components: rustfmt, clippy |
| 50 | + override: true |
| 51 | + - name: Check Rust version |
| 52 | + run: rustc --version |
| 53 | + - uses: Swatinem/rust-cache@v1 |
| 54 | + with: |
| 55 | + cache-on-failure: true |
| 56 | + - name: Check unused Cargo dependencies |
| 57 | + shell: bash |
| 58 | + run: scripts/cargo.unused.sh |
| 59 | + |
| 60 | + unit_tests: |
| 61 | + name: Unit tests |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v3 |
| 66 | + - name: Install Rust |
| 67 | + uses: actions-rs/toolchain@v1 |
| 68 | + with: |
| 69 | + toolchain: stable |
| 70 | + profile: minimal |
| 71 | + override: true |
| 72 | + - name: Check Rust version |
| 73 | + run: rustc --version |
| 74 | + - uses: Swatinem/rust-cache@v1 |
| 75 | + with: |
| 76 | + cache-on-failure: true |
| 77 | + - name: Run unit tests |
| 78 | + run: scripts/tests.unit.sh |
| 79 | + |
| 80 | + release: |
| 81 | + name: Release ${{ matrix.job.target }} (${{ matrix.job.os }}) |
| 82 | + runs-on: ${{ matrix.job.os }} |
| 83 | + needs: [static_analysis, check_cargo_unused, unit_tests] |
| 84 | + strategy: |
| 85 | + matrix: |
| 86 | + job: |
| 87 | + # https://doc.rust-lang.org/nightly/rustc/platform-support.html |
| 88 | + - os: ubuntu-latest |
| 89 | + platform: linux |
| 90 | + target: x86_64-unknown-linux-gnu |
| 91 | + - os: macos-latest |
| 92 | + platform: darwin |
| 93 | + target: x86_64-apple-darwin |
| 94 | + - os: ubuntu-latest |
| 95 | + platform: linux |
| 96 | + target: aarch64-unknown-linux-musl |
| 97 | + - os: macos-latest |
| 98 | + platform: darwin |
| 99 | + target: aarch64-apple-darwin |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Checkout |
| 103 | + uses: actions/checkout@v3 |
| 104 | + |
| 105 | + - name: Install Rust |
| 106 | + uses: actions-rs/toolchain@v1 |
| 107 | + with: |
| 108 | + profile: minimal |
| 109 | + toolchain: stable |
| 110 | + target: ${{ matrix.job.target }} |
| 111 | + override: true |
| 112 | + - name: Check Rust version |
| 113 | + run: rustc --version |
| 114 | + |
| 115 | + - uses: Swatinem/rust-cache@v1 |
| 116 | + with: |
| 117 | + cache-on-failure: true |
| 118 | + |
| 119 | + # ref. https://github.com/gakonst/foundry/blob/master/.github/workflows/cross-platform.yml |
| 120 | + - name: Apple M1 setup |
| 121 | + if: matrix.job.target == 'aarch64-apple-darwin' |
| 122 | + run: | |
| 123 | + echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV |
| 124 | + echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV |
| 125 | +
|
| 126 | + # ref. https://github.com/gakonst/foundry/blob/master/.github/workflows/cross-platform.yml |
| 127 | + # ref. https://github.com/briansmith/ring/blob/main/mk/install-build-tools.sh |
| 128 | + # ref. https://github.com/briansmith/ring/issues/1414 |
| 129 | + # ref. https://github.com/zellij-org/zellij/blob/main/.github/workflows/release.yml |
| 130 | + # ref. https://github.com/sfackler/rust-openssl/issues/621 |
| 131 | + - name: Linux ARM64 setup with musl-tools |
| 132 | + if: matrix.job.target == 'aarch64-unknown-linux-musl' |
| 133 | + run: | |
| 134 | + sudo apt-get install -y --no-install-recommends pkg-config libssl-dev musl-tools clang llvm |
| 135 | + echo "CC_aarch64_unknown_linux_musl=clang" >> $GITHUB_ENV |
| 136 | + echo "AR_aarch64_unknown_linux_musl=llvm-ar" >> $GITHUB_ENV |
| 137 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS=\"-Clink-self-contained=yes -Clinker=rust-lld\"" >> $GITHUB_ENV |
| 138 | + echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV |
| 139 | +
|
| 140 | + - name: Compile binaries |
| 141 | + env: |
| 142 | + RUSTFLAGS: -C link-args=-s |
| 143 | + uses: actions-rs/cargo@v1 |
| 144 | + with: |
| 145 | + command: build |
| 146 | + args: --release --bin mini-kvvm-rs --target ${{ matrix.job.target }} |
| 147 | + |
| 148 | + - name: Compress binaries |
| 149 | + id: release_artifacts |
| 150 | + env: |
| 151 | + PLATFORM_NAME: ${{ matrix.job.platform }} |
| 152 | + TARGET: ${{ matrix.job.target }} |
| 153 | + shell: bash |
| 154 | + run: | |
| 155 | + if [ "$PLATFORM_NAME" == "linux" ]; then |
| 156 | +
|
| 157 | + ./target/${TARGET}/release/mini-kvvm-rs |
| 158 | + cp ./target/${TARGET}/release/mini-kvvm-rs mini-kvvm-rs.${TARGET} |
| 159 | + echo "::set-output name=file_name_mini-kvvm-rs::mini-kvvm-rs.${TARGET}" |
| 160 | + tar -czvf mini-kvvm-rs_${TARGET}.tar.gz -C ./target/${TARGET}/release mini-kvvm-rs |
| 161 | + echo "::set-output name=file_name_mini-kvvm-rs_tar_gz::mini-kvvm-rs_${TARGET}.tar.gz" |
| 162 | +
|
| 163 | + elif [ "$PLATFORM_NAME" == "darwin" ]; then |
| 164 | +
|
| 165 | + cp ./target/${TARGET}/release/mini-kvvm-rs mini-kvvm-rs.${TARGET} |
| 166 | + echo "::set-output name=file_name_mini-kvvm-rs::mini-kvvm-rs.${TARGET}" |
| 167 | + gtar -czvf mini-kvvm-rs_${TARGET}.tar.gz -C ./target/${TARGET}/release mini-kvvm-rs |
| 168 | + echo "::set-output name=file_name_mini-kvvm-rs_tar_gz::mini-kvvm-rs_${TARGET}.tar.gz" |
| 169 | +
|
| 170 | + else |
| 171 | +
|
| 172 | + echo "skipping $PLATFORM_NAME" |
| 173 | +
|
| 174 | + fi |
| 175 | +
|
| 176 | + # release tip from latest commits |
| 177 | + # https://github.com/softprops/action-gh-release |
| 178 | + # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context |
| 179 | + - name: Release latest |
| 180 | + uses: softprops/action-gh-release@v1 |
| 181 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 182 | + with: |
| 183 | + name: Latest release |
| 184 | + tag_name: latest |
| 185 | + prerelease: true |
| 186 | + body: Latest builds from the last commit. |
| 187 | + files: | |
| 188 | + ${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs }} |
| 189 | + ${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs_tar_gz }} |
| 190 | +
|
| 191 | + # release only for tags |
| 192 | + # https://github.com/softprops/action-gh-release |
| 193 | + # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context |
| 194 | + - name: Release tag |
| 195 | + uses: softprops/action-gh-release@v1 |
| 196 | + if: startsWith(github.ref, 'refs/tags/') |
| 197 | + with: |
| 198 | + name: ${{ github.ref_name }} |
| 199 | + tag_name: ${{ github.ref_name }} |
| 200 | + draft: true |
| 201 | + prerelease: true |
| 202 | + body: Release builds for ${{ github.ref_name }}. |
| 203 | + files: | |
| 204 | + ${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs }} |
| 205 | + ${{ steps.release_artifacts.outputs.file_name_mini-kvvm-rs_tar_gz }} |
0 commit comments