Skip to content

Commit

Permalink
Update CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 13, 2022
1 parent 865336f commit 33c15ce
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
32 changes: 13 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ jobs:
MIRIFLAGS: -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check
RUSTFLAGS: ${{ env.RUSTFLAGS }} -Z randomize-layout

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@nightly
- run: cargo doc --workspace --all-features --document-private-items

tidy:
runs-on: ubuntu-latest
steps:
Expand All @@ -92,6 +101,7 @@ jobs:
- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@cargo-minimal-versions
- uses: taiki-e/install-action@shellcheck
- run: pip3 install yq
- run: cargo fmt --all --check
if: always()
- run: cargo clippy --workspace --all-features --all-targets
Expand All @@ -100,31 +110,15 @@ jobs:
if: always()
- run: shellcheck $(git ls-files '*.sh')
if: always()
- run: tools/check-workflow.sh
if: always()

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@nightly
- run: cargo doc --workspace --all-features

# This job doesn't actually test anything, but they're used to tell bors the
# build completed, as there is no practical way to detect when a workflow is
# successful listening to webhooks only.
#
# ALL THE PREVIOUS JOBS NEEDS TO BE ADDED TO THE `needs` SECTION OF THIS JOB!

ci-success:
name: ci
if: github.event_name == 'push' && success()
needs:
- test
- msrv
- miri
- tidy
- docs
needs: [test, msrv, miri, docs, tidy] # tidy:needs
runs-on: ubuntu-latest
steps:
- name: Mark the job as a success
Expand Down
41 changes: 41 additions & 0 deletions tools/check-workflow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# shellcheck disable=SC2046
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

# USAGE:
# ./tools/check-workflow.sh
#
# Note: This script requires the following tools:
# - jq
# - yq

bail() {
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
echo "::error::$*"
else
echo "error: $*" >&2
fi
exit 1
}

if [[ $# -gt 0 ]]; then
cat <<EOF
USAGE:
$0
EOF
exit 1
fi

# shellcheck disable=SC2207
jobs_actual=($(yq '.jobs' .github/workflows/ci.yml | jq -r 'keys_unsorted[]'))
unset 'jobs_actual[${#jobs_actual[@]}-1]'
# shellcheck disable=SC2207
jobs_expected=($(yq -r '.jobs."ci-success".needs[]' .github/workflows/ci.yml))
if [[ "${jobs_actual[*]}" != "${jobs_expected[*]+"${jobs_expected[*]}"}" ]]; then
printf -v jobs '%s, ' "${jobs_actual[@]}"
sed -i "s/needs: \[.*\] # tidy:needs/needs: [${jobs%, }] # tidy:needs/" .github/workflows/ci.yml
git --no-pager diff .github/workflows/ci.yml
bail "please update 'needs' section in 'ci-success' job to '[${jobs%, }]'"
fi

0 comments on commit 33c15ce

Please sign in to comment.