Skip to content

Commit f5a4a72

Browse files
committed
ci,tools: Update config and script
1 parent f5e107a commit f5a4a72

5 files changed

Lines changed: 75 additions & 44 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ indent_style = space
1111
insert_final_newline = true
1212
trim_trailing_whitespace = true
1313

14-
[*.{css,html,json,md,rb,sh,yml,yaml}]
14+
[*.{css,html,json,md,rb,ps1,sh,yml,yaml}]
1515
indent_size = 2
1616

1717
[*.{js,yml,yaml}]

.github/dependabot.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,3 @@ updates:
1818
commit-message:
1919
prefix: ''
2020
labels: []
21-
groups:
22-
github-actions:
23-
patterns:
24-
- '*'

.github/workflows/ci.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ concurrency:
3232
cancel-in-progress: true
3333

3434
jobs:
35-
miri:
36-
uses: taiki-e/github-actions/.github/workflows/miri.yml@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main
37-
msrv:
38-
uses: taiki-e/github-actions/.github/workflows/msrv.yml@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main
39-
release-dry-run:
40-
uses: taiki-e/github-actions/.github/workflows/release-dry-run.yml@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main
4135
tidy:
42-
uses: taiki-e/github-actions/.github/workflows/tidy.yml@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main
36+
uses: taiki-e/github-actions/.github/workflows/tidy.yml@3637cc7cf76d2ce698edc313bcd39bad8a92caa8 # main
4337
permissions:
44-
contents: write # for creating branch for pr
45-
pull-requests: write # unused (used in `codegen-automerge: true` case)
4638
security-events: write # for github/codeql-action/*
47-
secrets:
48-
PR_TOKEN_APP_PRIVATE_KEY: ${{ secrets.PR_TOKEN_APP_PRIVATE_KEY }}
39+
miri:
40+
needs: tidy
41+
uses: taiki-e/github-actions/.github/workflows/rust-miri.yml@3637cc7cf76d2ce698edc313bcd39bad8a92caa8 # main
42+
msrv:
43+
needs: tidy
44+
uses: taiki-e/github-actions/.github/workflows/rust-msrv.yml@3637cc7cf76d2ce698edc313bcd39bad8a92caa8 # main
45+
release-dry-run:
46+
needs: tidy
47+
uses: taiki-e/github-actions/.github/workflows/rust-release-dry-run.yml@3637cc7cf76d2ce698edc313bcd39bad8a92caa8 # main
4948

5049
test:
50+
needs: tidy
5151
strategy:
5252
fail-fast: false
5353
matrix:
@@ -63,9 +63,10 @@ jobs:
6363
timeout-minutes: 60
6464
steps:
6565
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
66-
- uses: taiki-e/github-actions/install-rust@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main # zizmor: ignore[stale-action-refs]
66+
- uses: taiki-e/install-action@ec28e287910af896fd98e04056d31fa68607e7ad # v2.77.4
6767
with:
68-
toolchain: ${{ matrix.rust }}
68+
tool: rust@${{ matrix.rust }}
69+
fallback: none
6970
- run: cargo test --workspace --all-features
7071
- run: |
7172
cargo install --path . --debug
@@ -76,7 +77,7 @@ jobs:
7677
rustup toolchain remove 1.63 1.64 1.65
7778
cargo hack check --rust-version --workspace --locked
7879
cargo uninstall cargo-hack
79-
- uses: taiki-e/install-action@58e862542551f667fa44c8a2a4a1d64ad477c96a # v2.75.17
80+
- uses: taiki-e/install-action@ec28e287910af896fd98e04056d31fa68607e7ad # v2.77.4
8081
with:
8182
tool: cargo-hack,cargo-minimal-versions
8283
fallback: none
@@ -86,6 +87,7 @@ jobs:
8687

