Run secrets scan #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
# By default, a workflow only runs when a pull_request event's activity type is opened, synchronize, or reopened. | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request | |
# So we add default event types and ready_for_review type here. | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- ready_for_review | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
env: | |
RUST_BACKTRACE: full | |
CARGO_TERM_COLOR: always | |
jobs: | |
ci: | |
if: github.event.pull_request.draft == false | |
name: Run CI tasks | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 # Latest as of 2023-11-16 | |
with: | |
toolchain: stable | |
components: rustfmt,clippy | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Check "cargo fmt" | |
run: cargo fmt -- --check | |
- name: Run "cargo check" | |
run: cargo check --locked --all-features --all-targets | |
- name: Run "cargo clippy" | |
run: cargo clippy --locked --all-features -- -D warnings | |
- name: Run "cargo test" | |
run: cargo test --locked --verbose --all-targets --all-features | |
crate-metadata: | |
if: startsWith(github.ref, 'refs/tags/v') | |
name: Extract crate metadata | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Extract crate information | |
id: crate-metadata | |
shell: bash | |
run: | | |
human_version="$(cargo metadata --no-deps --format-version 1 | jq -r '"v" + .packages[0].version')" | |
if [ "${{ github.ref_name }}" != "${human_version}" ]; then | |
echo "Tag does not match version in Cargo.toml: ${{ github.ref_name }} != ${human_version}" | |
exit 0 | |
fi | |
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT | |
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT | |
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT | |
outputs: | |
name: ${{ steps.crate-metadata.outputs.name }} | |
version: ${{ steps.crate-metadata.outputs.version }} | |
msrv: ${{ steps.crate-metadata.outputs.msrv }} | |
build-release: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: | |
- ci | |
- crate-metadata | |
permissions: | |
contents: write | |
name: Build release | |
env: | |
BUILD_CMD: cargo | |
runs-on: ${{ matrix.job.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
# To sort the matrix, use inline syntax. | |
- { target: aarch64-apple-darwin, os: macos-latest } | |
- { target: aarch64-unknown-linux-gnu, os: ubuntu-latest, cross: true } | |
- { target: x86_64-apple-darwin, os: macos-latest } | |
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest } | |
- { target: x86_64-unknown-linux-musl, os: ubuntu-latest } | |
steps: | |
- uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 # Latest as of 2023-11-16 | |
with: | |
toolchain: stable | |
targets: ${{ matrix.job.target }} | |
- uses: taiki-e/install-action@e2daa7c7c8bc02b4afae53143c6a07d8b916a3f7 # v2.21.12 | |
if: matrix.job.cross == true | |
with: | |
tool: cross | |
- name: Overwrite build command | |
if: matrix.job.cross == true | |
shell: bash | |
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Build release binary | |
run: $BUILD_CMD build --release --locked --verbose --all-features --target=${{ matrix.job.target }} | |
env: | |
PKG_CONFIG_ALLOW_CROSS: 1 | |
- name: Archive release binary | |
run: | | |
tar --create --gzip --verbose --file=${{ needs.crate-metadata.outputs.name }}-${{ matrix.job.target }}.tar.gz --directory=target/${{ matrix.job.target }}/release ${{ needs.crate-metadata.outputs.name }} | |
- name: Install coreutils for macOS runner | |
if: matrix.job.os == 'macos-latest' | |
run: brew install coreutils | |
- name: Calculate checksum | |
run: | | |
sha256sum ${{ needs.crate-metadata.outputs.name }}-${{ matrix.job.target }}.tar.gz > ${{ needs.crate-metadata.outputs.name }}-${{ matrix.job.target }}.tar.gz.sha256 | |
- name: Upload release binary | |
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15 | |
with: | |
files: | | |
${{ needs.crate-metadata.outputs.name }}-${{ matrix.job.target }}.tar.gz | |
${{ needs.crate-metadata.outputs.name }}-${{ matrix.job.target }}.tar.gz.sha256 |