The release gate stamps the version into `task build`, and the distribution step packages those binaries instead of compiling the tree a second time with different flags. `task build` is static to match. The image builds keep Go's compile cache between runs. canary and promote take archied from the published edge image. The Woodpecker gate and pull-request check keep Go's caches on the host. Also: one Node version, the distribution waits for the archied image, release notes wait for the signed release and carry the prerelease flag.
367 lines
13 KiB
YAML
367 lines
13 KiB
YAML
name: deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
|
|
concurrency:
|
|
group: ${{ startsWith(github.ref, 'refs/tags/') && format('deploy-release-{0}', github.sha) || format('deploy-{0}', github.ref) }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
plan:
|
|
runs-on: self-hosted
|
|
outputs:
|
|
archied_version: ${{ steps.release_tag.outputs.archied_version }}
|
|
run: ${{ steps.release_tag.outputs.run }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve archied tag at HEAD
|
|
id: release_tag
|
|
run: |
|
|
version="$(git tag --points-at HEAD --list 'v*' | sed -e 's|^v||' | sort -V | tail -1)"
|
|
echo "archied_version=$version" >> "$GITHUB_OUTPUT"
|
|
if [ -n "$version" ]; then
|
|
echo "archied release at HEAD: $version"
|
|
else
|
|
echo "no release tag at HEAD; distribution zip will be skipped"
|
|
fi
|
|
run=true
|
|
case "$GITHUB_REF" in
|
|
refs/tags/*) ;;
|
|
*)
|
|
if [ -n "$version" ]; then
|
|
run=false
|
|
echo "the v$version tag push runs this commit; skipping the branch run"
|
|
fi
|
|
;;
|
|
esac
|
|
echo "run=$run" >> "$GITHUB_OUTPUT"
|
|
|
|
gate:
|
|
needs: plan
|
|
if: needs.plan.outputs.run == 'true'
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: false
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
package_json_file: ui/package.json
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "24"
|
|
|
|
- name: Install quality tools
|
|
run: |
|
|
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(cat .golangci-version)
|
|
go install mvdan.cc/gofumpt@v0.11.0
|
|
go install github.com/go-task/task/v3/cmd/task@v3.48.0
|
|
|
|
- name: Install protobuf tools
|
|
run: bash tools/proto.sh install
|
|
|
|
- name: Ensure contract baseline ref
|
|
run: |
|
|
if ! git show-ref --verify --quiet refs/heads/main; then
|
|
git branch main origin/main
|
|
fi
|
|
|
|
- name: Verify unprivileged user namespaces
|
|
run: unshare --user --map-root-user --net true
|
|
|
|
- name: Pull test container images
|
|
run: docker pull alpine:3
|
|
|
|
# A release stamps its version here: dist-zip ships these binaries, so
|
|
# the release is what the gate tested.
|
|
- name: Quality gate
|
|
env:
|
|
RELEASE_VERSION: ${{ needs.plan.outputs.archied_version }}
|
|
run: |
|
|
if [ -n "$RELEASE_VERSION" ]; then
|
|
task check TEST_FLAGS=-count=1 GATEWAY_VERSION="$RELEASE_VERSION" RUNTIME_VERSION="$RELEASE_VERSION"
|
|
else
|
|
task check TEST_FLAGS=-count=1
|
|
fi
|
|
git diff --exit-code
|
|
|
|
- name: Vulnerability scan
|
|
run: |
|
|
go install golang.org/x/vuln/cmd/govulncheck@latest
|
|
govulncheck ./...
|
|
|
|
- name: Release tags must match changelogs
|
|
run: |
|
|
set -e
|
|
fail=0
|
|
for tag in $(git tag --points-at HEAD); do
|
|
case "$tag" in
|
|
v*)
|
|
ver="${tag#v}"
|
|
echo " release tag $tag -> looking for [$ver] in CHANGELOG.md"
|
|
grep -q "^## \\[$ver\\]" CHANGELOG.md || {
|
|
echo " FAIL: CHANGELOG.md has no [$ver] section"
|
|
fail=1
|
|
}
|
|
;;
|
|
esac
|
|
done
|
|
if [ $fail -ne 0 ]; then
|
|
echo
|
|
echo "A release tag points at this commit but its changelog does not"
|
|
echo "describe that version. Cut releases with the release workflow."
|
|
exit 1
|
|
fi
|
|
if ! git tag --points-at HEAD | grep -qE '^v[0-9]' ; then
|
|
echo "This commit isn't a release, so the images are published as :edge and sha-<sha>; :latest keeps naming the newest promoted release."
|
|
fi
|
|
|
|
- name: Upload the release binaries
|
|
if: needs.plan.outputs.archied_version != ''
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: release-binaries
|
|
path: bin/
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
archied-image:
|
|
needs: gate
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve the commit this ref points at
|
|
id: commit
|
|
run: |
|
|
sha="$(git rev-parse "${GITHUB_REF}^{commit}")"
|
|
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
|
echo "short=${sha:0:12}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
# A named builder that keeps its state, so the Dockerfile's compile
|
|
# cache is still there on the next run.
|
|
name: archie-archied
|
|
keep-state: true
|
|
|
|
- name: Log in to the Gitea registry
|
|
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
|
|
|
|
- name: Resolve component versions
|
|
id: versions
|
|
run: |
|
|
RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)"
|
|
GATEWAY_VERSION="${RELEASE_TAG#v}"
|
|
RUNTIME_VERSION="${RELEASE_TAG#v}"
|
|
[ -n "$GATEWAY_VERSION" ] || GATEWAY_VERSION="dev+${GITHUB_SHA:0:12}"
|
|
[ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION="dev+${GITHUB_SHA:0:12}"
|
|
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "gateway=$GATEWAY_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT"
|
|
{
|
|
echo "archied_tags<<EOF"
|
|
if [ -n "$RELEASE_TAG" ]; then
|
|
echo "git.catlow.cloud/sam/archied:$RELEASE_TAG"
|
|
fi
|
|
echo "git.catlow.cloud/sam/archied:edge"
|
|
echo "git.catlow.cloud/sam/archied:sha-${{ steps.commit.outputs.sha }}"
|
|
echo "EOF"
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push archied
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile.archied
|
|
push: true
|
|
tags: ${{ steps.versions.outputs.archied_tags }}
|
|
build-args: |
|
|
GATEWAY_VERSION=${{ steps.versions.outputs.gateway }}
|
|
RUNTIME_VERSION=${{ steps.versions.outputs.runtime }}
|
|
cache-from: type=gha,scope=archied
|
|
cache-to: type=gha,mode=max,scope=archied
|
|
|
|
agent-image:
|
|
outputs:
|
|
agent_digest: ${{ steps.agent.outputs.digest }}
|
|
needs: [plan, gate]
|
|
if: needs.plan.outputs.archied_version != ''
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve the commit this ref points at
|
|
id: commit
|
|
run: |
|
|
sha="$(git rev-parse "${GITHUB_REF}^{commit}")"
|
|
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
|
echo "short=${sha:0:12}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
name: archie-agent
|
|
keep-state: true
|
|
|
|
- name: Log in to the Gitea registry
|
|
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
|
|
|
|
- name: Resolve runtime version
|
|
id: versions
|
|
run: |
|
|
RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)"
|
|
RUNTIME_VERSION="${RELEASE_TAG#v}"
|
|
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push archie-agent
|
|
id: agent
|
|
if: steps.versions.outputs.release_tag != ''
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |
|
|
git.catlow.cloud/sam/archie-agent:${{ steps.versions.outputs.release_tag }}
|
|
git.catlow.cloud/sam/archie-agent:sha-${{ steps.commit.outputs.sha }}
|
|
build-args: |
|
|
RUNTIME_VERSION=${{ steps.versions.outputs.runtime }}
|
|
cache-from: type=gha,scope=archie-agent
|
|
cache-to: type=gha,mode=max,scope=archie-agent
|
|
|
|
dist-zip:
|
|
needs: [plan, gate, archied-image, agent-image]
|
|
if: needs.plan.outputs.archied_version != ''
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download the binaries the gate built
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: release-binaries
|
|
path: bin
|
|
|
|
- name: Resolve archied version
|
|
id: version
|
|
run: echo "version=${{ needs.plan.outputs.archied_version }}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Assemble distribution zip
|
|
id: zip
|
|
run: |
|
|
set -e
|
|
name="archie-core-archied-v${{ steps.version.outputs.version }}-linux-amd64"
|
|
mkdir -p "$name"
|
|
for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do
|
|
# An artifact does not keep the executable bit.
|
|
install -m 0755 "bin/$cmd" "$name/$cmd"
|
|
done
|
|
chmod +x bin/archied
|
|
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$name/"
|
|
digest='${{ needs.agent-image.outputs.agent_digest }}'
|
|
test -n "$digest"
|
|
jq --arg image "git.catlow.cloud/sam/archie-agent@$digest" '. + {agent_image: $image}' release.json > "$name/release.json"
|
|
[ -f README.md ] && cp README.md "$name/"
|
|
zip -r "$name.zip" "$name"
|
|
echo "name=$name" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Upload distribution zip
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ steps.zip.outputs.name }}
|
|
path: ${{ steps.zip.outputs.name }}.zip
|
|
retention-days: 90
|
|
|
|
- name: Log in to the Gitea registry
|
|
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
|
|
|
|
- name: Publish the signed release
|
|
env:
|
|
ARCHIE_RELEASE_SEED: ${{ secrets.RELEASE_SIGNING_KEY }}
|
|
run: |
|
|
set -e
|
|
version="${{ steps.version.outputs.version }}"
|
|
prerelease=false
|
|
case "$version" in *-*) prerelease=true ;; esac
|
|
./bin/archied release publish -source git.catlow.cloud/sam/archie \
|
|
-version "$version" -prerelease="$prerelease" \
|
|
-zip "${{ steps.zip.outputs.name }}.zip" \
|
|
-agent-image "git.catlow.cloud/sam/archie-agent@${{ needs.agent-image.outputs.agent_digest }}" \
|
|
-changelog "https://git.catlow.cloud/sam/archie/releases/tag/v$version"
|
|
|
|
- name: Publish the Gitea release notes
|
|
env:
|
|
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
|
run: |
|
|
set -e
|
|
tag="v${{ steps.version.outputs.version }}"
|
|
version="${{ steps.version.outputs.version }}"
|
|
prerelease=false
|
|
case "$version" in *-*) prerelease=true ;; esac
|
|
notes="$(mktemp)"
|
|
awk -v hdr="## [$version]" '
|
|
index($0, hdr) == 1 { printing = 1 }
|
|
printing && /^## \[/ && index($0, hdr) != 1 { exit }
|
|
printing { print }
|
|
' CHANGELOG.md > "$notes"
|
|
if ! [ -s "$notes" ]; then
|
|
echo "no [$version] section extracted from CHANGELOG.md" >&2
|
|
exit 1
|
|
fi
|
|
api="https://git.catlow.cloud/api/v1"
|
|
repo="sam/archie"
|
|
auth="Authorization: token $DEPLOY_TOKEN"
|
|
curl -sf -X DELETE -H "$auth" "$api/repos/$repo/releases/tags/$tag" >/dev/null || true
|
|
curl -sf -X POST -H "$auth" -H "Content-Type: application/json" \
|
|
-d "$(jq -n --arg tag "$tag" --arg name "Archie v$version" --arg body "$(cat "$notes")" \
|
|
--argjson prerelease "$prerelease" \
|
|
'{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: $prerelease}')" \
|
|
"$api/repos/$repo/releases" >/dev/null
|
|
echo "published release notes for $tag"
|
|
|
|
- name: Install the release on the canary
|
|
if: vars.CANARY_URL != ''
|
|
env:
|
|
ARCHIE_CANARY_TOKEN: ${{ secrets.CANARY_TOKEN }}
|
|
run: ./bin/archied release canary start -dashboard "${{ vars.CANARY_URL }}" -version "${{ steps.version.outputs.version }}"
|
|
|
|
- name: Link the packages to this repository
|
|
env:
|
|
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
|
run: |
|
|
for name in archied archie-agent archie; do
|
|
curl -sS -o /dev/null -X POST -H "Authorization: token $DEPLOY_TOKEN" \
|
|
"https://git.catlow.cloud/api/v1/packages/sam/container/$name/-/link/archie" || true
|
|
done
|