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: "22" - 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 run: | task check TEST_FLAGS=-count=1 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-; :latest keeps naming the newest promoted release." fi 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 - 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<> "$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: 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 - 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, agent-image] if: needs.plan.outputs.archied_version != '' runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 - 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: Build the dashboard working-directory: ui run: | pnpm install --frozen-lockfile pnpm run build - name: Resolve archied version id: version run: echo "version=${{ needs.plan.outputs.archied_version }}" >> "$GITHUB_OUTPUT" - name: Build linux/amd64 binaries env: GOOS: linux GOARCH: amd64 CGO_ENABLED: "0" run: | set -e ldflags="-X github.com/samcharles93/archie-core/internal/installtype.buildType=binary -X github.com/samcharles93/archie-core/internal/buildinfo.Version=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/app/agentworker.version=${{ steps.version.outputs.version }}" mkdir -p dist for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do go build -ldflags "$ldflags" -o "dist/$cmd" "./cmd/$cmd" done - 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 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 ./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 }}" 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")" \ '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" \ "$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: ./dist/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