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
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,77 @@ jobs:
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: stable
check-latest: true
- uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: v2.15
- name: gofmt
run: test -z "$(gofmt -l .)" || { gofmt -l .; exit 1; }
- run: go vet ./...
- run: go test -race ./...
- name: govulncheck
run: go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...

# Self-update and the installer differ per OS; the rest of the suite assumes
# unix tools, so only this package runs here.
selfupdate:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: stable
check-latest: true
- run: go test ./internal/selfupdate/...

# Runs the composite action the way users do. checkout keeps its credentials
# here so the scrub has something to remove.
action:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
version: 1.0.0
- os: macos-latest
version: 1.0.0
- os: windows-latest
version: 1.0.0
- os: ubuntu-latest
version: ""
runs-on: ${{ matrix.os }}
permissions:
contents: read
pull-requests: read
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./
with:
command: check
version: ${{ matrix.version }}
- name: credentials are gone and tend is installed
shell: bash
run: |
if git config --local --get-all http.https://github.com/.extraheader; then
echo "the checkout token is still in the config" >&2
exit 1
fi
if git config --local --get-regexp '^includeif\..*\.path$' | grep git-credentials-; then
echo "an include still points at checkout's credentials" >&2
exit 1
fi
temp=$RUNNER_TEMP
command -v cygpath >/dev/null && temp=$(cygpath -u "$RUNNER_TEMP")
if ls "$temp"/git-credentials-*.config 2>/dev/null; then
echo "checkout's credentials file is still in RUNNER_TEMP" >&2
exit 1
fi
ls "$temp"/tend/bin/tend*
tend version
27 changes: 23 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-*"
- "v[0-9]+.[0-9]+.[0-9]+-alpha*"
- "v[0-9]+.[0-9]+.[0-9]+-beta*"
- "v[0-9]+.[0-9]+.[0-9]+-rc*"

permissions:
contents: read
Expand All @@ -16,8 +18,16 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
go-version: stable
check-latest: true
# A shape tend update does not accept would ship binaries that call
# themselves development builds.
- name: tag shape
run: |
[[ $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.?[0-9]+)?$ ]] ||
{ echo "tag $GITHUB_REF_NAME is not vX.Y.Z or vX.Y.Z-(alpha|beta|rc)N" >&2; exit 1; }
- run: go test ./...
- run: go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...

