fix(ci): skip outdated production deploys

This commit is contained in:
Víctor Falcón 2026-03-17 12:19:26 +01:00
parent c53106289d
commit b36197e76b
1 changed files with 33 additions and 0 deletions

View File

@ -271,8 +271,37 @@ jobs:
runs-on: ubuntu-latest
needs: [tests, linter, static-analysis, performance-tests]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
concurrency:
group: production-deploy-main
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if this is the latest main commit
id: deploy_guard
run: |
latest_main_sha=$(git ls-remote origin refs/heads/main | cut -f1)
echo "Current workflow SHA: ${{ github.sha }}"
echo "Latest main SHA: $latest_main_sha"
if [ -z "$latest_main_sha" ]; then
echo "Unable to determine the latest main SHA."
exit 1
fi
if [ "$latest_main_sha" != "${{ github.sha }}" ]; then
echo "This workflow is not for the latest commit on main. Skipping deploy."
echo "should_deploy=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "This workflow is for the latest commit on main. Proceeding with deploy."
echo "should_deploy=true" >> "$GITHUB_OUTPUT"
- name: Trigger deployment
if: steps.deploy_guard.outputs.should_deploy == 'true'
run: |
max_attempts=5
attempt=1
@ -310,3 +339,7 @@ jobs:
echo "All $max_attempts attempts failed. Giving up."
exit 1
- name: Deployment skipped
if: steps.deploy_guard.outputs.should_deploy == 'false'
run: echo "Skipped deployment because a newer commit is already on main."