Files

264 lines
9.6 KiB
YAML

name: deploy
on:
push:
tags: ["v*"]
concurrency:
group: deploy-${{ 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 }}
sha: ${{ steps.release_tag.outputs.sha }}
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Resolve the release
id: release_tag
run: |
echo "archied_version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse "${GITHUB_REF}^{commit}")" >> "$GITHUB_OUTPUT"
gate:
needs: plan
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff
with:
go-version-file: go.mod
cache: false
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1
with:
package_json_file: ui/package.json
- name: Set up Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
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
- name: Quality gate
env:
RELEASE_VERSION: ${{ needs.plan.outputs.archied_version }}
run: |
task check dist TEST_FLAGS=-count=1 VERSION="$RELEASE_VERSION"
git diff --exit-code
- name: Vulnerability scan
run: |
go install golang.org/x/vuln/cmd/govulncheck@v1.9.0
govulncheck ./...
- name: Package the release binaries
# tar keeps the executable bit, which an uploaded artifact drops.
run: tar -cf release-binaries.tar dist
- name: Upload the release binaries
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: release-binaries
path: release-binaries.tar
if-no-files-found: error
retention-days: 1
archied-image:
needs: [plan, gate]
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
with:
# One named builder that is never removed, so the Dockerfiles' cache
# mounts are still there on the next run. Removing it at the end of
# a job would take it from under another run that is building.
name: archie-ci
cleanup: false
- name: Log in to the Gitea registry
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
- name: Build and push archied
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
with:
context: .
file: Dockerfile.archied
push: true
tags: |
git.catlow.cloud/sam/archied:v${{ needs.plan.outputs.archied_version }}
git.catlow.cloud/sam/archied:sha-${{ needs.plan.outputs.sha }}
build-args: |
GATEWAY_VERSION=${{ needs.plan.outputs.archied_version }}
RUNTIME_VERSION=${{ needs.plan.outputs.archied_version }}
cache-from: type=gha,scope=archied
cache-to: type=gha,mode=max,scope=archied
agent-image:
needs: [plan, gate]
outputs:
agent_digest: ${{ steps.agent.outputs.digest }}
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
with:
# One named builder that is never removed, so the Dockerfiles' cache
# mounts are still there on the next run. Removing it at the end of
# a job would take it from under another run that is building.
name: archie-ci
cleanup: false
- name: Log in to the Gitea registry
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
- name: Build and push archie-agent
id: agent
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
with:
context: .
file: Dockerfile
push: true
tags: |
git.catlow.cloud/sam/archie-agent:v${{ needs.plan.outputs.archied_version }}
git.catlow.cloud/sam/archie-agent:sha-${{ needs.plan.outputs.sha }}
build-args: |
RUNTIME_VERSION=${{ needs.plan.outputs.archied_version }}
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]
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
fetch-depth: 0
# The gate built these from the tree it checked; nothing is compiled here.
- name: Download the release binaries
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: release-binaries
- name: Unpack the release binaries
run: tar -xf release-binaries.tar
- 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
cp "dist/$cmd" "$name/"
done
cp deployments/INSTRUCTIONS.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@ea165f8d65b6e75b540449e92b4886f43607fa02
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
./dist/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)"
previous="$(git describe --tags --abbrev=0 --match 'v*' "$tag^" 2>/dev/null || true)"
git log --no-merges --format='- %s' ${previous:+"$previous.."}"$tag" > "$notes"
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: 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