Skip to content

Commit da3b337

Browse files
committed
ci: add shellcheck/actionlint/scalafmt flake checks
Adds three new `nix flake check` entries: - shellcheck on bin/*.sh - actionlint on .github/workflows/*.yml (which itself runs shellcheck against `run:` script bodies) - scalafmt --check across the whole project source tree (a writable copy is made and `git init` ed so that `.scalafmt.conf`'s `project.git = true` works) To unblock the new checks, fix the existing shellcheck findings in bin/*.sh and ci.yml: quote variables, drop a dead `ARGS=$@` line, and add a couple of in-line `# shellcheck disable=SC2016` directives where we intentionally use single quotes to defer expansion to the inner shell.
1 parent de2a594 commit da3b337

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ jobs:
5252
set -eu
5353
check_repo() {
5454
REPO=$1
55-
mkdir -p .repos/$REPO
56-
git clone https://github.com/$REPO.git .repos/$REPO && cd .repos/$REPO && git submodule update --init
55+
mkdir -p ".repos/$REPO"
56+
git clone "https://github.com/$REPO.git" ".repos/$REPO" && cd ".repos/$REPO" && git submodule update --init
5757
58-
docker run -v $PWD/.repos/$REPO:/sources -w /sources sourcegraph/scip-java:latest scip-java index
59-
file .repos/$REPO/index.scip || (echo "$REPO SCIP index doesn't exist!"; exit 1)
58+
docker run -v "$PWD/.repos/$REPO:/sources" -w /sources sourcegraph/scip-java:latest scip-java index
59+
file ".repos/$REPO/index.scip" || (echo "$REPO SCIP index doesn't exist!"; exit 1)
6060
}
6161
6262
sudo apt install parallel
@@ -97,14 +97,16 @@ jobs:
9797
- uses: DeterminateSystems/magic-nix-cache-action@v13
9898

9999
- run: nix develop --command sbt build
100-
- run: echo "$PWD/out/bin" >> $GITHUB_PATH
100+
- run: echo "$PWD/out/bin" >> "$GITHUB_PATH"
101101
- name: Auto-index scip-java codebase
102102
run: |
103+
# shellcheck disable=SC2016
103104
nix develop --command bash -c \
104105
'scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java)'
105106
- run: du -h index.scip
106107
- name: Auto-index example/bazel-workspace
107108
run: |
109+
# shellcheck disable=SC2016
108110
nix develop "$GITHUB_WORKSPACE" --command bash -c \
109111
'scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java)'
110112
working-directory: examples/bazel-example
@@ -169,21 +171,21 @@ jobs:
169171

170172
- run: |
171173
nix develop .#jdk${{ matrix.java }} --command sbt build publishM2 publishLocal dumpScipJavaVersion
172-
echo "SCIP_JAVA_VERSION=$(cat VERSION)" >> $GITHUB_ENV
173-
echo "SCIP_JAVA_CLI=$PWD/out/bin/scip-java" >> $GITHUB_ENV
174+
echo "SCIP_JAVA_VERSION=$(cat VERSION)" >> "$GITHUB_ENV"
175+
echo "SCIP_JAVA_CLI=$PWD/out/bin/scip-java" >> "$GITHUB_ENV"
174176
175177
- run: |
176178
nix develop "$GITHUB_WORKSPACE#jdk${{ matrix.java }}" --command \
177-
mvn clean verify -DskipTests -Dscip-java.version=$SCIP_JAVA_VERSION sourcegraph:sourcegraphDependencies
179+
mvn clean verify -DskipTests "-Dscip-java.version=$SCIP_JAVA_VERSION" sourcegraph:sourcegraphDependencies
178180
working-directory: examples/maven-example
179181
180-
- run: nix develop "$GITHUB_WORKSPACE#jdk${{ matrix.java }}" --command $SCIP_JAVA_CLI index-semanticdb target/semanticdb-targetroot
182+
- run: nix develop "$GITHUB_WORKSPACE#jdk${{ matrix.java }}" --command "$SCIP_JAVA_CLI" index-semanticdb target/semanticdb-targetroot
181183
working-directory: examples/maven-example
182184

183185
- run: |
184186
set -e
185187
grep org.hamcrest target/semanticdb-targetroot/*dependencies.txt
186-
grep $PWD/src/main/java target/semanticdb-targetroot/*dependencies.txt
188+
grep "$PWD/src/main/java" target/semanticdb-targetroot/*dependencies.txt
187189
working-directory: examples/maven-example
188190
189191
- run: du -h index.scip

bin/packagehub.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
/packagehub --host 0.0.0.0 --port $PORT --src /src --coursier /coursier --postgres.username=$DB_USER --postgres.password=$DB_PASS --postgres.url=$DB_URL
2+
/packagehub --host 0.0.0.0 --port "$PORT" --src /src --coursier /coursier --postgres.username="$DB_USER" --postgres.password="$DB_PASS" --postgres.url="$DB_URL"

bin/scip-java-docker-script.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ if test -f "$FILE"; then
1212
fi
1313
fi
1414

15-
JVM_VERSIONS=$(echo $JVM_VERSION | tr "," "\n")
15+
JVM_VERSIONS=$(echo "$JVM_VERSION" | tr "," "\n")
1616

1717
LAST_CODE="-1"
1818

19-
ARGS=$@
20-
2119
for JVM_VERSION in $JVM_VERSIONS
2220
do
2321
if [ "$LAST_CODE" != "0" ]; then

flake.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
in
4242
{
4343
checks = {
44+
actionlint = pkgs.runCommand "check-actionlint" { } ''
45+
${pkgs.actionlint}/bin/actionlint ${./.github/workflows}/*.yml
46+
touch $out
47+
'';
4448
nixfmt = pkgs.runCommand "check-nixfmt" { } ''
4549
${pkgs.nixfmt}/bin/nixfmt --check ${./flake.nix}
4650
touch $out
@@ -50,6 +54,18 @@
5054
${./.github/renovate.json}
5155
touch $out
5256
'';
57+
scalafmt = pkgs.runCommand "check-scalafmt" { buildInputs = [ pkgs.git ]; } ''
58+
cp -r ${./.}/. .
59+
chmod -R u+w .
60+
git init -q
61+
git add -A
62+
HOME=$(mktemp -d) ${pkgs.scalafmt}/bin/scalafmt --check --non-interactive
63+
touch $out
64+
'';
65+
shellcheck = pkgs.runCommand "check-shellcheck" { } ''
66+
${pkgs.shellcheck}/bin/shellcheck ${./bin}/*.sh
67+
touch $out
68+
'';
5369
};
5470

5571
devShells = {

0 commit comments

Comments
 (0)