@@ -13,9 +13,10 @@ concurrency:
1313
1414permissions :
1515 contents : read
16+ actions : read
1617
1718jobs :
18- patch-staging-yaml :
19+ verify-docker-build-ran :
1920 if : >-
2021 ${{
2122 github.event.workflow_run.conclusion == 'success'
@@ -24,25 +25,45 @@ jobs:
2425 || github.event.workflow_run.event == 'release'
2526 )
2627 }}
28+ runs-on : ubuntu-latest
29+ outputs :
30+ image_built : ${{ steps.check.outputs.image_built }}
31+ steps :
32+ - name : Check build-and-push job succeeded
33+ id : check
34+ env :
35+ GH_TOKEN : ${{ github.token }}
36+ run : |
37+ set -euo pipefail
38+ RUN_ID="${{ github.event.workflow_run.id }}"
39+ REPO="${{ github.repository }}"
40+ # Only update staging tags when a new image was built — skip retag-only / changes-only runs.
41+ if gh api "repos/${REPO}/actions/runs/${RUN_ID}/jobs?per_page=100" \
42+ --jq '.jobs[] | select(.name == "build-and-push" and .conclusion == "success") | .name' \
43+ | head -1 | grep -q .; then
44+ echo "image_built=true" >> "$GITHUB_OUTPUT"
45+ echo "Docker build-and-push succeeded; will refresh staging image tags."
46+ else
47+ echo "image_built=false" >> "$GITHUB_OUTPUT"
48+ echo "::notice::Skipping staging tag update: no successful build-and-push job in this workflow run (no new image built)."
49+ fi
50+
51+ patch-staging-yaml :
52+ needs : verify-docker-build-ran
53+ if : needs.verify-docker-build-ran.outputs.image_built == 'true'
2754 strategy :
2855 fail-fast : true
2956 matrix :
3057 include :
3158 - name : api-v3-main-s
3259 staging : environments/main-s.yaml
3360 prod : environments/main.yaml
34- url : https://api-v3-main-s.cfg.embrio.tech
3561 - name : api-v3-test-s
3662 staging : environments/test-s.yaml
3763 prod : environments/test.yaml
38- url : https://api-v3-test-s.cfg.embrio.tech
3964 runs-on : ubuntu-latest
40- environment :
41- name : ${{ matrix.name }}
42- url : ${{ matrix.url }}
4365 permissions :
4466 contents : read
45- deployments : write
4667 steps :
4768 - name : Checkout repository
4869 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
@@ -79,8 +100,10 @@ jobs:
79100 path : ${{ matrix.staging }}
80101
81102 open-staging-pr :
82- needs : patch-staging-yaml
83- if : success()
103+ needs : [verify-docker-build-ran, patch-staging-yaml]
104+ if : >-
105+ needs.verify-docker-build-ran.outputs.image_built == 'true'
106+ && needs.patch-staging-yaml.result == 'success'
84107 runs-on : ubuntu-latest
85108 permissions :
86109 contents : write
0 commit comments