Skip to content

Commit 8bb1355

Browse files
committed
Avoid duplicate workflows during releases
1 parent 620a417 commit 8bb1355

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

.github/actions/docker-meta/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
event_name:
2121
required: true
2222
description: 'GitHub event name'
23+
release_version:
24+
required: false
25+
default: ""
26+
description: 'Version extracted from a standardized release commit subject'
2327

2428
outputs:
2529
tags:
@@ -45,8 +49,8 @@ runs:
4549
images: ${{ inputs.image }}
4650
context: ${{ inputs.trunk_only_event == 'true' && 'git' || '' }}
4751
tags: |
48-
type=semver,enable=${{ inputs.current_branch != 'trunk' }},pattern={{version}},prefix=${{ inputs.os }}-
49-
type=semver,enable=${{ inputs.current_branch != 'trunk' }},pattern={{version}},suffix=-${{ inputs.os }}
52+
type=semver,enable=${{ inputs.release_version != '' }},value=${{ inputs.release_version }},pattern={{version}},prefix=${{ inputs.os }}-
53+
type=semver,enable=${{ inputs.release_version != '' }},value=${{ inputs.release_version }},pattern={{version}},suffix=-${{ inputs.os }}
5054
type=ref,enable=${{ inputs.current_branch != 'trunk' && inputs.event_name != 'workflow_dispatch' }},event=branch,prefix=${{ inputs.os }}-,suffix=-latest
5155
type=ref,enable=${{ inputs.current_branch != 'trunk' && inputs.event_name != 'workflow_dispatch' }},event=branch,suffix=-${{ inputs.os }}-latest
5256
type=raw,enable=${{ inputs.current_branch != 'trunk' && inputs.is_default_branch == 'true' }},value=${{ inputs.os }}-latest

.github/actions/get-branch-info/action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ outputs:
2424
sha_short:
2525
description: Short Git commit SHA
2626
value: ${{ steps.branch_info.outputs.sha_short }}
27+
release_version:
28+
description: Version extracted from a standardized release commit subject
29+
value: ${{ steps.branch_info.outputs.release_version }}
2730

2831
runs:
2932
using: composite
@@ -58,11 +61,19 @@ runs:
5861
5962
current_branch="${ref##*/}"
6063
is_default_branch=false
64+
release_version=""
6165
6266
if [[ "$current_branch" == "$DEFAULT_BRANCH" ]]; then
6367
is_default_branch=true
6468
fi
6569
70+
commit_subject="$(git log -1 --pretty=%s)"
71+
72+
if [[ "$GITHUB_EVENT_NAME" == "push" &&
73+
"$commit_subject" =~ ^Zabbix\ v([0-9]+\.[0-9]+\.[0-9]+)\ release$ ]]; then
74+
release_version="${BASH_REMATCH[1]}"
75+
fi
76+
6677
if [[ "${current_branch//.}" == "trunk" && -n "$TRUNK_MAJOR_VERSION" ]]; then
6778
secret_prefix="RHEL_${TRUNK_MAJOR_VERSION//.}"
6879
else
@@ -76,11 +87,13 @@ runs:
7687
echo "current_branch=$current_branch"
7788
echo "secret_prefix=$secret_prefix"
7889
echo "sha_short=$sha_short"
90+
echo "release_version=$release_version"
7991
echo "::endgroup::"
8092
8193
{
8294
echo "is_default_branch=$is_default_branch"
8395
echo "current_branch=$current_branch"
8496
echo "secret_prefix=$secret_prefix"
8597
echo "sha_short=$sha_short"
98+
echo "release_version=$release_version"
8699
} >> "$GITHUB_OUTPUT"

.github/workflows/images_build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Build images (DockerHub)
22

33
on:
4-
release:
5-
types:
6-
- published
74
push:
85
branches:
96
- '[0-9]+.[0-9]+'
@@ -65,6 +62,7 @@ jobs:
6562
is_default_branch: ${{ steps.branch_info.outputs.is_default_branch }}
6663
current_branch: ${{ steps.branch_info.outputs.current_branch }}
6764
sha_short: ${{ steps.branch_info.outputs.sha_short }}
65+
release_version: ${{ steps.branch_info.outputs.release_version }}
6866

6967
steps:
7068
- name: Block egress traffic
@@ -295,6 +293,7 @@ jobs:
295293
is_default_branch: ${{ needs.init_build.outputs.is_default_branch }}
296294
trunk_only_event: ${{ env.TRUNK_ONLY_EVENT }}
297295
event_name: ${{ github.event_name }}
296+
release_version: ${{ needs.init_build.outputs.release_version }}
298297

