diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d18b6f..9adc48b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,6 +118,7 @@ jobs: version: ${{ steps.meta.outputs.version }} release_tag: ${{ steps.meta.outputs.release_tag }} release_name: ${{ steps.meta.outputs.release_name }} + deploy_tag: ${{ steps.meta.outputs.deploy_tag }} prerelease: ${{ steps.meta.outputs.prerelease }} steps: - name: Checkout @@ -138,10 +139,14 @@ jobs: branch="${GITHUB_REF_NAME}" release_tag="" release_name="" + deploy_tag="" prerelease="false" if [[ "${branch}" == "main" ]]; then - tags="${image}:${version}" + # Publish an immutable :- that production pins to, + # so every release changes CD desired state and ArgoCD rolls it out. + tags="${image}:${version}"$'\n'"${image}:${version}-${short_sha}" + deploy_tag="${version}-${short_sha}" release_tag="v${version}" release_name="Benchfinity v${version}" elif [[ "${branch}" == "develop" ]]; then @@ -164,6 +169,7 @@ jobs: echo "version=${version}" echo "release_tag=${release_tag}" echo "release_name=${release_name}" + echo "deploy_tag=${deploy_tag}" echo "prerelease=${prerelease}" echo "tags< ~/.ssh/cd_deploy_key + chmod 600 ~/.ssh/cd_deploy_key + ssh-keyscan -t ed25519,rsa github.com >> ~/.ssh/known_hosts 2>/dev/null + export GIT_SSH_COMMAND="ssh -i ~/.ssh/cd_deploy_key -o IdentitiesOnly=yes" + + git clone --depth 1 --branch "${CD_BRANCH}" "git@github.com:${CD_REPO}.git" cd-repo + cd cd-repo + + # DEPLOY_TAG and IMAGE_NAME are CI-derived (package.json version + commit + # SHA), not user-controlled input, so they are safe to pass to yq via env. + DEPLOY_TAG="${DEPLOY_TAG}" IMAGE_NAME="${IMAGE_NAME}" yq -i \ + '(.images[] | select(.name == strenv(IMAGE_NAME)) | .newTag) = strenv(DEPLOY_TAG)' \ + "${OVERLAY}" + + if git diff --quiet -- "${OVERLAY}"; then + echo "Production already pinned to ${DEPLOY_TAG}; nothing to deploy." + exit 0 + fi + + git config user.name "benchfinity-workbench-ci[bot]" + git config user.email "ci@benchfinity.com" + git add "${OVERLAY}" + git commit -m "deploy(workbench): roll production to ${DEPLOY_TAG}" \ + -m "Auto-bumped by Workbench CI from BenchFinity/Workbench@${SOURCE_SHA}. ArgoCD reconciles." + git push origin "HEAD:${CD_BRANCH}" + echo "Pushed ${DEPLOY_TAG} to ${CD_REPO}@${CD_BRANCH}; ArgoCD will roll it out."