shell-scripts¶
Two small tools, one an archive and one a single binary.
Lint the shell scripts in a repository, with two small tools and no image built for the purpose. The step sees only the scripts.
flowchart LR
s0["shellcheck"]
s1["json is valid"]
The steps this script plans for a push about which nothing is known. An arrow is a needs.
# Lint the shell scripts in a repository, with two small tools and no image
# built for the purpose. The step sees only the scripts.
shellcheck = tool(
"shellcheck",
url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.{arch}.tar.xz",
sha256 = {
"amd64": "8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198",
"arm64": "12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588",
},
arch_names = {"amd64": "x86_64", "arm64": "aarch64"},
bin = ["shellcheck-v0.11.0"],
)
# A single binary rather than an archive: it is saved under the tool's name.
jq = tool(
"jq",
url = "https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-linux-{arch}",
sha256 = {
"amd64": "020468de7539ce70ef1bceaf7cde2e8c4f2ca6c3afb84642aabc5c97d9fc2a0d",
"arm64": "6bc62f25981328edd3cfcfe6fe51b073f2d7e7710d7ef7fcdac28d4e384fc3d4",
},
)
def ci(ctx):
return [
step(
"shellcheck",
image = "debian:12-slim",
tools = [shellcheck],
run = "shellcheck scripts/*.sh",
inputs = ["scripts/*.sh"],
),
step(
"json is valid",
image = "debian:12-slim",
tools = [jq],
run = "for f in config/*.json; do jq empty \"$f\" || exit 1; done",
inputs = ["config/*.json"],
),
]
# Generated by `starci compile` from shell-scripts.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
# - Passes are remembered in this repository's Actions cache, which GitHub
# scopes by branch and evicts when old. starci's own store has neither
# limit.
name: CI
on:
push:
branches: ['**']
tags: ['**']
pull_request:
workflow_dispatch:
jobs:
shellcheck:
name: "shellcheck"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/scripts/*.sh
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-shellcheck-ba360bc949a2f0ba-${{ hashFiles('scripts/*.sh') }}
- name: "Tool: shellcheck"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/shellcheck"
curl -fsSL 'https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz' -o "$RUNNER_TEMP/shellcheck.download"
echo "8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198 $RUNNER_TEMP/shellcheck.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/shellcheck.download" -C "$RUNNER_TEMP/starci-tools/shellcheck"
- name: "shellcheck"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
shellcheck scripts/*.sh
run: |
docker pull -q debian:12-slim
image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$RUNNER_TEMP/starci-tools/shellcheck:/opt/starci/tools/shellcheck:ro" \
-e "PATH=/opt/starci/tools/shellcheck/shellcheck-v0.11.0:$image_path" \
debian:12-slim sh -c "$STARCI_RUN"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
json-is-valid:
name: "json is valid"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/config/*.json
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-json-is-valid-278517b8325745c6-${{ hashFiles('config/*.json') }}
- name: "Tool: jq"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/jq"
curl -fsSL 'https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-linux-amd64' -o "$RUNNER_TEMP/jq.download"
echo "020468de7539ce70ef1bceaf7cde2e8c4f2ca6c3afb84642aabc5c97d9fc2a0d $RUNNER_TEMP/jq.download" | sha256sum -c -
install -m 755 "$RUNNER_TEMP/jq.download" "$RUNNER_TEMP/starci-tools/jq/jq"
- name: "json is valid"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
for f in config/*.json; do jq empty "$f" || exit 1; done
run: |
docker pull -q debian:12-slim
image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$RUNNER_TEMP/starci-tools/jq:/opt/starci/tools/jq:ro" \
-e "PATH=/opt/starci/tools/jq:$image_path" \
debian:12-slim sh -c "$STARCI_RUN"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
# Generated by `starci compile --target circleci` from shell-scripts.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
# - Passes are remembered in this project's CircleCI cache, which expires.
# starci's own store does not.
version: 2.1
jobs:
shellcheck:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Keep only this step's inputs"
command: |
git sparse-checkout set --no-cone '/scripts/*.sh'
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top,glob)scripts/*.sh' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-shellcheck-ba360bc949a2f0ba-{{ checksum "/tmp/starci-inputs" }}
- run:
name: "Stop here if it has"
command: |
if [ -e ~/starci-passed/at ]; then
echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
circleci-agent step halt
fi
- run:
name: "Tool: shellcheck"
command: |
mkdir -p "$HOME/starci-tools/shellcheck"
curl -fsSL 'https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz' -o /tmp/shellcheck.download
echo "8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198 /tmp/shellcheck.download" | sha256sum -c -
tar -xf "/tmp/shellcheck.download" -C "$HOME/starci-tools/shellcheck"
- run:
name: "shellcheck"
environment:
STARCI_RUN: |-
shellcheck scripts/*.sh
command: |
docker pull -q debian:12-slim
image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$HOME/starci-tools/shellcheck:/opt/starci/tools/shellcheck:ro" \
-e "PATH=/opt/starci/tools/shellcheck/shellcheck-v0.11.0:$image_path" \
debian:12-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-shellcheck-ba360bc949a2f0ba-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
json-is-valid:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Keep only this step's inputs"
command: |
git sparse-checkout set --no-cone '/config/*.json'
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top,glob)config/*.json' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-json-is-valid-278517b8325745c6-{{ checksum "/tmp/starci-inputs" }}
- run:
name: "Stop here if it has"
command: |
if [ -e ~/starci-passed/at ]; then
echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
circleci-agent step halt
fi
- run:
name: "Tool: jq"
command: |
mkdir -p "$HOME/starci-tools/jq"
curl -fsSL 'https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-linux-amd64' -o /tmp/jq.download
echo "020468de7539ce70ef1bceaf7cde2e8c4f2ca6c3afb84642aabc5c97d9fc2a0d /tmp/jq.download" | sha256sum -c -
install -m 755 "/tmp/jq.download" "$HOME/starci-tools/jq/jq"
- run:
name: "json is valid"
environment:
STARCI_RUN: |-
for f in config/*.json; do jq empty "$f" || exit 1; done
command: |
docker pull -q debian:12-slim
image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$HOME/starci-tools/jq:/opt/starci/tools/jq:ro" \
-e "PATH=/opt/starci/tools/jq:$image_path" \
debian:12-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-json-is-valid-278517b8325745c6-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
workflows:
ci:
jobs:
- shellcheck
- json-is-valid
Download: shell-scripts.ci.star, GitHub Actions, CircleCI