4444 id-token : write
4545 outputs :
4646 containers : ${{ steps.get-function-names.outputs.FUNC_NAMES }}
47- pr_num_tag : ${{ steps.tags.outputs.pr_num_tag }}
48- short_commit_hash : ${{ steps.tags.outputs.short_commit_hash }}
4947 steps :
5048 - uses : actions/checkout@v4
5149 with :
6866 SOURCE_CODE_PATH : ${{ inputs.function_app_source_code_path }}
6967 run : bash ./templates/scripts/deployments/get-docker-names.sh
7068
71- - name : Fetch tag metadata
72- id : tags
73- env :
74- GH_TOKEN : ${{ github.token }}
75- run : |
76- PR_NUMBER="${{ github.event.pull_request.number }}"
77- if [ -z "$PR_NUMBER" ]; then
78- echo "Looking up PR number for commit: $GITHUB_SHA"
79- PR_NUMBER=$(gh pr list --state open --search "$GITHUB_SHA" --json number -q '.[0].number' 2>/dev/null || true)
80- fi
81-
82- if [ -z "$PR_NUMBER" ]; then
83- PR_NUMBER=$(gh pr list --state merged --search "$GITHUB_SHA" --json number -q '.[0].number' 2>/dev/null || true)
84- fi
85-
86- echo "Resolved PR number: $PR_NUMBER"
87- echo "pr_num_tag=$PR_NUMBER" >> "$GITHUB_OUTPUT"
88-
89- set -x
90- [[ "${GITHUB_REF}" == "refs/heads/main" ]] && PR_NUMBER=$(gh api repos/{owner}/{repo}/commits/${GITHUB_SHA}/pulls --jq 'sort_by(.updated_at) | reverse | .[0].number')
91- echo "pr_num_tag=pr${PR_NUMBER}" >> "${GITHUB_OUTPUT}"
92- echo "short_commit_hash=$(git rev-parse --short ${GITHUB_SHA})" >> "${GITHUB_OUTPUT}"
93-
9469 build-and-push :
9570 if : needs.containers-to-build.outputs.containers != '[]'
9671 runs-on : ubuntu-latest
10479 fail-fast : false
10580 matrix :
10681 function : ${{ fromJSON(needs.containers-to-build.outputs.containers) }}
82+ outputs :
83+ pr_num_tag : ${{ steps.tags.outputs.pr_num_tag }}
84+ short_commit_hash : ${{ steps.tags.outputs.short_commit_hash }}
10785 steps :
10886 - uses : actions/checkout@v4
10987 with :
@@ -117,19 +95,34 @@ jobs:
11795 path : templates
11896 ref : fix/function-app-acr-is-optional
11997
98+ - name : Fetch tag metadata
99+ id : tags
100+ env :
101+ GH_TOKEN : ${{ github.token }}
102+ REGISTRY : ${{ env.USE_AZURECR == 'true' && format('{0}.azurecr.io', secrets.ACR_NAME) || format('ghcr.io/{0}', github.repository_owner) }}
103+ run : |
104+ set -x
105+ if [[ "${GITHUB_REF}" == refs/pull/*/merge ]]; then
106+ pr_number=$(echo "${GITHUB_REF}" | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
107+ else
108+ pr_number=$(gh api repos/{owner}/{repo}/commits/${GITHUB_SHA}/pulls --jq 'sort_by(.updated_at) | reverse | .[0].number')
109+ fi
110+ {
111+ echo "pr_num_tag=pr${pr_number}"
112+ echo "short_commit_hash=$(git rev-parse --short ${GITHUB_SHA})"
113+ echo "registry_repository_path=${REGISTRY,,}/${PROJECT_NAME,,}-${{ matrix.function }}"
114+ } >> "${GITHUB_OUTPUT}"
115+
120116 - name : Build Docker image
121- id : build
122117 working-directory : ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
123118 continue-on-error : false
124119 env :
125120 IMAGE_NAME : ${{ inputs.project_name }}-${{ matrix.function }}
126- PR_NUM_TAG : ${{ needs.containers-to-build .outputs.pr_num_tag }}
127- REGISTRY : ${{ env.USE_AZURECR == 'true' && format('{0}.azurecr.io', secrets.ACR_NAME) || format('ghcr.io/{0}', github.repository_owner) }}
121+ PR_NUM_TAG : ${{ steps.tags .outputs.pr_num_tag }}
122+ REPO_PATH : ${{ steps.tags.outputs.registry_repository_path }}
128123 run : |
129- repo_path="${REGISTRY,,}/${PROJECT_NAME,,}-${{ matrix.function }}"
130- echo "registry_repository_path=${repo_path}" >> "${GITHUB_OUTPUT}"
131124 docker compose -f ${COMPOSE_FILE//,/ -f } -p ${PROJECT_NAME} build --no-cache --pull ${{ matrix.function }}
132- docker tag ${IMAGE_NAME}:latest "${repo_path }:${PR_NUM_TAG}"
125+ docker tag ${IMAGE_NAME}:latest "${REPO_PATH }:${PR_NUM_TAG}"
133126
134127 - name : AzureCLI login
135128 if : github.ref == 'refs/heads/main' && env.USE_AZURECR == 'true'
@@ -152,8 +145,8 @@ jobs:
152145 working-directory : ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
153146 continue-on-error : false
154147 env :
155- PR_NUM_TAG : ${{ needs.containers-to-build .outputs.pr_num_tag }}
156- REPO_PATH : ${{ steps.build .outputs.registry_repository_path }}
148+ PR_NUM_TAG : ${{ steps.tags .outputs.pr_num_tag }}
149+ REPO_PATH : ${{ steps.tags .outputs.registry_repository_path }}
157150 run : |
158151 [[ "${USE_AZURECR}" == "true" ]] && az acr login --name "${ACR_NAME}"
159152 [[ -n "${ENVIRONMENT_TAG}" ]] && docker push "${REPO_PATH}:${ENVIRONMENT_TAG}"
@@ -177,8 +170,8 @@ jobs:
177170 runs-on : ubuntu-latest
178171 needs : build-and-push
179172 env :
180- PR_NUM_TAG : ${{ needs.containers-to-build .outputs.pr_num_tag }}
181- SHORT_COMMIT_HASH : ${{ needs.containers-to-build .outputs.short_commit_hash }}
173+ PR_NUM_TAG : ${{ needs.build-and-push .outputs.pr_num_tag }}
174+ SHORT_COMMIT_HASH : ${{ needs.build-and-push .outputs.short_commit_hash }}
182175 permissions :
183176 id-token : write
184177 packages : write
@@ -252,10 +245,10 @@ jobs:
252245 - name : Get all artifacts
253246 uses : actions/download-artifact@v4
254247 with :
255- path : reports-${{ env.PR_NUM_TAG }}
248+ path : reports-${{ needs.build-and-push.outputs.pr_num_tag }}
256249
257250 - name : Aggregate reports
258251 uses : actions/upload-artifact@v4
259252 with :
260- name : aggregated-reports-${{ env.PR_NUM_TAG }}
261- path : reports-${{ env.PR_NUM_TAG }}
253+ name : aggregated-reports-${{ needs.build-and-push.outputs.pr_num_tag }}
254+ path : reports-${{ needs.build-and-push.outputs.pr_num_tag }}
0 commit comments