1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Formatting, as `just format` checks it: `swiftformat --lint` over Grain
# and GrainTests with the repository's .swiftformat, on pushes to main and
# pulls into it. It lists each file it would change and fails if there is
# one; `just format-fix` changes them.
#
# The build and the tests are not here, nor anything else that needs Xcode:
# the runner is Linux, and xcodebuild runs on macOS alone. SwiftFormat and
# SwiftLint (lint.yml) are what has a Linux build.
#
# SwiftFormat is its Linux release, pinned by version and SHA-256, so a
# release's new rules land on purpose rather than with an unrelated push.
# 0.62.1 is the version the code is formatted with: 0.64.5 adds rules
# (repeatedGuard, nestedIf, extensionAttributes) that main does not pass,
# and a bump here comes with `just format-fix` run on that version.
# Its own image will not do: the runner starts the image with
# `tail -f /dev/null` to run each step in, and the image's entrypoint is
# swiftformat. The download is kept between runs.
image: debian:trixie-slim
on:
push: { refs: [refs/heads/main] }
pull: { base: [refs/heads/main] }
cache: [/opt/swiftformat]
env:
SWIFTFORMAT_VERSION: 0.62.1
SWIFTFORMAT_SHA256: 61ff55f3581e2144a4ad114831167102c38be853df75c1477d20b40a8e8120aa
steps:
- name: swiftformat
timeout: 10
run: |
if [ "$(cat /opt/swiftformat/.version 2>/dev/null)" != "$SWIFTFORMAT_VERSION" ]; then
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends ca-certificates curl unzip >/dev/null
find /opt/swiftformat -mindepth 1 -delete
curl -fsSL -o /tmp/swiftformat.zip "https://github.com/nicklockwood/SwiftFormat/releases/download/$SWIFTFORMAT_VERSION/swiftformat_linux.zip"
echo "$SWIFTFORMAT_SHA256 /tmp/swiftformat.zip" | sha256sum -c -
unzip -q /tmp/swiftformat.zip -d /opt/swiftformat
bin=$(find /opt/swiftformat -type f -name 'swiftformat*' ! -name '*.zip' | head -1)
chmod +x "$bin" && ln -sf "$bin" /opt/swiftformat/swiftformat-bin
echo "$SWIFTFORMAT_VERSION" > /opt/swiftformat/.version
fi
- name: format
timeout: 10
run: |
/opt/swiftformat/swiftformat-bin --version
/opt/swiftformat/swiftformat-bin Grain GrainTests --lint