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
76 changes: 69 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,109 @@ name: release
# they came from. People install from
# https://github.com/selfhostit/docs/releases/latest/download/install.sh.
#
# gh workflow run release.yml --repo selfhostit/docs -f version=v1.2.0
# It runs every hour by itself: when an app has a newer release than install.sh pins,
# and that release's images are built, it re-pins install.sh on main and publishes the
# next installer patch release. So after `scripts/release-apps.sh` (or a hand-made app
# release) there is nothing else to do. To release by hand:
#
# gh workflow run release.yml --repo selfhostit/docs # re-pin if needed, next patch
# gh workflow run release.yml --repo selfhostit/docs -f version=v1.2.0 # a version of your choice
#
# Releases are immutable, so the files go in when the release is created.
on:
schedule:
- cron: '17 * * * *'
workflow_dispatch:
inputs:
version:
description: Version tag, like v1.2.0
required: true
description: Version tag, like v1.2.0 (empty for the next patch release)
required: false

permissions:
contents: read

concurrency:
group: release

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # to create the release and its tag
contents: write # to push the new pins, and create the release and its tag
actions: write # to start the release run on the new pins
id-token: write # to sign the attestation
attestations: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Check the version

- name: Re-pin the apps
id: pin
run: |
scripts/pin-apps.sh
if git diff --quiet install.sh; then
echo "The pins are up to date."
echo "changed=n" >> "$GITHUB_OUTPUT"
exit 0
fi
# Pin only releases whose CI run (the signed image build) has succeeded.
git diff -U0 install.sh | sed -n 's/^+\t\([^ ]*\) \([^ ]*\) .*/\1 \2/p' | sort -u |
while read -r app tag; do
result=$(gh run list --repo "selfhostit/$app" --workflow CI --branch "$tag" --limit 1 \
--json status,conclusion -q '.[0] | "\(.status) \(.conclusion)"')
echo "$app $tag: ${result:-no build}"
case $result in
"completed success") ;;
completed*) echo "::error::the $app $tag build failed; release a fixed version"; exit 1 ;;
*) echo "still building; trying again next hour"; exit 2 ;;
esac
done || { [ $? = 2 ] && echo "changed=wait" >> "$GITHUB_OUTPUT" && exit 0; exit 1; }
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -q -m "Pin the installer to the new app releases" install.sh
git push origin HEAD:main
# Release from a fresh run on the new commit, so the attestation names it.
gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref main -f version="$VERSION"
echo "changed=y" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ inputs.version }}

- name: Pick the version
id: version
if: github.event_name == 'workflow_dispatch' && steps.pin.outputs.changed == 'n'
run: |
if [ -z "$VERSION" ]; then
last=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName -q .tagName 2>/dev/null || true)
if [ -n "$last" ]; then
VERSION=$(echo "$last" | awk -F. '{ printf "%s.%s.%d\n", $1, $2, $3 + 1 }')
else
VERSION=v1.0.0
fi
fi
echo "$VERSION" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' || { echo "not a version like v1.2.0: $VERSION"; exit 1; }
echo "Releasing $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ inputs.version }}

- name: Check the pinned app files
if: steps.version.outputs.version
run: scripts/pin-apps.sh --check
- name: SHA-256 sums
if: steps.version.outputs.version
run: sha256sum install.sh selfhostit > SHA256SUMS && cat SHA256SUMS
- name: Attest the files
if: steps.version.outputs.version
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: |
install.sh
selfhostit
- name: Publish the release
if: steps.version.outputs.version
run: |
gh release create "$VERSION" install.sh selfhostit SHA256SUMS \
--target "$GITHUB_SHA" --title "Installer $VERSION" --generate-notes
env:
VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
73 changes: 14 additions & 59 deletions scripts/release-apps.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/sh
# Releases every app that has changed since its last release, then re-pins the
# installer and publishes a new installer release. One command for the whole round:
# Releases every app that has changed since its last release, and returns as soon as
# the releases exist. GitHub does the rest: each release builds and signs its images,
# and .github/workflows/release.yml re-pins the installer and releases it once they're built.
#
# scripts/release-apps.sh show the plan, ask once, then do it all
# scripts/release-apps.sh show the plan, ask once, then release
# scripts/release-apps.sh --dry-run only show the plan
# scripts/release-apps.sh --yes don't ask (for a scheduled run)
#
# Each app with new commits on main gets a patch release (v1.0.0 -> v1.0.1). An app
# whose latest CI run on main isn't green is skipped. For a minor or major release,
# run `gh release create vX.Y.0 --repo selfhostit/<app> --generate-notes` by hand
# first; this script then only re-pins the installer for it.
# first.
#
# Needs gh (signed in, with write access to the selfhostit repos), git and curl.
# Run it from a clone of selfhostit/docs with nothing uncommitted.
# Needs gh, signed in with write access to the selfhostit repos.
set -eu

