Skip to content

Commit 7a46fa2

Browse files
authored
Make actual action for it
1 parent 33b1d03 commit 7a46fa2

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: get-branch
2+
description: extracts the branch in readable form
3+
author: datavisyn
4+
5+
inputs:
6+
branch:
7+
description: "branch override"
8+
required: false
9+
10+
outputs:
11+
branch:
12+
description: "extracted branch"
13+
value: ${{ steps.get-branch.outputs.branch }}
14+
commit:
15+
description: "extracted commit hash"
16+
value: ${{ steps.get-branch.outputs.commit }}
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Extract branch and commit
22+
shell: bash
23+
id: get-branch
24+
run: |
25+
# Use HEAD_REF for PRs, fallback to REF_NAME for pushes.
26+
BRANCH_NAME_RAW="${HEAD_REF:-$REF_NAME}"
27+
# Clean up the ref by removing 'refs/heads/' or 'refs/tags/'
28+
BRANCH_NAME="${BRANCH_NAME_RAW#refs/heads/}"
29+
BRANCH_NAME="${BRANCH_NAME#refs/tags/}"
30+
31+
# A manual input from workflow_dispatch will always override the detected branch name
32+
if [ -n "${MANUAL_BRANCH}" ]; then
33+
BRANCH_NAME="${MANUAL_BRANCH}"
34+
fi
35+
36+
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
37+
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
38+
env:
39+
HEAD_REF: ${{ github.head_ref }}
40+
REF_NAME: ${{ github.ref_name }}
41+
MANUAL_BRANCH: ${{ inputs.branch }}

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ concurrency:
4545
cancel-in-progress: true
4646

4747
env:
48-
WORKFLOW_BRANCH: "main"
48+
WORKFLOW_BRANCH: "mp/docker_branch"
4949
PYTHON_BASE_IMAGE: "python:3.10.18-slim-bullseye"
5050
DATAVISYN_PYTHON_BASE_IMAGE: "188237246440.dkr.ecr.eu-central-1.amazonaws.com/datavisyn/base/python:main"
5151
NODE_BASE_IMAGE: "node:20.9-bullseye"
@@ -211,26 +211,10 @@ 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 HEAD_REF for PRs, fallback to REF_NAME for pushes.
218-
BRANCH_NAME_RAW="${HEAD_REF:-$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 "${MANUAL_BRANCH}" ]; then
225-
BRANCH_NAME="${MANUAL_BRANCH}"
226-
fi
227-
228-
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
229-
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
230-
env:
231-
HEAD_REF: ${{ github.head_ref }}
232-
REF_NAME: ${{ github.ref_name }}
233-
MANUAL_BRANCH: ${{ inputs.branch }}
214+
- uses: ./tmp/github-workflows/.github/actions/get-branch
215+
id: get-branch
216+
with:
217+
branch: ${{ inputs.branch }}
234218

235219
- name: Build image
236220
uses: docker/build-push-action@v6
@@ -244,8 +228,8 @@ jobs:
244228
# Disable the cache to avoid outdated (base) images
245229
no-cache: true
246230
build-args: |
247-
GIT_BRANCH=${{ steps.extract-branch.outputs.branch }}
248-
GIT_COMMIT=${{ steps.extract-branch.outputs.commit }}
231+
GIT_BRANCH=${{ steps.get-branch.outputs.branch }}
232+
GIT_COMMIT=${{ steps.get-branch.outputs.commit }}
249233
DOCKERFILE_DIRECTORY=${{ matrix.component.flavor_directory }}/${{ matrix.component.directory }}
250234
PYTHON_BASE_IMAGE=${{ env.PYTHON_BASE_IMAGE }}
251235
DATAVISYN_PYTHON_BASE_IMAGE=${{ env.DATAVISYN_PYTHON_BASE_IMAGE }}

0 commit comments

Comments
 (0)