Skip to content

ci

ci #1069

Workflow file for this run

# input for CI
# https://github.com/ClementTsang/bottom/blob/master/.github/workflows/ci.yml
# https://github.com/heim-rs/heim/blob/master/.github/workflows/ci.yml
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/ci.yml
# TODO: cargo-deny, cargo-audit, cargo-udeps, cargo-outdated
name: ci
on:
pull_request:
push:
branches:
- main
schedule:
- cron: '00 01 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
- run: cargo fmt --all -- --check
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master
# with:
# files: ./file.txt
clippy:
# should be fine to run clippy only on one platform since there aren't many
# operating system dependent configurations (except case sensitivity setting)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: clippy
- run: cargo clippy --all-targets --workspace -- -D warnings
compile:
name: Compile ${{ matrix.tuple.build }}
needs: [rustfmt, clippy, typos]
runs-on: ${{ matrix.tuple.os }}
env:
# For some checks&builds we use cross instead of cargo.
CARGO: cargo
strategy:
fail-fast: false
matrix:
tuple:
# available VMs are documented here:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
# though it is not very visible what the actual architecture is, and therefore it is not
# clear whether or not cross can/needs to be used.
# ---
# see https://doc.rust-lang.org/nightly/rustc/platform-support.html for platform support / tiers
# see https://github.com/cross-rs/cross#supported-targets for supported targets in cross
# ---
# alternatively matrix could be shared and specified via .json
# see https://github.community/t/how-to-share-matrix-between-jobs/128595/8
# ---
- { build: 'linux-x86_64-pinned', os: 'ubuntu-22.04', target: 'x86_64-unknown-linux-gnu', cross: false, rust: 1.82, archive: true }
- { build: 'windows-x86_64-pinned', os: 'windows-2019', target: 'x86_64-pc-windows-msvc', cross: false, rust: 1.82, archive: true }
- { build: 'macos-x86_64-pinned', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: 1.82, archive: true }
- { build: 'linux-x86_64', os: 'ubuntu-latest', target: 'x86_64-unknown-linux-gnu', cross: false, rust: stable, archive: false }
- { build: 'linux-i686', os: 'ubuntu-latest', target: 'i686-unknown-linux-gnu', cross: true, rust: stable, archive: false }
- { build: 'linux-arm', os: 'ubuntu-latest', target: 'aarch64-unknown-linux-gnu', cross: true, rust: stable, archive: false } # aarch64
# - { build: 'ubuntu-armv7', os: 'ubuntu-latest', target: 'armv7-unknown-linux-gnueabihf', cross: true, rust: stable, archive: false } # armv7
# - { build: 'ubuntu-armv6', os: 'ubuntu-latest', target: 'arm-unknown-linux-gnueabihf', cross: true, rust: stable, archive: false } # armv6
- { build: 'macos-x86_64', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: stable, archive: false }
# - { build: 'macos-arm', os: 'macos-latest', target: 'aarch64-apple-darwin', cross: true, rust: stable, archive: false } # arm (tier 2, not in cross)
- { build: 'windows-x86_64-msvc', os: 'windows-latest', target: 'x86_64-pc-windows-msvc', cross: false, rust: stable, archive: false }
- { build: 'windows-i686-msvc', os: 'windows-latest', target: 'i686-pc-windows-msvc', cross: false, rust: stable, archive: false }
- { build: 'windows-x86_64-mingw', os: 'windows-latest', target: 'x86_64-pc-windows-gnu', cross: false, rust: stable, archive: false }
# - { build: 'windows-i686-mingw', os: 'windows-latest', target: 'i686-pc-windows-gnu', cross: false, rust: stable, archive: false }
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Rustup update can fail on windows since it tries to replace its binary. This is not really
# needed anyhow. https://github.com/rust-lang/rustup/issues/3029
- name: Disable rustup self-update
shell: bash
run: rustup set auto-self-update disable
- name: Install toolchain
uses: dtolnay/rust-toolchain@v1
with:
# this specifies the rustup toolchain
toolchain: ${{ matrix.tuple.rust }}
target: ${{ matrix.tuple.target }}
- name: Install cross
if: matrix.tuple.cross != false
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Check
run: |
echo "cargo command is: ${{ env.CARGO }}"
# this runs check for the target to use for (cross) compilation (must exist in rustup)
${{ env.CARGO }} check --verbose --target=${{ matrix.tuple.target }}
- name: Build artifact
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
env:
CI_PKG_VERSION_PRE_RELEASE: --alpha
CI_PKG_VERSION_BUILD: ${{ github.run_number }}
run: |
${{ env.CARGO }} build --release --target=${{ matrix.tuple.target }}
- name: Archive
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
shell: bash
run: |
staging="run-clang-format-build-${{github.run_number}}-${{ matrix.tuple.target }}"
mkdir -p "$staging"
cp {readme.md,LICENSE} "$staging/"
if [ "${{ matrix.tuple.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.tuple.target }}/release/run-clang-format.exe" "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> $GITHUB_ENV
else
cp "target/${{ matrix.tuple.target }}/release/run-clang-format" "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
- name: Archive artifacts
uses: actions/upload-artifact@v4
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
with:
name: dist-${{github.run_number}}-${{ matrix.tuple.target }}
path: ${{ env.ASSET }}
retention-days: 7
tests:
name: Test ${{ matrix.os }}
needs: [compile]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
# testing on the real VMs only, not via cross
- ubuntu-22.04
- macos-latest
- windows-latest
toolchain:
- stable
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install packages (ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: |
.github/setup/load_artifacts_ubuntu.sh
- name: Install packages (macos)
if: matrix.os == 'macos-latest'
run: |
.github/setup/load_artifacts_macos.sh
- name: Install packages (windows)
if: matrix.os == 'windows-latest'
run: |
.github/setup/load_artifacts_windows.bat
# Rustup update can fail on windows since it tries to replace its binary. This is not really
# needed anyhow. https://github.com/rust-lang/rustup/issues/3029
- name: Disable rustup self-update
# if: matrix.os == 'windows-latest'
shell: bash
run: rustup set auto-self-update disable
- name: Install toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
- name: Test
# using only one test thread to avoid race conditions on temporary files
run: cargo test --verbose --no-fail-fast -- --test-threads 1