cd "$(dirname "$0")/.."
Expand All @@ -32,9 +32,6 @@ die() { printf 'release-apps: %s\n' "$*" >&2; exit 1; }
next_patch() { echo "$1" | awk -F. '{ printf "%s.%s.%d\n", $1, $2, $3 + 1 }'; }

gh auth status >/dev/null 2>&1 || die "gh isn't signed in; run: gh auth login"
[ -z "$(git status --porcelain)" ] || die "this docs clone has uncommitted changes"
git checkout -q main
git pull -q --ff-only origin main

# 1. Which apps have something to release?
plan=""
Expand All @@ -57,69 +54,27 @@ for app in $apps; do
plan="$plan $app:$next"
done

# Re-pinning is needed when an app was released since the last pin (by this script or by hand).
if [ -z "$plan" ] && scripts/pin-apps.sh --check 2>/dev/null | grep -q '^note'; then
say " the installer pins an older release of an app; it will be re-pinned"
elif [ -z "$plan" ]; then
if [ -z "$plan" ]; then
say "Nothing to release."
exit 0
fi

last=$(gh release view --repo "$org/docs" --json tagName -q .tagName 2>/dev/null || echo v0.9.9)
installer=$(next_patch "$last")
[ "$last" = v0.9.9 ] && installer=v1.0.0
say " installer -> $installer"

[ $mode = dry ] && exit 0
if [ $mode = ask ]; then
printf 'Release these? [y/N] '
read -r answer
[ "$answer" = y ] || [ "$answer" = Y ] || exit 1
fi

# 2. Release the apps. Each tag starts a CI run that builds, signs and publishes the images.
# 2. Release the apps. Each tag starts a CI run on GitHub that builds, signs and publishes
# the images; the installer's release workflow re-pins them once those runs are green.
for item in $plan; do
app=${item%%:*} next=${item#*:}
gh release create "$next" --repo "$org/$app" --target main --generate-notes >/dev/null
say "Released $app $next"
done

# 3. Wait for every image build; a failed one stops here, before the installer points at it.
for item in $plan; do
app=${item%%:*} next=${item#*:}
run=""
for _ in 1 2 3 4 5 6 7 8 9 10 11 12; do
run=$(gh run list --repo "$org/$app" --workflow CI --branch "$next" --limit 1 \
--json databaseId -q '.[0].databaseId // empty')
[ -n "$run" ] && break
sleep 10
done
[ -n "$run" ] || die "no CI run started for $app $next"
say "Waiting for the $app $next images..."
gh run watch "$run" --repo "$org/$app" --exit-status >/dev/null ||
die "the $app $next build failed: gh run view $run --repo $org/$app --log-failed"
say " $app $next images published"
done

# 4. Re-pin the installer through a pull request, and merge it once its checks pass.
scripts/pin-apps.sh
if git diff --quiet install.sh; then
say "The installer already pins these releases."
else
branch="pin-apps-$installer"
git checkout -q -b "$branch"
git commit -q -m "Pin the installer to the new app releases" install.sh
git push -q -u origin "$branch"
gh pr create --fill --head "$branch" >/dev/null
say "Opened the pins pull request; waiting for its checks..."
sleep 15
gh pr checks "$branch" --watch --fail-fast >/dev/null || die "the pins pull request failed its checks"
gh pr merge "$branch" --squash --delete-branch >/dev/null
git checkout -q main
git pull -q --ff-only origin main
say "Merged the new pins"
fi

# 5. Publish the installer release from main.
gh workflow run release.yml --repo "$org/docs" -f version="$installer"
say "Started the installer $installer release: gh run list --repo $org/docs --workflow release.yml"
say ""
say "GitHub builds the images now (about 15 minutes); follow them with:"
say " gh run list --repo $org/<app> --workflow CI --limit 1"
say "Once they're done, 'selfhostit update all' on your server picks them up, and within the"
say "hour the installer re-pins itself and gets a new release for new installs."
5 changes: 3 additions & 2 deletions security.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ It is one plain shell script with comments. What it does:
starts the compose file ([should-we](https://github.com/selfhostit/should-we/blob/main/docker-compose.yml)).
4. If you say yes, starts one Tailscale container and gives each app an `https://` address.

The pinned list is updated with `scripts/pin-apps.sh` after an app's release, and CI checks
every week that each pinned file still matches GitHub.
The pinned list is updated by `scripts/pin-apps.sh`: an hourly workflow runs it after an
app's release, once that release's images are built, and then publishes a new installer
release. CI checks every week that each pinned file still matches GitHub.

### What needs sudo

Expand Down
Loading