Skip to content

Commit efb57ff

Browse files
kgwizdz-splunkawownysz-splunk
authored andcommitted
feat: add publish for custom version
1 parent e3a7bc1 commit efb57ff

File tree

1 file changed

+80
-15
lines changed

1 file changed

+80
-15
lines changed

.github/workflows/reusable-build-test-release.yml

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ on:
1414
type: string
1515
default: >-
1616
[""]
17+
custom-version:
18+
required: false
19+
description: 'Version of release in the form of "x.x.x" string, specified by user instead of automatically generated semantic release'
20+
type: string
21+
default: ""
22+
execute-tests-on-push-to-develop:
23+
required: false
24+
description: 'Flag to run all tests on push to develop branch'
25+
type: string
26+
default: 'false'
27+
execute-tests-on-push-to-release:
28+
required: false
29+
description: 'Flag to run all tests on push to release branch'
30+
type: string
31+
default: 'false'
1732
k8s-environment:
1833
required: false
1934
description: Specifies which environment to use for k8s testing. ["production", "staging"]
@@ -77,6 +92,24 @@ concurrency:
7792
group: ${{ github.head_ref || github.run_id }}
7893
cancel-in-progress: true
7994
jobs:
95+
validate-custom-version:
96+
runs-on: ubuntu-latest
97+
if: ${{ github.event.inputs.custom-version != '' }}
98+
steps:
99+
- uses: actions/checkout@v4
100+
- name: Validate custom version
101+
run: |
102+
if [[ ! ${{ github.event.inputs.custom-version }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
103+
echo "Invalid custom version provided. Please provide a valid semver version."
104+
exit 1
105+
fi
106+
107+
git fetch --tags
108+
if [ "$(git tag -l 'v${{ github.event.inputs.custom-version }}')" ]; then
109+
echo "The provided version already exists. Please provide a unique version."
110+
exit 1
111+
fi
112+
80113
setup-workflow:
81114
runs-on: ubuntu-latest
82115
outputs:
@@ -140,7 +173,10 @@ jobs:
140173
fi
141174
;;
142175
"push")
143-
if ${{ github.ref_name == 'main' }} || ${{ github.ref_name == 'develop' }} || ${{ github.ref_type == 'tag' }} ; then
176+
if ${{ github.ref_name == 'main' }} ||
177+
${{ github.ref_name == 'develop' && inputs.execute-tests-on-push-to-develop == 'true' }} ||
178+
${{ startsWith(github.ref_name, 'release/') && inputs.execute-tests-on-push-to-release == 'true' }} ||
179+
${{ github.ref_type == 'tag' }} ; then
144180
for test_type in "${TESTSET[@]}"; do
145181
EXECUTE_LABELED["$test_type"]="true"
146182
done
@@ -151,6 +187,13 @@ jobs:
151187
EXECUTE_LABELED["$test_type"]="true"
152188
done
153189
;;
190+
"workflow_dispatch")
191+
if ${{ inputs.custom-version != '' }} ; then
192+
for test_type in "${TESTSET[@]}"; do
193+
EXECUTE_LABELED["$test_type"]="true"
194+
done
195+
fi
196+
;;
154197
*)
155198
echo "No tests were labeled for execution!"
156199
;;
@@ -415,6 +458,7 @@ jobs:
415458
build:
416459
runs-on: ubuntu-latest
417460
needs:
461+
- validate-custom-version
418462
- setup-workflow
419463
- test-inventory
420464
- meta
@@ -424,7 +468,7 @@ jobs:
424468
- semgrep
425469
- run-unit-tests
426470
- fossa-scan
427-
if: ${{ !cancelled() && (needs.run-unit-tests.result == 'success' || needs.run-unit-tests.result == 'skipped') }}
471+
if: ${{ !cancelled() && (needs.run-unit-tests.result == 'success' || needs.run-unit-tests.result == 'skipped') && (needs.validate-custom-version.result == 'success' || needs.validate-custom-version.result == 'skipped') }}
428472
outputs:
429473
buildname: ${{ steps.buildupload.outputs.name }}
430474
permissions:
@@ -495,7 +539,7 @@ jobs:
495539
- name: Determine the version to build
496540
id: BuildVersion
497541
run: |
498-
INPUT_SEMVER="${{ steps.semantic.outputs.new_release_version }}"
542+
INPUT_SEMVER="${{ github.event.inputs.custom-version != '' && github.event.inputs.custom-version || steps.semantic.outputs.new_release_version }}"
499543
echo "Initial semver ${INPUT_SEMVER}"
500544
INPUT_PRNUMBER="${{ github.event.number }}"
501545
SEMVER_REGEX='^v?[0-9]+\.[0-9]+\.[0-9]+$'
@@ -602,6 +646,7 @@ jobs:
602646
build-3_9:
603647
runs-on: ubuntu-latest
604648
needs:
649+
- validate-custom-version
605650
- setup-workflow
606651
- test-inventory
607652
- meta
@@ -613,7 +658,8 @@ jobs:
613658
- fossa-scan
614659
if: |
615660
always() &&
616-
(needs.run-unit-tests-3_9.result == 'success' || needs.run-unit-tests-3_9.result == 'skipped')
661+
(needs.run-unit-tests-3_9.result == 'success' || needs.run-unit-tests-3_9.result == 'skipped') &&
662+
(needs.validate-custom-version.result == 'success' || needs.validate-custom-version.result == 'skipped')
617663
permissions:
618664
contents: write
619665
packages: read
@@ -673,7 +719,7 @@ jobs:
673719
GITHUB_TOKEN: ${{ github.token }}
674720
- id: BuildVersion
675721
run: |
676-
INPUT_SEMVER="${{ steps.semantic.outputs.new_release_version }}"
722+
INPUT_SEMVER="${{ github.event.inputs.custom-version != '' && github.event.inputs.custom-version || steps.semantic.outputs.new_release_version }}"
677723
echo "Initial semver ${INPUT_SEMVER}"
678724
INPUT_PRNUMBER="${{ github.event.number }}"
679725
SEMVER_REGEX='^v?[0-9]+\.[0-9]+\.[0-9]+$'
@@ -1819,7 +1865,10 @@ jobs:
18191865
${{ needs.setup.outputs.directory-path }}/diag*
18201866
18211867
run-scripted-input-tests-full-matrix:
1822-
if: ${{ !cancelled() && needs.build.result == 'success' && needs.test-inventory.outputs.scripted_inputs == 'true' && ( github.base_ref == 'main' || github.ref_name == 'main' ) && needs.setup-workflow.outputs.execute-scripted_inputs-labeled == 'true' }}
1868+
if: |
1869+
( !cancelled() && needs.build.result == 'success' && needs.test-inventory.outputs.scripted_inputs == 'true' ) &&
1870+
( github.base_ref == 'main' || github.ref_name == 'main' || ( github.ref_name == 'develop' && inputs.execute-tests-on-push-to-develop == 'true' ) || ( startsWith(github.ref_name, 'release/') && inputs.execute-tests-on-push-to-release == 'true' ) ) &&
1871+
( needs.setup-workflow.outputs.execute-scripted_inputs-labeled == 'true' )
18231872
needs:
18241873
- build
18251874
- test-inventory
@@ -2044,12 +2093,13 @@ jobs:
20442093
${{ needs.setup.outputs.directory-path }}/diag*
20452094
20462095
pre-publish:
2047-
if: ${{ !cancelled() }}
2096+
if: ${{ !cancelled() && needs.validate-custom-version.result == 'success' }}
20482097
# The following line will rename 'pre-publish' to 'pre-publish-not_main_pr' when PR is created towards main branch
20492098
# It is necessary to avoid confusion caused by githubactions considering pre-publish for both push to develop branch
20502099
# and pull_request to main branch events.
20512100
name: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' && 'pre-publish' || 'pre-publish-not_main_pr' }}
20522101
needs:
2102+
- validate-custom-version
20532103
- meta
20542104
- compliance-copyrights
20552105
- lint
@@ -2086,9 +2136,14 @@ jobs:
20862136
exit 1
20872137
20882138
publish:
2089-
if: ${{ !cancelled() && needs.pre-publish.result == 'success' && github.event_name != 'pull_request' && github.event_name != 'schedule' }}
2139+
if: |
2140+
(!cancelled() && needs.pre-publish.result == 'success' && github.event_name != 'pull_request' && github.event_name != 'schedule') ||
2141+
(!cancelled() && needs.pre-publish.result == 'success' && github.event.inputs.custom-version != '' && needs.validate-custom-version.result == 'success')
2142+
name: ${{ github.event.inputs.custom-version == '' && 'publish' || 'publish-custom-version' }}
2143+
20902144
needs:
20912145
- pre-publish
2146+
- validate-custom-version
20922147
runs-on: ubuntu-latest
20932148
permissions:
20942149
contents: write
@@ -2102,6 +2157,7 @@ jobs:
21022157
submodules: false
21032158
persist-credentials: false
21042159
- name: Semantic Release
2160+
if: ${{ github.event.inputs.custom-version == '' }}
21052161
id: semantic
21062162
uses: splunk/semantic-release-action@v1.3
21072163
env:
@@ -2111,46 +2167,55 @@ jobs:
21112167
git_committer_email: ${{ secrets.SA_GH_USER_EMAIL }}
21122168
gpg_private_key: ${{ secrets.SA_GPG_PRIVATE_KEY }}
21132169
passphrase: ${{ secrets.SA_GPG_PASSPHRASE }}
2170+
- name: Release custom version
2171+
if: ${{ github.event.inputs.custom-version != '' }}
2172+
id: custom
2173+
uses: "softprops/action-gh-release@v2"
2174+
with:
2175+
token: "${{ secrets.GH_TOKEN_ADMIN }}"
2176+
tag_name: v${{ github.event.inputs.custom-version }}
2177+
target_commitish: "${{github.ref_name}}"
2178+
make_latest: false
21142179
- name: Download package-deployment
2115-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2180+
if: ${{ steps.semantic.outputs.new_release_published == 'true' || steps.custom.outputs.upload_url != '' }}
21162181
uses: actions/download-artifact@v4
21172182
id: download-package-deployment
21182183
with:
21192184
name: package-deployment
21202185
path: download/artifacts/
21212186
- name: Download package-splunkbase
2122-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2187+
if: ${{ steps.semantic.outputs.new_release_published == 'true' || steps.custom.outputs.upload_url != '' }}
21232188
uses: actions/download-artifact@v4
21242189
id: download-package-splunkbase
21252190
with:
21262191
name: package-splunkbase
21272192
path: download/artifacts/deployment
21282193
- name: Download cim-compliance-report
21292194
id: download-cim-compliance-report
2130-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2195+
if: ${{ steps.semantic.outputs.new_release_published == 'true' || steps.custom.outputs.upload_url != '' }}
21312196
continue-on-error: true
21322197
uses: actions/download-artifact@v4
21332198
with:
21342199
name: cim-compliance-report
21352200
path: download/artifacts/deployment
21362201
- name: Download cim-field-report
21372202
id: download-cim-field-report
2138-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2203+
if: ${{ steps.semantic.outputs.new_release_published == 'true' || steps.custom.outputs.upload_url != '' }}
21392204
continue-on-error: true
21402205
uses: actions/download-artifact@v4
21412206
with:
21422207
name: cim-field-report
21432208
path: download/artifacts/deployment
21442209
- name: List of assets
2145-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2210+
if: ${{ steps.semantic.outputs.new_release_published == 'true'|| steps.custom.outputs.upload_url != '' }}
21462211
run: |
21472212
ls -la ${{ steps.download-package-splunkbase.outputs.download-path }}
21482213
- name: Upload assets to release
2149-
if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
2214+
if: ${{ steps.semantic.outputs.new_release_published == 'true' || steps.custom.outputs.upload_url != '' }}
21502215
uses: svenstaro/upload-release-action@v2
21512216
with:
21522217
repo_token: ${{ github.token }}
21532218
file: ${{ steps.download-package-splunkbase.outputs.download-path }}/*
21542219
overwrite: true
21552220
file_glob: true
2156-
tag: v${{ steps.semantic.outputs.new_release_version }}
2221+
tag: v${{ github.event.inputs.custom-version != '' && github.event.inputs.custom-version || steps.semantic.outputs.new_release_version }}

0 commit comments

Comments
 (0)