diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 281f2c7da..d17dc3edf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,8 @@ jobs: outputs: archied_version: ${{ steps.release_tag.outputs.archied_version }} run: ${{ steps.release_tag.outputs.run }} + sha: ${{ steps.release_tag.outputs.sha }} + component: ${{ steps.release_tag.outputs.component }} steps: - name: Checkout uses: actions/checkout@v4 @@ -35,6 +37,12 @@ jobs: else echo "no release tag at HEAD; distribution zip will be skipped" fi + # An annotated tag makes GITHUB_SHA the tag object, so the commit is + # resolved from the ref: image tags pin it. + sha="$(git rev-parse "${GITHUB_REF}^{commit}")" + echo "sha=$sha" >> "$GITHUB_OUTPUT" + # A release reports its version; any other build of main names its commit. + echo "component=${version:-dev+${sha:0:12}}" >> "$GITHUB_OUTPUT" run=true case "$GITHUB_REF" in refs/tags/*) ;; @@ -70,7 +78,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v4 with: - node-version: "22" + node-version: "24" - name: Install quality tools run: | @@ -94,13 +102,22 @@ jobs: run: docker pull alpine:3 - name: Quality gate + env: + RELEASE_VERSION: ${{ needs.plan.outputs.archied_version }} run: | - task check TEST_FLAGS=-count=1 + # A release also builds the binaries it ships, in the same task run: + # the dashboard is built once and the tree that passed is the tree + # that is published. + if [ -n "$RELEASE_VERSION" ]; then + task check dist TEST_FLAGS=-count=1 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 + go install golang.org/x/vuln/cmd/govulncheck@v1.9.0 govulncheck ./... - name: Release tags must match changelogs @@ -129,156 +146,116 @@ jobs: echo "This commit isn't a release, so the images are published as :edge and sha-; :latest keeps naming the newest promoted release." fi + - name: Package the release binaries + if: needs.plan.outputs.archied_version != '' + # tar keeps the executable bit, which an uploaded artifact drops. + run: tar -cf release-binaries.tar dist + + - name: Upload the release binaries + if: needs.plan.outputs.archied_version != '' + uses: actions/upload-artifact@v4 + with: + name: release-binaries + path: release-binaries.tar + if-no-files-found: error + retention-days: 1 + archied-image: - needs: gate + needs: [plan, 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: + # 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: 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 }} + # The first line is empty for a build of main; empty lines are ignored. + tags: | + ${{ needs.plan.outputs.archied_version != '' && format('git.catlow.cloud/sam/archied:v{0}', needs.plan.outputs.archied_version) || '' }} + git.catlow.cloud/sam/archied:edge + git.catlow.cloud/sam/archied:sha-${{ needs.plan.outputs.sha }} build-args: | - GATEWAY_VERSION=${{ steps.versions.outputs.gateway }} - RUNTIME_VERSION=${{ steps.versions.outputs.runtime }} + GATEWAY_VERSION=${{ needs.plan.outputs.component }} + RUNTIME_VERSION=${{ needs.plan.outputs.component }} cache-from: type=gha,scope=archied cache-to: type=gha,mode=max,scope=archied agent-image: + needs: [plan, gate] + # The agent image is only published with a release. + if: needs.plan.outputs.run == 'true' && needs.plan.outputs.archied_version != '' 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 + 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: 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 }} + 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=${{ steps.versions.outputs.runtime }} + 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, agent-image] - if: needs.plan.outputs.archied_version != '' + # archied-image is needed so a release never reaches the canary without it. + needs: [plan, gate, archied-image, agent-image] + if: needs.plan.outputs.run == 'true' && 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 + # The gate built these from the tree it checked; nothing is compiled here. + - name: Download the release binaries + uses: actions/download-artifact@v4 with: - go-version-file: go.mod - cache: false + name: release-binaries - - 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: 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: 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: | @@ -327,6 +304,8 @@ jobs: 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 } @@ -343,7 +322,8 @@ jobs: 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}')" \ + --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"