Skip to content

Commit 3793790

Browse files
authored
feat: make GIT_BRANCH and GIT_COMMIT available as build args
1 parent 1507ab5 commit 3793790

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

.github/workflows/build-docker-artifacts.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ jobs:
211211
id: login-ecr
212212
uses: aws-actions/[email protected]
213213

214+
- name: Extract branch and SHA
215+
id: extract-branch
216+
run: |
217+
# Use the recommended GITHUB_HEAD_REF for PRs, fallback to GITHUB_REF for pushes
218+
BRANCH_NAME_RAW="${{ github.head_ref || github.ref_name }}"
219+
# Clean up the ref by removing 'refs/heads/' or 'refs/tags/'
220+
BRANCH_NAME="${BRANCH_NAME_RAW#refs/heads/}"
221+
BRANCH_NAME="${BRANCH_NAME#refs/tags/}"
222+
223+
# A manual input from workflow_dispatch will always override the detected branch name
224+
if [ -n "${{ github.event.inputs.branch }}" ]; then
225+
BRANCH_NAME="${{ github.event.inputs.branch }}"
226+
fi
227+
228+
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
229+
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
230+
214231
- name: Build image
215232
uses: docker/build-push-action@v6
216233
with:
@@ -223,6 +240,8 @@ jobs:
223240
# Disable the cache to avoid outdated (base) images
224241
no-cache: true
225242
build-args: |
243+
GIT_BRANCH=${{ steps.extract-branch.outputs.branch }}
244+
GIT_COMMIT=${{ steps.extract-branch.outputs.commit }}
226245
DOCKERFILE_DIRECTORY=${{ matrix.component.flavor_directory }}/${{ matrix.component.directory }}
227246
PYTHON_BASE_IMAGE=${{ env.PYTHON_BASE_IMAGE }}
228247
DATAVISYN_PYTHON_BASE_IMAGE=${{ env.DATAVISYN_PYTHON_BASE_IMAGE }}

0 commit comments

Comments
 (0)