Skip to content

fix(session): export through directory handles, refuse hard links, no… #158

fix(session): export through directory handles, refuse hard links, no…

fix(session): export through directory handles, refuse hard links, no… #158

Workflow file for this run

name: CLI release
on:
push:
tags:
- 'cli-v[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: cli-release-${{ github.ref }}
cancel-in-progress: false
jobs:
meta:
name: version and notes
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
dry_run: ${{ steps.v.outputs.dry_run }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- id: v
run: |
CLI_VERSION=$(cargo metadata --no-deps --format-version 1 --locked \
| jq -r '.packages[] | select(.name == "tmgr-cli") | .version')
echo "version=$CLI_VERSION" >> "$GITHUB_OUTPUT"
if [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$GITHUB_REF_TYPE" = "tag" ] && [[ "$GITHUB_REF_NAME" == cli-v* ]]; then
if [ "cli-v$CLI_VERSION" != "$GITHUB_REF_NAME" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match crates/tmgr-cli version $CLI_VERSION"
exit 1
fi
echo "dry_run=false" >> "$GITHUB_OUTPUT"
else
echo "dry_run=true" >> "$GITHUB_OUTPUT"
fi
- name: release notes from crates/tmgr-cli/CHANGELOG.md
env:
CLI_VERSION: ${{ steps.v.outputs.version }}
DRY_RUN: ${{ steps.v.outputs.dry_run }}
run: |
awk -v v="$CLI_VERSION" '/^## /{p = ($2 == v); next} p' crates/tmgr-cli/CHANGELOG.md \
| sed -e '/./,$!d' > "$RUNNER_TEMP/notes.md"
if [ ! -s "$RUNNER_TEMP/notes.md" ]; then
if [ "$DRY_RUN" = "false" ]; then
echo "::error::crates/tmgr-cli/CHANGELOG.md has no '## $CLI_VERSION' section"
exit 1
fi
echo "::warning::crates/tmgr-cli/CHANGELOG.md has no '## $CLI_VERSION' section (dry run)"
echo "Dry run notes for $CLI_VERSION" > "$RUNNER_TEMP/notes.md"
fi
cat "$RUNNER_TEMP/notes.md"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: notes
path: ${{ runner.temp }}/notes.md
if-no-files-found: error
build:
name: build ${{ matrix.target }}
needs: meta
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: true
matrix:
include:
- target: x86_64-unknown-linux-musl
runner: ubuntu-latest
- target: aarch64-unknown-linux-musl
runner: ubuntu-24.04-arm
- target: aarch64-apple-darwin
runner: macos-latest
- target: x86_64-apple-darwin
runner: macos-latest
defaults:
run:
shell: bash
env:
CLI_VERSION: ${{ needs.meta.outputs.version }}
TARGET: ${{ matrix.target }}
TMGR_BUILD_COMMIT: ${{ github.sha }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: musl tools
if: contains(matrix.target, 'linux-musl')
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
with:
targets: ${{ matrix.target }}
- name: build
run: |
cargo build --release --locked --package tmgr-cli --features runner --target "$TARGET"
mkdir -p dist
cp "target/$TARGET/release/tmgr" dist/tmgr
file dist/tmgr
- name: smoke
run: |
./dist/tmgr --version
./dist/tmgr runner --help > /dev/null
./dist/tmgr version --json | jq -e --arg v "$CLI_VERSION" '.schema == "tmgr.v1" and .ok and .data.version == $v'
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bin-${{ matrix.target }}
path: dist/tmgr
if-no-files-found: error
sign-macos:
name: sign ${{ matrix.target }}
needs: build
runs-on: macos-latest
strategy:
fail-fast: true
matrix:
target: [aarch64-apple-darwin, x86_64-apple-darwin]
defaults:
run:
shell: bash
env:
SIGNING: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') }}
TARGET: ${{ matrix.target }}
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: bin-${{ matrix.target }}
path: dist
- name: codesign
env:
APPLE_CERTIFICATE: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_CERTIFICATE || '' }}
APPLE_CERTIFICATE_PASSWORD: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_CERTIFICATE_PASSWORD || '' }}
APPLE_SIGNING_IDENTITY: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_SIGNING_IDENTITY || '' }}
run: |
mkdir -p missing
if [ -z "$APPLE_CERTIFICATE" ] || [ -z "$APPLE_CERTIFICATE_PASSWORD" ] || [ -z "$APPLE_SIGNING_IDENTITY" ]; then
echo "::warning::macOS codesign skipped (APPLE_CERTIFICATE, APPLE_CERTIFICATE_PASSWORD, APPLE_SIGNING_IDENTITY not all set, or not a tag push)"
echo "macOS codesign" >> missing/codesign.txt
exit 0
fi
KEYCHAIN="$RUNNER_TEMP/tmgr-sign.keychain-db"
KEYCHAIN_PASSWORD=$(uuidgen)
echo "::add-mask::$KEYCHAIN_PASSWORD"
cleanup() {
security delete-keychain "$KEYCHAIN" 2>/dev/null || true
rm -f "$RUNNER_TEMP/cert.p12"
}
trap cleanup EXIT
echo "$APPLE_CERTIFICATE" | base64 --decode > "$RUNNER_TEMP/cert.p12"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN"
security set-keychain-settings -lut 3600 "$KEYCHAIN"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN"
security import "$RUNNER_TEMP/cert.p12" -k "$KEYCHAIN" -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN" > /dev/null
security list-keychains -d user -s "$KEYCHAIN" login.keychain-db
codesign --force --options runtime --timestamp --sign "$APPLE_SIGNING_IDENTITY" --keychain "$KEYCHAIN" dist/tmgr
codesign --verify --strict --verbose=2 dist/tmgr
touch signed
- name: notarize
env:
APPLE_ID: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_ID || '' }}
APPLE_PASSWORD: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_PASSWORD || '' }}
APPLE_TEAM_ID: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.APPLE_TEAM_ID || '' }}
run: |
if [ ! -f signed ]; then
echo "::warning::macOS notarization skipped (binary is not signed)"
echo "macOS notarization (binary not signed)" >> missing/notarize.txt
exit 0
fi
if [ -z "$APPLE_ID" ] || [ -z "$APPLE_PASSWORD" ] || [ -z "$APPLE_TEAM_ID" ]; then
echo "::warning::macOS notarization skipped (APPLE_ID, APPLE_PASSWORD, APPLE_TEAM_ID not all set)"
echo "macOS notarization (APPLE_ID, APPLE_PASSWORD, APPLE_TEAM_ID)" >> missing/notarize.txt
exit 0
fi
ditto -c -k --keepParent dist/tmgr "$RUNNER_TEMP/tmgr-notarize.zip"
xcrun notarytool submit "$RUNNER_TEMP/tmgr-notarize.zip" \
--apple-id "$APPLE_ID" --password "$APPLE_PASSWORD" --team-id "$APPLE_TEAM_ID" --wait
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: signed-${{ matrix.target }}
path: dist/tmgr
if-no-files-found: error
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: missing-${{ matrix.target }}
path: missing/*
if-no-files-found: ignore
assemble:
name: ${{ needs.meta.outputs.dry_run == 'true' && 'assemble (dry run)' || 'assemble' }}
needs: [meta, build, sign-macos]
runs-on: ubuntu-latest
env:
CLI_VERSION: ${{ needs.meta.outputs.version }}
DRY_RUN: ${{ needs.meta.outputs.dry_run }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: bin-*-linux-musl
path: in
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: signed-*
path: in
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: missing-*
path: missing
merge-multiple: true
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: notes
path: notes
- name: archives and checksums
run: |
mkdir -p release pkg missing
for dir in in/*/; do
NAME=$(basename "$dir")
TARGET=${NAME#bin-}
TARGET=${TARGET#signed-}
PKG="tmgr-$CLI_VERSION-$TARGET"
mkdir -p "pkg/$PKG"
install -m 755 "$dir/tmgr" "pkg/$PKG/tmgr"
cp LICENSE "pkg/$PKG/"
{
echo "tmgr $CLI_VERSION ($TARGET)"
echo
echo "Command line tool for TMGR. Put the tmgr binary on your PATH."
echo "Verify the archive against SHA256SUMS and its .minisig from the release page."
echo "Source: https://github.com/$GITHUB_REPOSITORY (AGPL-3.0-only)"
} > "pkg/$PKG/README.txt"
tar -czf "release/$PKG.tar.gz" -C pkg "$PKG"
done
cd release
sha256sum tmgr-*.tar.gz > SHA256SUMS
cat SHA256SUMS
test "$(wc -l < SHA256SUMS)" -eq 4
- name: manifest
env:
HAS_SIGNING_KEY: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && secrets.CLI_MINISIGN_SECRET_KEY != '' }}
run: |
CHANNEL=stable
if [[ "$CLI_VERSION" == *-* ]] || [ "$HAS_SIGNING_KEY" != "true" ] || compgen -G "missing/*.txt" > /dev/null; then
CHANNEL=beta
fi
EXPIRES=$(date -u -d '+180 days' +%Y-%m-%dT%H:%M:%SZ)
cd release
jq -n --arg version "$CLI_VERSION" --arg channel "$CHANNEL" --arg expires "$EXPIRES" \
'{product: "tmgr-cli", version: $version, channel: $channel, key_epoch: 1, expires_at: $expires, artifacts: []}' \
> manifest.json
for f in tmgr-*.tar.gz; do
TARGET=${f#"tmgr-$CLI_VERSION-"}
TARGET=${TARGET%.tar.gz}
SHA=$(sha256sum "$f" | cut -d' ' -f1)
SIZE=$(stat -c %s "$f")
jq --arg target "$TARGET" --arg name "$f" --arg sha "$SHA" --argjson size "$SIZE" \
'.artifacts += [{target: $target, name: $name, sha256: $sha, size: $size}]' \
manifest.json > manifest.tmp
mv manifest.tmp manifest.json
done
jq -e '.artifacts | length == 4' manifest.json > /dev/null
cat manifest.json
- name: homebrew formula
run: |
mkdir -p homebrew
sha() { grep " tmgr-$CLI_VERSION-$1.tar.gz\$" release/SHA256SUMS | cut -d' ' -f1; }
sed \
-e "s/@VERSION@/$CLI_VERSION/g" \
-e "s/@SHA256_AARCH64_APPLE_DARWIN@/$(sha aarch64-apple-darwin)/" \
-e "s/@SHA256_X86_64_APPLE_DARWIN@/$(sha x86_64-apple-darwin)/" \
-e "s/@SHA256_AARCH64_UNKNOWN_LINUX_MUSL@/$(sha aarch64-unknown-linux-musl)/" \
-e "s/@SHA256_X86_64_UNKNOWN_LINUX_MUSL@/$(sha x86_64-unknown-linux-musl)/" \
packaging/homebrew/tmgr.rb.tmpl > homebrew/tmgr.rb
if grep -q '@' homebrew/tmgr.rb; then
echo "::error::unrendered placeholder in the Homebrew formula"
exit 1
fi
{
echo "### Homebrew formula (not published)"
echo '```ruby'
cat homebrew/tmgr.rb
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: homebrew-formula
path: homebrew/tmgr.rb
if-no-files-found: error
- name: notes and summary
run: |
cp notes/notes.md release-notes.md
{
echo "### tmgr $CLI_VERSION"
echo "- dry run: $DRY_RUN"
if compgen -G "missing/*.txt" > /dev/null; then
echo "- skipped:"
sort -u missing/*.txt | sed 's/^/ - /'
fi
} >> "$GITHUB_STEP_SUMMARY"
cat release-notes.md
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release
path: |
release/*
release-notes.md
missing
if-no-files-found: error
publish:
name: publish release
needs: [meta, assemble]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli-v') && needs.meta.outputs.dry_run == 'false'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
attestations: write
env:
CLI_VERSION: ${{ needs.meta.outputs.version }}
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release
path: .
- name: minisign
env:
CLI_MINISIGN_SECRET_KEY: ${{ secrets.CLI_MINISIGN_SECRET_KEY }}
CLI_MINISIGN_PASSWORD: ${{ secrets.CLI_MINISIGN_PASSWORD }}
run: |
mkdir -p missing
if [ -z "$CLI_MINISIGN_SECRET_KEY" ]; then
echo "::warning::minisign signatures skipped (CLI_MINISIGN_SECRET_KEY not set)"
echo "minisign signatures (CLI_MINISIGN_SECRET_KEY)" >> missing/minisign.txt
exit 0
fi
KEY="$RUNNER_TEMP/minisign.key"
trap 'rm -f "$KEY"' EXIT
umask 077
printf '%s\n' "$CLI_MINISIGN_SECRET_KEY" > "$KEY"
KDF=$(sed -n 2p "$KEY" | base64 --decode | od -An -tx1 | tr -d ' \n' | cut -c5-8)
if [ "$KDF" = "5363" ] && [ -z "$CLI_MINISIGN_PASSWORD" ]; then
echo "::warning::minisign signatures skipped (secret key is encrypted and CLI_MINISIGN_PASSWORD is not set)"
echo "minisign signatures (CLI_MINISIGN_PASSWORD)" >> missing/minisign.txt
exit 0
fi
sudo apt-get update
sudo apt-get install -y minisign
cd release
for f in tmgr-*.tar.gz SHA256SUMS manifest.json; do
if [ "$KDF" = "5363" ]; then
printf '%s\n' "$CLI_MINISIGN_PASSWORD" | minisign -S -s "$KEY" -m "$f"
else
minisign -S -W -s "$KEY" -m "$f"
fi
done
ls -l
- uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: |
release/tmgr-*.tar.gz
release/SHA256SUMS
release/manifest.json
- name: publish GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PRERELEASE=false
if [[ "$CLI_VERSION" == *-* ]]; then PRERELEASE=true; fi
if compgen -G "missing/*.txt" > /dev/null; then
PRERELEASE=true
LIST=$(sort -u missing/*.txt | paste -sd ',' - | sed 's/,/, /g')
printf '\nUnsigned prerelease: %s.\n' "$LIST" >> release-notes.md
fi
{
echo "- prerelease: $PRERELEASE"
if compgen -G "missing/*.txt" > /dev/null; then
echo "- skipped:"
sort -u missing/*.txt | sed 's/^/ - /'
fi
} >> "$GITHUB_STEP_SUMMARY"
FLAGS=(--latest=false)
if [ "$PRERELEASE" = "true" ]; then FLAGS+=(--prerelease); fi
gh release create "$GITHUB_REF_NAME" release/* \
--repo "$GITHUB_REPOSITORY" \
--title "tmgr $CLI_VERSION" \
--notes-file release-notes.md \
"${FLAGS[@]}"