Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit b4856f0

Browse files
committed
Change the way to tag images
Tag the images based on the VERSION file if the file was changed, or as latest if the referenced branch is the main branch. Otherwise just use the commit's hash. Signed-off-by: Charalampos Mainas <[email protected]>
1 parent bd3400b commit b4856f0

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Diff for: .github/workflows/build-trigger.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ on:
44
pull_request:
55
branches: ["main"]
66
push:
7-
branches: ["main", "staging"]
7+
branches: ["main"]
88
workflow_dispatch: # build on demand
9-
#schedule:
10-
# - cron: "43 6 * * 0" # build every Sunday at 6:43 AM UTC
119

1210
concurrency:
1311
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -17,6 +15,8 @@ jobs:
1715
get-changed-files:
1816
runs-on: ubuntu-latest
1917
outputs:
18+
version_files: ${{ steps.filter.outputs.version_files}}
19+
version: ${{ steps.filter.outputs.version }}
2020
dockerfile_files: ${{ steps.filter.outputs.dockerfile_files}}
2121
dockerfile: ${{ steps.filter.outputs.dockerfile }}
2222
go_files: ${{ steps.filter.outputs.go_files}}
@@ -32,6 +32,8 @@ jobs:
3232
list-files: 'json'
3333
base: 'main'
3434
filters: |
35+
version:
36+
- 'VERSION'
3537
dockerfile:
3638
- 'Dockerfile'
3739
go:
@@ -42,17 +44,20 @@ jobs:
4244
- name: Show Changed Files
4345
run: |
4446
echo "Files in dockerfile: ${{ steps.filter.outputs.dockerfile_files }}"
47+
echo "Files for version: ${{ steps.filter.outputs.version_files }}"
4548
echo "Files in go: ${{ steps.filter.outputs.go_files }}"
4649
echo "dockerfile: ${{ steps.filter.outputs.dockerfile}}"
4750
echo "go: ${{ steps.filter.outputs.go}}"
51+
echo "version: ${{ steps.filter.outputs.version}}"
4852
4953
build-pun:
5054
needs: [get-changed-files]
5155
name: Pun
52-
if: ${{ needs.get-changed-files.outputs.go == 'true' || needs.get-changed-files.outputs.dockerfile == 'true' }}
56+
if: ${{ needs.get-changed-files.outputs.go == 'true' || needs.get-changed-files.outputs.dockerfile == 'true' || needs.get-changed-files.outputs.version == 'true' }}
5357
uses: ./.github/workflows/build.yml
5458
secrets: inherit
5559
with:
5660
runner: '["gcc", "dind", "2204"]'
57-
runner-archs: '["amd64", "arm64"]'
61+
runner-archs: '["amd64"]'
5862
dockerfiles: ${{ toJSON(fromJSON(needs.get-changed-files.outputs.dockerfile_files || '[]')) }}
63+
version-tag: ${{ needs.get-changed-files.outputs.version == 'true' }}

Diff for: .github/workflows/build.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ on:
1818
registry:
1919
type: string
2020
default: 'harbor.nbfc.io'
21+
version-tag:
22+
type: boolean
23+
default: false
2124
secrets:
2225
GIT_CLONE_PAT:
2326
required: false
@@ -140,16 +143,15 @@ jobs:
140143
- name: Set Docker tag based on branch or PR
141144
id: tag
142145
run: |
143-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
144-
echo "PR detected. Using branch name: ${{ github.head_ref }}."
145-
#SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
146-
echo "TAG=${{ github.head_ref }}" >> $GITHUB_ENV
146+
if [[ ${{ inputs.version-tag }} == true ]]; then
147+
echo "Version change detected. Using version: $( cat VERSION )."
148+
echo "TAG=$( cat VERSION ) " >> $GITHUB_ENV
147149
elif [[ "${GITHUB_REF##*/}" == "main" ]]; then
148-
echo "TAG=main" >> $GITHUB_ENV
149-
elif [[ "${GITHUB_REF##*/}" == "staging" ]]; then
150-
echo "TAG=staging" >> $GITHUB_ENV
150+
echo "Change in main branch detected. Using latest tag."
151+
echo "TAG=latest" >> $GITHUB_ENV
151152
else
152153
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
154+
echo "Using tag: ${SHORT_SHA}."
153155
echo "TAG=${SHORT_SHA}" >> $GITHUB_ENV
154156
fi
155157

0 commit comments

Comments
 (0)