build:
needs: test
Expand All @@ -34,7 +44,8 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
go-version: stable
check-latest: true
- name: build and package
run: |
tag=$GITHUB_REF_NAME
Expand All @@ -44,6 +55,7 @@ jobs:
go build -trimpath \
-ldflags "-s -w -X main.version=$tag -X main.commit=$(git rev-parse --short HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-o "stage/$bin" ./cmd/tend
env -u GOOS -u GOARCH go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 -mode binary "stage/$bin"
name=tend_${tag#v}_${GOOS}_${GOARCH}
if [ "$GOOS" = windows ]; then
(cd stage && zip -q "../dist/$name.zip" "$bin")
Expand All @@ -68,7 +80,8 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
go-version: stable
check-latest: true
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: dist-*
Expand All @@ -80,6 +93,12 @@ jobs:
run: |
(cd dist && sha256sum tend_* > checksums.txt)
go run ./internal/selfupdate/sign -in dist/checksums.txt > dist/checksums.txt.sig
# The same check install.sh makes, on the exact files the Action will read.
- name: verify signature
run: |
base64 -d < dist/checksums.txt.sig > "$RUNNER_TEMP/sig.bin"
openssl pkeyutl -verify -pubin -inkey action/pubkey.pem -rawin \
-in dist/checksums.txt -sigfile "$RUNNER_TEMP/sig.bin"
- name: publish
env:
GH_TOKEN: ${{ github.token }}
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/tend.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
name: tend

# Runs the action from this checkout on this repository. Its PRs only start
# ci.yml when TEND_TOKEN holds a GitHub App or fine-grained token; with the
# default token, "Allow GitHub Actions to create and approve pull requests"
# has to be on and the PRs get no CI.
on:
schedule:
- cron: "17 6 * * 1"
- cron: "17 6 * * 1,4"
workflow_dispatch:

permissions:
contents: write
pull-requests: write
issues: write
checks: read
statuses: read

concurrency:
group: tend
Expand All @@ -21,20 +27,12 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
go-version: stable
check-latest: true
- uses: ./
with:
path: ~/.cache/tend/repos
key: tend-${{ github.repository }}-${{ github.run_id }}
restore-keys: tend-${{ github.repository }}-
- run: go run ./cmd/tend run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEND_MODEL_KEY: ${{ secrets.TEND_MODEL_KEY }}
- if: always()
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/tend/repos
key: tend-${{ github.repository }}-${{ github.run_id }}
token: ${{ secrets.TEND_TOKEN || github.token }}
model-key: ${{ secrets.TEND_MODEL_KEY }}
37 changes: 25 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branding:
color: green
inputs:
token:
description: Token with contents:write and pull-requests:write. The default token cannot start other workflows or push workflow changes; pass a fine-grained or GitHub App token for those
description: Token with contents:write and pull-requests:write. PRs the default token opens start no other workflows; pass a fine-grained or GitHub App token, with the Workflows permission for Action bumps, to lift that
default: ${{ github.token }}
command:
description: run | check
Expand All @@ -17,11 +17,14 @@ inputs:
description: Path to tend.yml
default: ""
version:
description: tend version to install; default is the latest release of this action's major
description: tend version to install; default is the release this action is pinned to (a tag, or the release tagged at a pinned commit), or the newest release of its major or minor
default: ""
model-key:
description: API key for the model provider named in tend.yml
default: ""
fail-on-unproven:
description: Fail the job when tend cannot prove a change it lists in its tracking issue; by default that is a warning, and the change is tried again when the base moves
default: "false"
runs:
using: composite
steps:
Expand All @@ -31,17 +34,20 @@ runs:
GITHUB_TOKEN: ${{ inputs.token }}
run: '"$GITHUB_ACTION_PATH/action/install.sh" "$TEND_VERSION"'
# tend pushes with the token it is given. A token that actions/checkout
# left in the repository's config would be readable by the project's own
# install and test commands, so it goes, whatever the checkout step says.
# left behind, in the repository's config or in the credentials file under
# RUNNER_TEMP, would be readable by the project's own install and test
# commands, so both go, whatever the checkout step says. A process running
# as the runner's user can still find tokens elsewhere, through sudo on
# hosted runners for one; verify.container is the real boundary.
- shell: bash
run: |
git config --local --unset-all http.https://github.com/.extraheader || true
git config --local --get-regexp '^includeif\..*\.path$' 2>/dev/null | while read -r key val; do
case "$val" in *git-credentials*) git config --local --unset-all "$key" ;; esac
done || true
run: '"$GITHUB_ACTION_PATH/action/scrub.sh"'
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/tend/repos
path: |
${{ runner.temp }}/tend/repos
!${{ runner.temp }}/tend/repos/*/wt
!${{ runner.temp }}/tend/repos/*/baseline
!${{ runner.temp }}/tend/repos/*/lock
key: tend-${{ github.repository }}-${{ github.run_id }}
restore-keys: tend-${{ github.repository }}-
# The user cache dir differs per OS, so state goes where the cache steps look.
Expand All @@ -54,9 +60,16 @@ runs:
TEND_CONFIG: ${{ inputs.config }}
TEND_COMMAND: ${{ inputs.command }}
TEND_ARGS: ${{ inputs.args }}
run: tend "$TEND_COMMAND" $TEND_ARGS
TEND_FAIL_ON_UNPROVEN: ${{ inputs.fail-on-unproven }}
# exec, so no shell holding these variables stays behind as tend's
# parent for the project's commands to read through /proc.
run: set -f; exec tend "$TEND_COMMAND" $TEND_ARGS
- if: always()
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/tend/repos
path: |
${{ runner.temp }}/tend/repos
!${{ runner.temp }}/tend/repos/*/wt
!${{ runner.temp }}/tend/repos/*/baseline
!${{ runner.temp }}/tend/repos/*/lock
key: tend-${{ github.repository }}-${{ github.run_id }}
78 changes: 58 additions & 20 deletions action/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,62 @@ tags() {
grep -o '"tag_name": *"[^"]*"' | sed 's/.*"\([^"]*\)"$/\1/' || true
}

# An explicit version wins. Then a full tag in the action ref. Then the newest
# release inside the ref's major (uses: ...@v1), followed by the one before
# it, else the newest release.
releases() {
local body
body=$(api_get "$api/repos/$repo/releases?per_page=100") || die "could not list releases of $repo"
echo "$body" | tags
}

