|
| 1 | +name: Binary executable builds |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + tags: |
| 10 | + - v[0-9]+.* |
| 11 | + pull_request: |
| 12 | + branches: [main] |
| 13 | + |
| 14 | +env: |
| 15 | + CARGO_INCREMENTAL: 0 |
| 16 | + CARGO_NET_GIT_FETCH_WITH_CLI: true |
| 17 | + CARGO_NET_RETRY: 10 |
| 18 | + CARGO_TERM_COLOR: always |
| 19 | + RUST_BACKTRACE: 1 |
| 20 | + RUSTFLAGS: -D warnings |
| 21 | + RUSTUP_MAX_RETRIES: 10 |
| 22 | + |
| 23 | +defaults: |
| 24 | + run: |
| 25 | + shell: bash |
| 26 | + |
| 27 | +jobs: |
| 28 | + |
| 29 | + create-assets: |
| 30 | + name: ${{ matrix.target }} |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - target: aarch64-unknown-linux-gnu |
| 36 | + os: ubuntu-latest |
| 37 | + ## I GIVE UP! For this target, OpenSSL needs to be cross compiled |
| 38 | + ## which is driven by openssl-sys crate's custom build script... |
| 39 | + ## Linux users with aarch64 (aka ARM64) using musl C lib can go fish (or build from source). |
| 40 | + # - target: aarch64-unknown-linux-musl |
| 41 | + # os: ubuntu-latest |
| 42 | + - target: x86_64-unknown-linux-gnu |
| 43 | + os: ubuntu-latest |
| 44 | + - target: x86_64-unknown-linux-musl |
| 45 | + os: ubuntu-latest |
| 46 | + - target: aarch64-apple-darwin |
| 47 | + os: macos-latest |
| 48 | + - target: x86_64-apple-darwin |
| 49 | + os: macos-latest |
| 50 | + - target: x86_64-pc-windows-msvc |
| 51 | + os: windows-latest |
| 52 | + runs-on: ${{ matrix.os }} |
| 53 | + permissions: |
| 54 | + contents: write |
| 55 | + steps: |
| 56 | + - name: Calculate Release Version |
| 57 | + id: calc-version |
| 58 | + run: | |
| 59 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 60 | + short_sha=$(echo "${{ github.sha }}" | awk '{print substr($0,0,5)}') |
| 61 | + echo "RELEASE_VERSION=nightly-$(date '+%Y-%m-%d')-$short_sha" >> $GITHUB_OUTPUT |
| 62 | + else |
| 63 | + echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Install native OpenSSL on Linux |
| 67 | + if: runner.os == 'Linux' && !(startsWith(matrix.target, 'aarch64') || endsWith(matrix.target, 'musl')) |
| 68 | + run: sudo apt-get install -y pkg-config libssl-dev |
| 69 | + - name: Install GCC for aarch64 (for cross-compiling openssl) |
| 70 | + if: runner.os == 'Linux' && startsWith(matrix.target, 'aarch64') |
| 71 | + run: | |
| 72 | + sudo apt-get update |
| 73 | + sudo apt-get install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu |
| 74 | + if [[ "${{matrix.target}}" == *musl ]]; then |
| 75 | + sudo apt-get install musl-dev musl-tools |
| 76 | + fi |
| 77 | + - name: Install musl-gcc (for compiling OpenSSL) |
| 78 | + if: matrix.target == 'x86_64-unknown-linux-musl' |
| 79 | + run: sudo apt-get install musl-tools |
| 80 | + |
| 81 | + - name: Calculate openssl-vendored |
| 82 | + shell: bash |
| 83 | + id: is-openssl-vendored |
| 84 | + run: | |
| 85 | + case "${{ matrix.target }}" in |
| 86 | + "aarch64-apple-darwin" | "x86_64-apple-darwin" | "aarch64-unknown-linux-gnu" | "aarch64-unknown-linux-musl" | "x86_64-unknown-linux-musl") |
| 87 | + echo "enabled=--features openssl-vendored" >> $GITHUB_OUTPUT |
| 88 | + ;; |
| 89 | + *) |
| 90 | + echo "enabled=" >> $GITHUB_OUTPUT |
| 91 | + ;; |
| 92 | + esac |
| 93 | +
|
| 94 | + - name: Checkout |
| 95 | + uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Setup Rust |
| 98 | + uses: dtolnay/rust-toolchain@stable |
| 99 | + with: |
| 100 | + target: ${{ matrix.target }} |
| 101 | + |
| 102 | + # problems with cross-compiling linux with musl |
| 103 | + - run: echo "RUSTFLAGS=-D warnings -C target-feature=+crt-static -C link-self-contained=yes" >> "${GITHUB_ENV}" |
| 104 | + if: contains(matrix.target, '-linux-musl') |
| 105 | + - run: | |
| 106 | + echo "CC=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" |
| 107 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" |
| 108 | + if: matrix.target == 'aarch64-unknown-linux-musl' |
| 109 | +
|
| 110 | + - name: Build |
| 111 | + env: |
| 112 | + # problems with cross-compiling aarch64 linux with gnu |
| 113 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: /usr/bin/aarch64-linux-gnu-gcc |
| 114 | + run: cargo build --manifest-path cpp-linter-cli/Cargo.toml --release --bin cpp-linter-cli --target ${{ matrix.target }} ${{ steps.is-openssl-vendored.outputs.enabled }} |
| 115 | + |
| 116 | + - name: Prepare artifacts [Windows] |
| 117 | + shell: bash |
| 118 | + if: matrix.os == 'windows-latest' |
| 119 | + id: prep-artifacts-windows |
| 120 | + run: | |
| 121 | + release_dir="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}" |
| 122 | + artifact_path="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}-${{ matrix.target }}.zip" |
| 123 | + echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_OUTPUT |
| 124 | + mkdir $release_dir |
| 125 | + cp target/${{ matrix.target }}/release/cpp-linter-cli.exe $release_dir/ |
| 126 | + cp LICENSE $release_dir/ |
| 127 | + 7z a -tzip $artifact_path $release_dir/ |
| 128 | + - name: Prepare artifacts [Unix] |
| 129 | + shell: bash |
| 130 | + id: prep-artifacts-unix |
| 131 | + if: matrix.os != 'windows-latest' |
| 132 | + run: | |
| 133 | + release_dir="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}" |
| 134 | + artifact_path="cpp-linter-cli-${{ steps.calc-version.outputs.RELEASE_VERSION }}-${{ matrix.target }}.tar.gz" |
| 135 | + echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_OUTPUT |
| 136 | + mkdir $release_dir |
| 137 | + cp target/${{ matrix.target }}/release/cpp-linter-cli $release_dir/ |
| 138 | + cp LICENSE $release_dir |
| 139 | + tar -czvf $artifact_path $release_dir/ |
| 140 | + - name: Upload artifacts |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: ${{ steps.prep-artifacts-unix.outputs.ARTIFACT_PATH || steps.prep-artifacts-windows.outputs.ARTIFACT_PATH }} |
| 144 | + path: ${{ steps.prep-artifacts-unix.outputs.ARTIFACT_PATH || steps.prep-artifacts-windows.outputs.ARTIFACT_PATH }} |
| 145 | + if-no-files-found: error |
| 146 | + |
| 147 | + create-release: |
| 148 | + if: startswith(github.ref, 'refs/tags') |
| 149 | + runs-on: ubuntu-latest |
| 150 | + needs: [create-assets] |
| 151 | + permissions: |
| 152 | + contents: write |
| 153 | + steps: |
| 154 | + - uses: actions/checkout@v4 |
| 155 | + with: |
| 156 | + persist-credentials: false |
| 157 | + - name: Install Rust |
| 158 | + run: rustup update stable --no-self-update |
| 159 | + - run: cargo package |
| 160 | + - name: Create a Github Release |
| 161 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 162 | + env: |
| 163 | + GH_TOKEN: ${{ github.token }} |
| 164 | + run: gh release create ${{ github.ref_name }} --generate-notes |
| 165 | + - run: cargo publish |
| 166 | + working-directory: cpp-linter-lib |
| 167 | + env: |
| 168 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 169 | + |
| 170 | + upload-assets: |
| 171 | + needs: [create-release] |
| 172 | + runs-on: ubuntu-latest |
| 173 | + strategy: |
| 174 | + matrix: |
| 175 | + target: |
| 176 | + - aarch64-unknown-linux-gnu |
| 177 | + # skip this target due to cross-compiling OpenSSL for musl C lib |
| 178 | + # - aarch64-unknown-linux-musl |
| 179 | + - x86_64-unknown-linux-gnu |
| 180 | + - x86_64-unknown-linux-musl |
| 181 | + - aarch64-apple-darwin |
| 182 | + - x86_64-apple-darwin |
| 183 | + - x86_64-pc-windows-msvc |
| 184 | + steps: |
| 185 | + - name: Download build asset |
| 186 | + uses: actions/download-artifact@v4 |
| 187 | + with: |
| 188 | + name: cpp-linter-cli-${{ matrix.target }} |
| 189 | + path: dist |
| 190 | + - name: Upload release assets |
| 191 | + env: |
| 192 | + GH_TOKEN: ${{ github.token }} |
| 193 | + run: gh release upload ${{ github.ref_name }} dist/cpp-linter-cli${{ contains(matrix.target, 'windows') || '.exe' }}%#%cpp-linter-cli_${{ matrix.target }} --clobber |
0 commit comments