Skip to content

Commit 44ff412

Browse files
committed
Further improve GitHub Actions workflow code style
This makes more stylistic adjustments to YAML workflows files. (Previous recent adjustments were, for the most part, only those needed to ensure clarity would be preserved while adding `permissions:`. This commit does some others that weren't needed for that.) The changes made here are: - Use `actions/checkout@v4`, not `actions/checkout@master`, in the one place where `@master` was still used for it. This is not strictly speaking a purely stylistic change, since it is eventually expected to make a difference, by holding onto major version 4 until the version is updated (which Depedabot automates). - Don't explicitly set the `CI` environment variable in the `test` job. This variable is guaranteed to be set automatically with the value of `true` by the GitHub Actions runner. Furthermore, no environment variables to indicate CI are explicitly set for other jobs, even though others rely on their presence as well due to the use of `is_ci` through `gix-testtools`. - Specify all environment variables' values as strings. Most values in YAML are strings without explicit quoting. This does not add quotation marks in those cases. But some values are parsed as some other type, such as integer, unless quoted. That makes it less obvious what the value will actually be in the environment, since it will be implicitly converted to a string, which does not always consist of the same sequence of characters as the original expression. This effect is most prominent for booleans (e.g. unquoted `yes` and `true` in YAML have the same meaning) but not entirely limited to them. In addition, such expressions may also lead to confusion if it is misread to mean that they will retain any kind of type information. So this quotes such values (except when other changes here remove them). - Minor quoting style adjustments, for YAML strings are quoted. Omit quotes when clearly not needed, and use single-quotes by default when quotes are needed. - Use 2-space indent inside scripts in script steps for consistency with other scripts. Most existing multi-line script steps, as well as all shell scripts, use 2-space indents already. - Remove `\` in a script step where it was not needed for line continuation because it followed a `|`. - In the `wasm` job's script steps, put `name:` and, when present, `if:`, ahead of `run:`, so it's clear what each step is for. (This was already done where applicable in other jobs.) - In the `wasm` job's script steps, split single-line `run:` values with `&&` into separate commands, one per line, where doing so has the same effect due to the `-e` option the CI runner automatically passes to `bash` shells unless `shell:` is overridden with a value that contains `{0}`. - In the `wasm` job's script steps, split single-line `run:` values with `;` into separate lines, including running loops over multiple lines, for readability. - In the `wasm` job, extract `${{ matrix.target }}` to an environment variable. This seems to make the steps slightly more readable, since `wasm` steps make heavy use of it. - Extremely minor adjustment to array style, for consistency. - In commands, use `--` where guaranteed to be supported if any non-option argument begins with parameter expansion or a glob. This was already almost, but not quite, already done. Since the possible values can be inferred from nearby code and do not begin with `-`, the reason is to clearly communicate that they are non-option arguments, rather than to fix any actual bug. (This continues to be avoided where is not guaranteed correct.) - Use the `-e` option before a pattern argument to `grep` formed through parameter expansion (same rationale as `--` above). - Use `-E` rather than `-r` with `sed`, since `-E` is standardized.
1 parent f41a58c commit 44ff412

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

Diff for: .github/workflows/ci.yml

+48-27
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions:
1818

1919
env:
2020
CARGO_TERM_COLOR: always
21-
CLICOLOR: 1
21+
CLICOLOR: '1'
2222

2323
jobs:
2424
pure-rust-build:
@@ -36,14 +36,14 @@ jobs:
3636
run: |
3737
set -x
3838
for pattern in cmake g++ libssl-dev make pkgconf pkg-config; do
39-
if dpkg-query --status -- "$pattern"; then
40-
exit 1
41-
fi
39+
if dpkg-query --status -- "$pattern"; then
40+
exit 1
41+
fi
4242
done
4343
for cmd in cmake g++ make pkgconf pkg-config; do
44-
if command -v -- "$cmd"; then
45-
exit 1
46-
fi
44+
if command -v -- "$cmd"; then
45+
exit 1
46+
fi
4747
done
4848
- name: Install Rust via Rustup
4949
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
@@ -65,8 +65,7 @@ jobs:
6565
tool: nextest
6666
- name: test
6767
env:
68-
CI: true
69-
GIX_TEST_IGNORE_ARCHIVES: 1
68+
GIX_TEST_IGNORE_ARCHIVES: '1'
7069
run: just ci-test
7170

7271
test-fast:
@@ -95,7 +94,7 @@ jobs:
9594
tool: nextest
9695
- name: "Test (nextest)"
9796
env:
98-
GIX_TEST_CREATE_ARCHIVES_EVEN_ON_CI: 1
97+
GIX_TEST_CREATE_ARCHIVES_EVEN_ON_CI: '1'
9998
run: cargo nextest run --workspace --no-fail-fast
10099
- name: Doctest
101100
run: cargo test --workspace --doc --no-fail-fast
@@ -127,8 +126,8 @@ jobs:
127126
[xml]$junit_xml = Get-Content -Path 'target/nextest/with-xml/junit.xml'
128127
129128
$actual_failures = $junit_xml.SelectNodes("//testcase[failure]") |
130-
ForEach-Object { "$($_.classname) $($_.name)" } |
131-
Sort-Object
129+
ForEach-Object { "$($_.classname) $($_.name)" } |
130+
Sort-Object
132131
133132
Write-Output $actual_failures
134133
Set-Content -Path 'actual-failures.txt' -Value $actual_failures
@@ -137,7 +136,7 @@ jobs:
137136
# Fail on any differences, even unexpectedly passing tests, so they can be investigated.
138137
# (If the job is made blocking for PRs, it may make sense to make this less stringent.)
139138
git --no-pager diff --no-index --exit-code --unified=1000000 --color=always -- `
140-
etc/test-fixtures-windows-expected-failures-see-issue-1358.txt actual-failures.txt
139+
etc/test-fixtures-windows-expected-failures-see-issue-1358.txt actual-failures.txt
141140
142141
test-32bit:
143142
runs-on: ubuntu-latest
@@ -183,8 +182,8 @@ jobs:
183182
run: cargo fmt --all -- --check
184183
- name: Run cargo diet
185184
run: |
186-
curl -LSfs https://raw.githubusercontent.com/the-lean-crate/cargo-diet/master/ci/install.sh | \
187-
sh -s -- --git the-lean-crate/cargo-diet --target x86_64-unknown-linux-musl --tag v1.2.4
185+
curl -LSfs https://raw.githubusercontent.com/the-lean-crate/cargo-diet/master/ci/install.sh |
186+
sh -s -- --git the-lean-crate/cargo-diet --target x86_64-unknown-linux-musl --tag v1.2.4
188187
189188
# Let's not fail CI for this, it will fail locally often enough, and a crate a little bigger
190189
# than allows is no problem either if it comes to that.
@@ -219,22 +218,44 @@ jobs:
219218
matrix:
220219
target: [ wasm32-unknown-unknown, wasm32-wasi ]
221220

221+
env:
222+
TARGET: ${{ matrix.target }}
223+
222224
steps:
223-
- uses: actions/checkout@master
225+
- uses: actions/checkout@v4
224226
- name: Install Rust
225-
run: rustup update stable && rustup default stable && rustup target add ${{ matrix.target }}
227+
run: |
228+
rustup update stable
229+
rustup default stable
230+
rustup target add "$TARGET"
226231
- uses: Swatinem/rust-cache@v2
227-
- run: set +x; for name in gix-sec; do (cd $name && cargo build --target ${{ matrix.target }}); done
228-
name: "WASI only: crates without feature toggle"
232+
- name: 'WASI only: crates without feature toggle'
229233
if: endsWith(matrix.target, '-wasi')
230-
- run: set +x; for name in gix-actor gix-attributes gix-bitmap gix-chunk gix-command gix-commitgraph gix-config-value gix-date gix-glob gix-hash gix-hashtable gix-mailmap gix-object gix-packetline gix-path gix-pathspec gix-prompt gix-quote gix-refspec gix-revision gix-traverse gix-url gix-validate; do (cd $name && cargo build --target ${{ matrix.target }}); done
231-
name: crates without feature toggles
232-
- run: set +x; for feature in progress fs-walkdir-parallel parallel io-pipe crc32 zlib zlib-rust-backend fast-sha1 rustsha1 cache-efficiency-debug; do (cd gix-features && cargo build --features $feature --target ${{ matrix.target }}); done
233-
name: features of gix-features
234-
- run: set +x; for name in gix-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
235-
name: crates with 'wasm' feature
236-
- run: cd gix-pack && cargo build --all-features --target ${{ matrix.target }}
237-
name: gix-pack with all features (including wasm)
234+
run: |
235+
set +x
236+
for name in gix-sec; do
237+
(cd -- "$name" && cargo build --target "$TARGET")
238+
done
239+
- name: crates without feature toggles
240+
run: |
241+
set +x
242+
for name in gix-actor gix-attributes gix-bitmap gix-chunk gix-command gix-commitgraph gix-config-value gix-date gix-glob gix-hash gix-hashtable gix-mailmap gix-object gix-packetline gix-path gix-pathspec gix-prompt gix-quote gix-refspec gix-revision gix-traverse gix-url gix-validate; do
243+
(cd -- "$name" && cargo build --target "$TARGET")
244+
done
245+
- name: features of gix-features
246+
run: |
247+
set +x
248+
for feature in progress fs-walkdir-parallel parallel io-pipe crc32 zlib zlib-rust-backend fast-sha1 rustsha1 cache-efficiency-debug; do
249+
(cd gix-features && cargo build --features "$feature" --target "$TARGET")
250+
done
251+
- name: crates with 'wasm' feature
252+
run: |
253+
set +x
254+
for name in gix-pack; do
255+
(cd -- "$name" && cargo build --features wasm --target "$TARGET")
256+
done
257+
- name: gix-pack with all features (including wasm)
258+
run: cd gix-pack && cargo build --all-features --target "$TARGET"
238259

239260
check-packetline:
240261
strategy:

Diff for: .github/workflows/release.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ jobs:
266266
- name: Pre-populate directory for archive
267267
run: |
268268
mkdir -- "$ARCHIVE"
269-
cp {README.md,LICENSE-*,CHANGELOG.md} "$ARCHIVE/"
269+
cp -- {README.md,LICENSE-*,CHANGELOG.md} "$ARCHIVE/"
270270
271271
- name: Build archive (Windows)
272272
if: matrix.os == 'windows-latest'
273273
run: |
274274
file -- "$TARGET_DIR/$PROFILE"/{ein,gix}.exe
275275
cp -- "$TARGET_DIR/$PROFILE"/{ein,gix}.exe "$ARCHIVE/"
276276
7z a "$ARCHIVE.zip" "$ARCHIVE"
277-
/usr/bin/core_perl/shasum --algorithm=256 --binary "$ARCHIVE.zip" > "$ARCHIVE.zip.sha256"
277+
/usr/bin/core_perl/shasum --algorithm=256 --binary -- "$ARCHIVE.zip" > "$ARCHIVE.zip.sha256"
278278
echo "ASSET=$ARCHIVE.zip" >> "$GITHUB_ENV"
279279
echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> "$GITHUB_ENV"
280280
@@ -283,8 +283,8 @@ jobs:
283283
run: |
284284
file -- "$TARGET_DIR/$PROFILE"/{ein,gix}
285285
cp -- "$TARGET_DIR/$PROFILE"/{ein,gix} "$ARCHIVE/"
286-
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
287-
shasum --algorithm=256 --binary "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
286+
tar czf "$ARCHIVE.tar.gz" -- "$ARCHIVE"
287+
shasum --algorithm=256 --binary -- "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
288288
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
289289
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> "$GITHUB_ENV"
290290
@@ -329,7 +329,7 @@ jobs:
329329

330330
- name: Unpack single-architecture releases
331331
run: |
332-
shasum --check "$(name aarch64).tar.gz.sha256" "$(name x86_64).tar.gz.sha256"
332+
shasum --check -- "$(name aarch64).tar.gz.sha256" "$(name x86_64).tar.gz.sha256"
333333
tar xf "$(name aarch64).tar.gz"
334334
tar xf "$(name x86_64).tar.gz"
335335
@@ -350,8 +350,8 @@ jobs:
350350
351351
- name: Build archive
352352
run: |
353-
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
354-
shasum --algorithm=256 --binary "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
353+
tar czf "$ARCHIVE.tar.gz" -- "$ARCHIVE"
354+
shasum --algorithm=256 --binary -- "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
355355
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
356356
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> "$GITHUB_ENV"
357357
@@ -389,12 +389,12 @@ jobs:
389389
- name: Extract macOS asset names by architecture
390390
run: |
391391
for arch in aarch64 x86_64 universal; do
392-
grep -Fw "$arch-apple-darwin" assets.txt | sort | tee -- "$arch.txt"
392+
grep -Fwe "$arch-apple-darwin" assets.txt | sort | tee -- "$arch.txt"
393393
done
394394
395395
- name: Check macOS archive features
396396
run: |
397-
mask() { sed -r 's/\w+-apple-darwin/<arch>-apple-darwin/' -- "$1.txt"; }
397+
mask() { sed -E 's/\w+-apple-darwin/<arch>-apple-darwin/' -- "$1.txt"; }
398398
diff -- <(mask aarch64) <(mask universal)
399399
diff -- <(mask x86_64) <(mask universal)
400400
@@ -432,7 +432,7 @@ jobs:
432432
installation:
433433
strategy:
434434
matrix:
435-
build: [win-msvc, win-gnu, win32-msvc, win32-gnu]
435+
build: [ win-msvc, win-gnu, win32-msvc, win32-gnu ]
436436
include:
437437
- build: win-msvc
438438
os: windows-latest
@@ -465,8 +465,8 @@ jobs:
465465
msystem: MINGW${{ startsWith(matrix.target, 'i686-') && '32' || '64' }}
466466
pacboy: cc:p
467467
path-type: inherit
468-
- name: "Install prerequisites"
468+
- name: Install prerequisites
469469
run: vcpkg install zlib:x64-windows-static-md
470-
- name: "Installation from crates.io: gitoxide"
470+
- name: 'Installation from crates.io: gitoxide'
471471
run: cargo +${{ matrix.rust }} install --target ${{ matrix.target }} --no-default-features --features max-pure --target-dir install-artifacts --debug --force gitoxide
472472
shell: msys2 {0}

0 commit comments

Comments
 (0)