Skip to content

Commit 1b696d0

Browse files
committed
Outputs on containers-to-build
Remove duplicate fetch tag metadata Build Docker Images has an id for repository_path Set output for docker_compose_dir
1 parent 7d5f0e5 commit 1b696d0

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

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

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ 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 }}
50+
docker_compose_dir: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
4851
steps:
4952
- uses: actions/checkout@v4
5053
with:
@@ -104,9 +107,6 @@ jobs:
104107
fail-fast: false
105108
matrix:
106109
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 }}
110110
steps:
111111
- uses: actions/checkout@v4
112112
with:
@@ -120,35 +120,20 @@ jobs:
120120
path: templates
121121
ref: fix/function-app-acr-is-optional
122122

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-
141123
- name: Build Docker image
142-
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
124+
id: docker_image
125+
working-directory: ${{ needs.containers-to-build.outputs.docker_compose_dir }}
143126
continue-on-error: false
144127
env:
145128
IMAGE_NAME: ${{ inputs.project_name }}-${{ matrix.function }}
146-
PR_NUM_TAG: ${{ steps.tags.outputs.pr_num_tag }}
147-
REPO_PATH: ${{ steps.tags.outputs.registry_repository_path }}
129+
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
130+
REGISTRY: ${{ env.USE_AZURECR == 'true' && format('{0}.azurecr.io', secrets.ACR_NAME) || format('ghcr.io/{0}', github.repository_owner) }}
148131
run: |
132+
echo "repository_path=${REGISTRY,,}/${IMAGE_NAME}" >> "${GITHUB_OUTPUT}"
133+
149134
docker compose -f ${COMPOSE_FILE//,/ -f } -p ${PROJECT_NAME} build --no-cache --pull ${{ matrix.function }}
150135
docker tag ${IMAGE_NAME}:latest "${REPO_PATH}:${PR_NUM_TAG}"
151-
[[ -n "${ENVIRONMENT_TAG}" ]] && docker tag "${IMAGE_NAME}:latest "${REPO_PATH}:${ENVIRONMENT_TAG}"
136+
[[ -n "${ENVIRONMENT_TAG}" ]] && docker tag "${IMAGE_NAME}:latest "$${ENVIRONMENT_TAG}"
152137
153138
- name: AzureCLI login
154139
if: github.ref == 'refs/heads/main' && env.USE_AZURECR == 'true'
@@ -168,11 +153,11 @@ jobs:
168153

169154
- name: Push Docker image
170155
if: github.ref == 'refs/heads/main' || env.IS_TEST_DEPLOY == 'true'
171-
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
156+
working-directory: ${{ needs.containers-to-build.outputs.docker_compose_dir }}
172157
continue-on-error: false
173158
env:
174-
PR_NUM_TAG: ${{ steps.tags.outputs.pr_num_tag }}
175-
REPO_PATH: ${{ steps.tags.outputs.registry_repository_path }}
159+
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
160+
REPO_PATH: ${{ steps.docker_image.outputs.repository_path }}
176161
run: |
177162
[[ "${USE_AZURECR}" == "true" ]] && az acr login --name "${ACR_NAME}"
178163
[[ -n "${ENVIRONMENT_TAG}" ]] && docker push "${REPO_PATH}:${ENVIRONMENT_TAG}"
@@ -194,10 +179,10 @@ jobs:
194179
name: Add merge commit tag to all images
195180
if: github.ref == 'refs/heads/main'
196181
runs-on: ubuntu-latest
197-
needs: build-and-push
182+
needs: [build-and-push, containers-to-build]
198183
env:
199-
PR_NUM_TAG: ${{ needs.build-and-push.outputs.pr_num_tag }}
200-
SHORT_COMMIT_HASH: ${{ needs.build-and-push.outputs.short_commit_hash }}
184+
PR_NUM_TAG: ${{ needs.containers-to-build.outputs.pr_num_tag }}
185+
SHORT_COMMIT_HASH: ${{ needs.containers-to-build.outputs.short_commit_hash }}
201186
permissions:
202187
id-token: write
203188
packages: write
@@ -271,10 +256,10 @@ jobs:
271256
- name: Get all artifacts
272257
uses: actions/download-artifact@v4
273258
with:
274-
path: reports-${{ needs.build-and-push.outputs.pr_num_tag }}
259+
path: reports-${{ needs.containers-to-build.outputs.pr_num_tag }}
275260

276261
- name: Aggregate reports
277262
uses: actions/upload-artifact@v4
278263
with:
279-
name: aggregated-reports-${{ needs.build-and-push.outputs.pr_num_tag }}
280-
path: reports-${{ needs.build-and-push.outputs.pr_num_tag }}
264+
name: aggregated-reports-${{ needs.containers-to-build.outputs.pr_num_tag }}
265+
path: reports-${{ needs.containers-to-build.outputs.pr_num_tag }}

0 commit comments

Comments
 (0)