299298
- name: Set up Docker tooling
300299
uses: ./.github/actions/docker-linux-setup
@@ -446,6 +445,7 @@ jobs:
446445
is_default_branch: ${{ needs.init_build.outputs.is_default_branch }}
447446
trunk_only_event: ${{ env.TRUNK_ONLY_EVENT }}
448447
event_name: ${{ github.event_name }}
448+
release_version: ${{ needs.init_build.outputs.release_version }}
449449

450450
- name: Download artifact metadata of ${{ env.BASE_BUILD_NAME }}:${{ matrix.os }}
451451
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -748,6 +748,7 @@ jobs:
748748
is_default_branch: ${{ needs.init_build.outputs.is_default_branch }}
749749
trunk_only_event: ${{ env.TRUNK_ONLY_EVENT }}
750750
event_name: ${{ github.event_name }}
751+
release_version: ${{ needs.init_build.outputs.release_version }}
751752

752753
- name: Download artifact metadata of ${{ steps.build_base_image.outputs.build_base }}:${{ matrix.os }}
753754
if: ${{ matrix.build != 'snmptraps' }}

.github/workflows/images_build_windows.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Build images (DockerHub, Windows)
22

33
on:
4-
release:
5-
types:
6-
- published
74
push:
85
branches:
96
- '[0-9]+.[0-9]+'
@@ -70,6 +67,7 @@ jobs:
7067
is_default_branch: ${{ steps.branch_info.outputs.is_default_branch }}
7168
current_branch: ${{ steps.branch_info.outputs.current_branch }}
7269
sha_short: ${{ steps.branch_info.outputs.sha_short }}
70+
release_version: ${{ steps.branch_info.outputs.release_version }}
7371
steps:
7472
- name: Block egress traffic
7573
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
@@ -311,8 +309,8 @@ jobs:
311309
images: ${{ format('{0}/{1}/{2}{3}', env.DOCKER_REGISTRY, env.DOCKER_REPOSITORY, env.IMAGES_PREFIX, env.BASE_IMAGE_NAME ) }}
312310
context: ${{ env.TRUNK_ONLY_EVENT == 'true' && 'git' || '' }}
313311
tags: |
314-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-
315-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }},prefix=${{ matrix.component }}-
312+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-
313+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }},prefix=${{ matrix.component }}-
316314
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-,suffix=-latest
317315
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,suffix=-${{ steps.base_os_tag.outputs.os_tag }}-latest,prefix=${{ matrix.component }}-
318316
type=raw,enable=${{ needs.init_build.outputs.current_branch != 'trunk' && needs.init_build.outputs.is_default_branch == 'true' }},value=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-latest
@@ -467,8 +465,8 @@ jobs:
467465
images: ${{ format('{0}/{1}/{2}{3}', env.DOCKER_REGISTRY, env.DOCKER_REPOSITORY, env.IMAGES_PREFIX, env.BASE_BUILD_IMAGE_NAME ) }}
468466
context: ${{ env.TRUNK_ONLY_EVENT == 'true' && 'git' || '' }}
469467
tags: |
470-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-
471-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }},prefix=${{ matrix.component }}-
468+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-
469+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }},prefix=${{ matrix.component }}-
472470
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,prefix=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-,suffix=-latest
473471
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,suffix=-${{ steps.base_os_tag.outputs.os_tag }}-latest,prefix=${{ matrix.component }}-
474472
type=raw,enable=${{ (needs.init_build.outputs.current_branch != 'trunk') && (needs.init_build.outputs.is_default_branch == 'true') }},value=${{ matrix.component }}-${{ steps.base_os_tag.outputs.os_tag }}-latest
@@ -655,8 +653,8 @@ jobs:
655653
images: ${{ format('{0}/{1}/{2}{3}', env.DOCKER_REGISTRY, env.DOCKER_REPOSITORY, env.IMAGES_PREFIX, matrix.component ) }}
656654
context: ${{ env.TRUNK_ONLY_EVENT == 'true' && 'git' || '' }}
657655
tags: |
658-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},prefix=${{ steps.base_os_tag.outputs.os_tag }}-
659-
type=semver,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }}
656+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},prefix=${{ steps.base_os_tag.outputs.os_tag }}-
657+
type=semver,enable=${{ needs.init_build.outputs.release_version != '' }},value=${{ needs.init_build.outputs.release_version }},pattern={{version}},suffix=-${{ steps.base_os_tag.outputs.os_tag }}
660658
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,prefix=${{ steps.base_os_tag.outputs.os_tag }}-,suffix=-latest
661659
type=ref,enable=${{ needs.init_build.outputs.current_branch != 'trunk' }},event=branch,suffix=-${{ steps.base_os_tag.outputs.os_tag }}-latest
662660
type=raw,enable=${{ (needs.init_build.outputs.current_branch != 'trunk') && (needs.init_build.outputs.is_default_branch == 'true') }},value=${{ steps.base_os_tag.outputs.os_tag }}-latest

0 commit comments

Comments
 (0)