Skip to content

Commit c388b4b

Browse files
committed
Merge changes
Work on PR number
2 parents 3fee07a + fa1ae65 commit c388b4b

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

.github/workflows/stage-3-build.yaml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ jobs:
4545
id-token: write
4646
outputs:
4747
containers: ${{ steps.get-function-names.outputs.FUNC_NAMES }}
48-
pr_num_tag: ${{ steps.tags.outputs.pr_num_tag }}
49-
short_commit_hash: ${{ steps.tags.outputs.short_commit_hash }}
5048
steps:
5149
- uses: actions/checkout@v4
5250
with:
@@ -106,6 +104,9 @@ jobs:
106104
fail-fast: false
107105
matrix:
108106
function: ${{ fromJSON(needs.containers-to-build.outputs.containers) }}
107+
outputs:
108+
pr_num_tag: ${{ steps.tags.outputs.pr_num_tag }}
109+
short_commit_hash: ${{ steps.tags.outputs.short_commit_hash }}
109110
steps:
110111
- uses: actions/checkout@v4
111112
with:
@@ -119,19 +120,34 @@ jobs:
119120
path: templates
120121
ref: fix/function-app-acr-is-optional
121122

123+
- name: Fetch tag metadata
124+
id: tags
125+
env:
126+
GH_TOKEN: ${{ github.token }}
127+
REGISTRY: ${{ env.USE_AZURECR == 'true' && format('{0}.azurecr.io', secrets.ACR_NAME) || format('ghcr.io/{0}', github.repository_owner) }}
128+
run: |
129+
set -x
130+
if [[ "${GITHUB_REF}" == refs/pull/*/merge ]]; then
131+
pr_number=$(echo "${GITHUB_REF}" | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
132+
else
133+
pr_number=$(gh api repos/{owner}/{repo}/commits/${GITHUB_SHA}/pulls --jq 'sort_by(.updated_at) | reverse | .[0].number')
134+
fi
135+
{
136+
echo "pr_num_tag=pr${pr_number}"
137+
echo "short_commit_hash=$(git rev-parse --short ${GITHUB_SHA})"
138+
echo "registry_repository_path=${REGISTRY,,}/${PROJECT_NAME,,}-${{ matrix.function }}"
139+
} >> "${GITHUB_OUTPUT}"
140+
122141
- name: Build Docker image
123-
id: build
124142
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
125143
continue-on-error: false
126144
env:
127145
IMAGE_NAME: ${{ inputs.project_name }}-${{ matrix.function }}
128-
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
129-
REGISTRY: ${{ env.USE_AZURECR == 'true' && format('{0}.azurecr.io', secrets.ACR_NAME) || format('ghcr.io/{0}', github.repository_owner) }}
146+
PR_NUM_TAG: ${{ steps.tags.outputs.pr_num_tag }}
147+
REPO_PATH: ${{ steps.tags.outputs.registry_repository_path }}
130148
run: |
131-
repo_path="${REGISTRY,,}/${PROJECT_NAME,,}-${{ matrix.function }}"
132-
echo "registry_repository_path=${repo_path}" >> "${GITHUB_OUTPUT}"
133149
docker compose -f ${COMPOSE_FILE//,/ -f } -p ${PROJECT_NAME} build --no-cache --pull ${{ matrix.function }}
134-
docker tag ${IMAGE_NAME}:latest "${repo_path}:${PR_NUM_TAG}"
150+
docker tag ${IMAGE_NAME}:latest "${REPO_PATH}:${PR_NUM_TAG}"
135151
136152
- name: AzureCLI login
137153
if: github.ref == 'refs/heads/main' && env.USE_AZURECR == 'true'
@@ -154,8 +170,8 @@ jobs:
154170
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
155171
continue-on-error: false
156172
env:
157-
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
158-
REPO_PATH: ${{ steps.build.outputs.registry_repository_path }}
173+
PR_NUM_TAG: ${{ steps.tags.outputs.pr_num_tag }}
174+
REPO_PATH: ${{ steps.tags.outputs.registry_repository_path }}
159175
run: |
160176
[[ "${USE_AZURECR}" == "true" ]] && az acr login --name "${ACR_NAME}"
161177
[[ -n "${ENVIRONMENT_TAG}" ]] && docker push "${REPO_PATH}:${ENVIRONMENT_TAG}"
@@ -179,8 +195,8 @@ jobs:
179195
runs-on: ubuntu-latest
180196
needs: build-and-push
181197
env:
182-
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
183-
SHORT_COMMIT_HASH: ${{ needs.containers-to-build.outputs.short_commit_hash }}
198+
PR_NUM_TAG: ${{ needs.build-and-push.outputs.pr_num_tag }}
199+
SHORT_COMMIT_HASH: ${{ needs.build-and-push.outputs.short_commit_hash }}
184200
permissions:
185201
id-token: write
186202
packages: write
@@ -254,10 +270,10 @@ jobs:
254270
- name: Get all artifacts
255271
uses: actions/download-artifact@v4
256272
with:
257-
path: reports-${{ env.PR_NUM_TAG }}
273+
path: reports-${{ needs.build-and-push.outputs.pr_num_tag }}
258274

259275
- name: Aggregate reports
260276
uses: actions/upload-artifact@v4
261277
with:
262-
name: aggregated-reports-${{ env.PR_NUM_TAG }}
263-
path: reports-${{ env.PR_NUM_TAG }}
278+
name: aggregated-reports-${{ needs.build-and-push.outputs.pr_num_tag }}
279+
path: reports-${{ needs.build-and-push.outputs.pr_num_tag }}

0 commit comments

Comments
 (0)