8788
test-compat:
8889
name: test (1.${{ matrix.rust }})
90+
needs: tidy
8991
strategy:
9092
fail-fast: false
9193
matrix:
@@ -102,9 +104,10 @@ jobs:
102104
timeout-minutes: 60
103105
steps:
104106
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
105-
- uses: taiki-e/github-actions/install-rust@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main # zizmor: ignore[stale-action-refs]
107+
- uses: taiki-e/install-action@ec28e287910af896fd98e04056d31fa68607e7ad # v2.77.4
106108
with:
107-
toolchain: nightly
109+
tool: rust@nightly
110+
fallback: none
108111
- run: cargo test --workspace --all-features
109112
env:
110113
CARGO_HACK_TEST_TOOLCHAIN: ${{ matrix.rust }}
@@ -116,6 +119,7 @@ jobs:
116119

117120
test-no-rustup:
118121
name: test (no rustup)
122+
needs: tidy
119123
runs-on: ubuntu-24.04
120124
timeout-minutes: 60
121125
container: alpine

.github/workflows/release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ on:
1414
- minor
1515
- major
1616

17-
defaults:
18-
run:
19-
shell: bash --noprofile --norc -CeEuxo pipefail {0}
20-
2117
concurrency:
2218
group: ${{ github.workflow }}
2319
cancel-in-progress: false
2420

2521
jobs:
2622
release:
2723
if: github.repository_owner == 'taiki-e'
28-
uses: taiki-e/github-actions/.github/workflows/rust-release.yml@5f549ff6b21e9a853f5f613784d5db27746fd2bc # main
24+
uses: taiki-e/github-actions/.github/workflows/rust-release.yml@3637cc7cf76d2ce698edc313bcd39bad8a92caa8 # main
2925
permissions:
3026
contents: write # for taiki-e/create-gh-release-action / taiki-e/upload-rust-binary-action
3127
id-token: write # for rust-lang/crates-io-auth-action / actions/attest

tools/tidy.sh

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ cd -- "$(dirname -- "$0")"/..
99
# GITHUB_TOKEN=$(gh auth token) ./tools/tidy.sh
1010
#
1111
# Note: This script requires the following tools:
12-
# - docker
12+
# - docker or podman (or compatible CLI specified by TIDY_DOCKER_PATH. when both available and TIDY_DOCKER_PATH is not set, docker is preferred)
1313
#
1414
# This script is shared by projects under github.com/taiki-e, so there may also
1515
# be checks for files not included in this repository, but they will be skipped
1616
# if the corresponding files do not exist.
1717
# It is not intended for manual editing.
1818