# tagged prints the release tags that point at commit $1. /tags gives each
# tag's commit already dereferenced, so annotated tags match too.
tagged() {
local page=1 body count
while [ "$page" -le 50 ]; do
body=$(api_get "$api/repos/$repo/tags?per_page=100&page=$page") || die "could not list tags of $repo"
count=$(echo "$body" | grep -o '"name": *"[^"]*"' | wc -l)
echo "$body" | grep -oE '"(name|sha)": *"[^"]*"' | awk -F'"' -v want="$1" '
$2 == "name" { name = $4; next }
$2 == "sha" && name != "" { if ($4 == want) print name; name = "" }'
[ "$count" -ge 100 ] || return 0
page=$((page + 1))
done
}

newest() {
sort -t. -k1.2,1nr -k2,2nr -k3,3nr | head -n "$1"
}

# An explicit version wins. Then the action ref: a full tag is used as is; a
# commit installs the release tagged at that commit; a major (@v1) or a minor
# (@v1.2) installs the newest release inside it, followed by the one before
# it. Any other ref, a branch, gets the latest release.
resolve() {
local major list
local list sha found pick
if [ -n "${1:-}" ]; then
echo "v${1#v}"
return
fi
case "$ref" in
v[0-9]*.[0-9]*.[0-9]*)
if [[ $ref =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
echo "$ref"
return
;;
v[0-9]*)
major=${ref%%.*}
list=$(api_get "$api/repos/$repo/releases?per_page=100" | tags) || die "could not list releases of $repo"
{ echo "$list" | grep -E "^${major}\.[0-9]+\.[0-9]+\$" || true; } | sort -t. -k2,2nr -k3,3nr | head -n 2
return
;;
esac
api_get "$api/repos/$repo/releases/latest" | tags | sed -n 1p
elif [[ $ref =~ ^v[0-9]+$ ]]; then
list=$(releases) || exit 1
echo "$list" | grep -E "^${ref}\.[0-9]+\.[0-9]+\$" | newest 2 || true
elif [[ $ref =~ ^v[0-9]+\.[0-9]+$ ]]; then
list=$(releases) || exit 1
echo "$list" | grep -E "^${ref%.*}\.${ref#*.}\.[0-9]+\$" | newest 2 || true
elif [[ $ref =~ ^[0-9a-fA-F]{40}$ ]]; then
sha=$(echo "$ref" | tr A-F a-f)
found=$(tagged "$sha") || exit 1
pick=$(echo "$found" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | newest 1 || true)
[ -n "$pick" ] || pick=$(echo "$found" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.]+$' | head -n 1 || true)
[ -n "$pick" ] || die "commit $sha of $repo is not a release; pin a release commit or set the version input"
echo "$pick"
elif [[ $ref =~ ^v[0-9] ]]; then
die "action ref $ref is not a release tag; use @vN, @vN.M, @vN.M.P or a release commit, or set the version input"
else
[ -z "$ref" ] || echo "tend install: action ref $ref is not a release; installing the latest release" >&2
api_get "$api/repos/$repo/releases/latest" | tags | sed -n 1p
fi
}

find_openssl() {
Expand All @@ -70,9 +104,8 @@ sha256_of() {
tags=$(resolve "${1:-}")
tag=$(echo "$tags" | sed -n 1p)
[ -n "$tag" ] || die "no release of $repo matches ${1:-${ref:-the latest release}}"
# The newest release of a major may still be uploading its files when a
# scheduled run starts; the one before it is installed instead. Either is
# checked the same way below.
# A major or minor ref falls back to the release before the newest when the
# newest has no signed checksums. Either is checked the same way below.
older=$(echo "$tags" | sed -n 2p)
if [ -n "$older" ] && ! curl -fsSL --retry 2 -o /dev/null "$dl/$repo/releases/download/$tag/checksums.txt.sig" 2>/dev/null; then
echo "tend install: $tag has no signed checksums yet; installing $older" >&2
Expand Down Expand Up @@ -128,10 +161,15 @@ else
fi

dest=${RUNNER_TEMP:-${TMPDIR:-/tmp}}/tend/bin
entry=$dest
if [ "$os" = windows ] && command -v cygpath >/dev/null 2>&1; then
dest=$(cygpath -u "$dest")
entry=$(cygpath -w "$dest")
fi
mkdir -p "$dest"
install -m 0755 "$work/$bin" "$dest/$bin"
if [ -n "${GITHUB_PATH:-}" ]; then
echo "$dest" >>"$GITHUB_PATH"
echo "$entry" >>"$GITHUB_PATH"
else
echo "add to PATH: $dest"
fi
Expand Down
Loading
Loading