Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Smoke-test cooldowns.sh (Linux + macOS). Logic: ci/smoke-test.sh
# (fed on stdin: bash -s <profile> < ci/smoke-test.sh — same pattern in Docker and on host).
# https://github.com/mprpic/cooldowns/pull/1
name: Smoke tests

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
smoke:
strategy:
matrix:
include:
- name: Linux (Debian container)
runs-on: ubuntu-latest
- name: macOS (isolated HOME, zsh)
runs-on: macos-latest
name: ${{ matrix.name }}
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v5

# Pin Node/npm on every runner (npm 11+ avoids `check` WARN for min-release-age).
# Linux smoke runs in Docker (isolated); macOS smoke uses host PATH, so this matters there.
- uses: actions/setup-node@v4
with:
node-version: '24'

- name: Smoke test
run: |
set -euo pipefail
script="$GITHUB_WORKSPACE/ci/smoke-test.sh"

if [[ "${{ runner.os }}" == "Linux" ]]; then
docker run --rm -i \
-v "$GITHUB_WORKSPACE/cooldowns.sh:/usr/local/bin/cooldowns.sh:ro" \
debian:stable-slim \
bash -s /etc/profile.d/cooldowns.sh < "$script"
else
export PATH="$GITHUB_WORKSPACE:$PATH"
chmod +x "$GITHUB_WORKSPACE/cooldowns.sh"
(
export HOME=$(mktemp -d)
unset ZDOTDIR
export SHELL=/bin/zsh
unset UV_EXCLUDE_NEWER YARN_NPM_MINIMAL_AGE_GATE COOLDOWN_MINUTES PIP_UPLOADED_PRIOR_TO 2>/dev/null || true
trap 'rm -rf "$HOME"' EXIT
bash -s "$HOME/.zshrc" < "$script"
)
fi
79 changes: 79 additions & 0 deletions ci/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# CI/local: configure all tools, source a profile, assert on `cooldowns.sh check`.
# Usage:
# bash ci/smoke-test.sh <profile-to-source>
# bash -s <profile-to-source> < ci/smoke-test.sh # stdin (Docker-friendly)
# Expects cooldowns.sh on PATH.
set -euo pipefail

profile="${1:?usage: ci/smoke-test.sh <profile-to-source>}"

# `set bun` rewrites ~/.bunfig.toml via mktemp+mv when [install] exists; mode must match
# the previous file (copy_mode_from). Seed that case only when bunfig is absent.
file_mode_octal() {
local f="$1"
case "$(uname -s)" in
Darwin) stat -f %OLp "$f" ;; # permission octal only (%a is wrong on macOS)
*) stat -c %a "$f" ;;
esac
}

bunfig="${HOME}/.bunfig.toml"
verify_bunfig_mode_preserved=false
if [[ ! -f "$bunfig" ]]; then
( umask 027; printf '[install]\n' >"$bunfig" )
bunfig_mode_before=$(file_mode_octal "$bunfig")
verify_bunfig_mode_preserved=true
fi

for t in pip uv npm pnpm yarn bun deno cargo; do
cooldowns.sh set "$t" 7d
done

if [[ "$verify_bunfig_mode_preserved" == true ]]; then
bunfig_mode_after=$(file_mode_octal "$bunfig")
if (( "8#$bunfig_mode_before" != "8#$bunfig_mode_after" )); then
echo "smoke: ~/.bunfig.toml mode changed (${bunfig_mode_before} -> ${bunfig_mode_after}) after bun set (expected unchanged; see copy_mode_from in cooldowns.sh)" >&2
exit 1
fi
fi

# shellcheck disable=SC1090
. "$profile"

echo
check_log=$(mktemp)
trap 'rm -f "$check_log"' EXIT

if ! cooldowns.sh check >"$check_log" 2>&1; then
echo "cooldowns.sh check exited non-zero"
cat "$check_log"
exit 1
fi

grep -q "Checking dependency cooldown configurations" "$check_log" || {
echo "expected check header missing"
cat "$check_log"
exit 1
}
grep -q "8 configured, 0 warnings, 0 not configured" "$check_log" || {
echo "expected check summary missing"
cat "$check_log"
exit 1
}
for t in pip uv npm pnpm yarn bun deno cargo; do
grep -qE "^ ok[[:space:]]+${t}[[:space:]]" "$check_log" || {
echo "expected ok line for ${t} missing"
cat "$check_log"
exit 1
}
done
if grep -qE "^ (WARN|MISS)[[:space:]]" "$check_log"; then
echo "unexpected WARN or MISS line"
cat "$check_log"
exit 1
fi

cat "$check_log"
echo "=== sourced profile (${profile}) ==="
cat "$profile"
Loading
Loading