19+
bail() {
20+
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
21+
printf '::error::%s\n' "$*"
22+
else
23+
printf >&2 'error: %s\n' "$*"
24+
fi
25+
exit 1
26+
}
27+
1928
if [[ $# -gt 0 ]]; then
2029
cat <<EOF
2130
USAGE:
@@ -24,13 +33,14 @@ EOF
2433
exit 1
2534
fi
2635

36+
image='ghcr.io/taiki-e/tidy'
2737
if [[ -n "${TIDY_DEV:-}" ]]; then
28-
image="ghcr.io/taiki-e/tidy:latest"
38+
image+=':latest'
2939
else
30-
image="ghcr.io/taiki-e/tidy@sha256:c78ba09aa420feddc57ca76fca38b1d4c998a0ede37f76378f12df15a826cf59"
40+
image+='@sha256:151cd5c4f7c88bd21322c7dab255d60e699ffe4d4903e4e712429952537df6cf'
3141
fi
3242
user="$(id -u):$(id -g)"
33-
workdir=$(pwd)
43+
workdir="${PWD}"
3444
tmp=$(mktemp -d)
3545
trap -- 'rm -rf -- "${tmp:?}"' EXIT
3646
mkdir -p -- "${tmp}"/{pwsh-cache,pwsh-local,zizmor-cache,dummy-dir,tmp}
@@ -40,8 +50,12 @@ color=''
4050
if [[ -t 1 ]] || [[ -n "${GITHUB_ACTIONS:-}" ]]; then
4151
color=1
4252
fi
53+
# Refs:
54+
# - https://docs.docker.com/reference/cli/docker/container/run/
55+
# - https://docs.podman.io/en/latest/markdown/podman-run.1.html
56+
# - https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html
4357
common_args=(
44-
run --rm --init -i --user "${user}"
58+
run --rm --init
4559
--cap-drop=all
4660
--security-opt=no-new-privileges
4761
--read-only
@@ -59,6 +73,30 @@ common_args=(
5973
--env TIDY_EXPECTED_SHELL_FILE_COUNT
6074
--env TIDY_EXPECTED_DOCKER_FILE_COUNT
6175
)
76+
if [[ -n "${TIDY_DOCKER_PATH:-}" ]]; then
77+
docker="${TIDY_DOCKER_PATH}"
78+
elif type -P docker >/dev/null; then
79+
docker='docker'
80+
elif type -P podman >/dev/null; then
81+
docker='podman'
82+
else
83+
bail 'this script requires docker or podman'
84+
fi
85+
rootless=''
86+
if [[ "$("${docker}" --version)" == *'podman'* ]]; then
87+
if [[ "$("${docker}" info)" == *'rootless: true'* ]]; then
88+
rootless=1
89+
fi
90+
elif [[ "$("${docker}" info -f '{{println .SecurityOptions}}')" == *'rootless'* ]]; then
91+
rootless=1
92+
fi
93+
if [[ -n "${rootless}" ]]; then
94+
printf 'docker path: %s\n' "${docker} (rootless)"
95+
else
96+
printf 'docker path: %s\n' "${docker}"
97+
common_args+=(--user "${user}")
98+
fi
99+
62100
# Map ignored files (e.g., .env) to dummy files.
63101
while IFS= read -r path; do
64102
if [[ -d "${path}" ]]; then
@@ -73,36 +111,33 @@ while IFS= read -r path; do
73111
done < <(git status --porcelain --ignored | grep -E '^!!' | cut -d' ' -f2)
74112

75113
docker_run() {
76-
docker "${common_args[@]}" "$@"
114+
local script="$1"
115+
shift
116+
"${docker}" "${common_args[@]}" "$@" "${image}" /checks/"${script}"
77117
code2="$?"
78118
if [[ ${code} -eq 0 ]] && [[ ${code2} -ne 0 ]]; then
79119
code="${code2}"
80120
fi
81121
}
82122

83123
set +e
84-
docker_run \
124+
docker_run offline.sh \
85125
--mount "type=bind,source=${workdir},target=${workdir}" --workdir "${workdir}" \
126+
--mount "type=bind,source=${workdir}/.git,target=${workdir}/.git,readonly" \
86127
--mount "type=bind,source=${tmp}/tmp,target=/tmp/tidy" \
87128
--mount "type=bind,source=${tmp}/pwsh-cache,target=/.cache/powershell" \
88129
--mount "type=bind,source=${tmp}/pwsh-local,target=/.local/share/powershell" \
89-
--network=none \
90-
"${image}" \
91-
/checks/offline.sh
130+
--network=none
92131
# Some good audits requires access to GitHub API.
93-
docker_run \
132+
docker_run zizmor.sh \
94133
--mount "type=bind,source=${workdir},target=${workdir},readonly" --workdir "${workdir}" \
95134
--mount "type=bind,source=${tmp}/zizmor-cache,target=/.cache/zizmor" \
96-
--env GH_TOKEN --env GITHUB_TOKEN --env ZIZMOR_GITHUB_TOKEN \
97-
"${image}" \
98-
/checks/zizmor.sh
135+
--env GH_TOKEN --env GITHUB_TOKEN --env ZIZMOR_GITHUB_TOKEN
99136
# We use remote dictionary.
100-
docker_run \
137+
docker_run cspell.sh \
101138
--mount "type=bind,source=${workdir},target=${workdir},readonly" --workdir "${workdir}" \
102139
--mount "type=bind,source=${workdir}/.github/.cspell/project-dictionary.txt,target=${workdir}/.github/.cspell/project-dictionary.txt" \
103140
--mount "type=bind,source=${workdir}/.github/.cspell/rust-dependencies.txt,target=${workdir}/.github/.cspell/rust-dependencies.txt" \
104-
--mount "type=bind,source=${tmp}/tmp,target=/tmp/tidy" \
105-
"${image}" \
106-
/checks/cspell.sh
141+
--mount "type=bind,source=${tmp}/tmp,target=/tmp/tidy"
107142

108143
exit "${code}"

0 commit comments

Comments
 (0)