Skip to content

Commit 82cb9fe

Browse files
authored
fix: build action rework (#69)
1 parent 96f3adf commit 82cb9fe

File tree

1 file changed

+83
-22
lines changed

1 file changed

+83
-22
lines changed

.github/workflows/build-source-image.yaml

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,27 @@ on:
216216
- source-zoom
217217
- source-zuora
218218

219-
basetag:
220-
description: 'Custom tag if you want the versioning to be based on a different tag than the latest'
219+
customtag:
220+
description: 'Custom tag (If entered, the image will be build using this tag)'
221221

222222
change_type:
223-
description: 'Choose between minor and patch (Major will be changed during upstream sync)'
223+
description: 'Change type (only applicable when image build from main, choose n/a for resuing latest tag)'
224224
required: true
225225
type: choice
226226
default: "minor"
227227
options:
228228
- minor
229229
- patch
230+
- n/a
231+
232+
sort_by:
233+
description: 'Latest tag by'
234+
required: true
235+
type: choice
236+
default: "version"
237+
options:
238+
- date
239+
- version
230240
jobs:
231241
build-and-push:
232242
runs-on: ubuntu-latest
@@ -243,44 +253,95 @@ jobs:
243253
fetch-depth: 0
244254

245255
- name: Get previous tag
246-
id: previoustag
247-
uses: "WyriHaximus/github-action-get-previous-tag@v1"
256+
if: ${{ github.event.inputs.customtag == '' }}
257+
id: current_tag
258+
uses: "debanjan97/[email protected]"
248259
env:
249260
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
261+
with:
262+
sort: ${{ github.event.inputs.sort_by }}
263+
stable: true # ignores alpha builds
250264

251-
- name: Get Next Version
252-
id: nextversion
265+
- name: Check if version bump is required
266+
if: ${{ github.ref_name == 'main' }}
267+
id: bump
268+
run: |
269+
if [ "${{ github.event.inputs.customtag }}" != "" ]; then
270+
# custom tag exists, no version bump required
271+
echo "required=false" >> $GITHUB_OUTPUT
272+
exit 0
273+
fi;
274+
275+
if [ "${{ github.event.inputs.change_type }}"="n/a" ]; then
276+
echo "change type is marked n/a, assuming no version bump is required"
277+
echo "required=false" >> $GITHUB_OUTPUT
278+
exit 0
279+
fi;
280+
281+
last_commit=${git rev-list -n 1 ${{ steps.current_tag.outputs.tag }}}
282+
current_commit=${{ github.sha }}
283+
if [ $last_commit = $current_commit ]; then
284+
echo "no new commits from the last tag, no version bump is required"
285+
required=false
286+
else
287+
required=true
288+
fi;
289+
echo "required=$required" >> $GITHUB_OUTPUT
290+
291+
- name: Calculate Next Versions
292+
if: ${{ steps.bump.outputs.required == 'true' }}
293+
id: calculatenextversion
253294
uses: "WyriHaximus/github-action-next-semvers@v1"
254295
with:
255-
version: ${{ github.event.inputs.basetag || steps.previoustag.outputs.tag }}
296+
version: ${{ steps.current_tag.outputs.tag }}
256297

257-
- name: Generate Next Version according to change_type
258-
id: version
298+
- name: Generate New Version according to change_type
299+
if: ${{ steps.bump.outputs.required == 'true' }}
300+
id: newversion
259301
run: |
260302
if [ "${{ github.event.inputs.change_type }}" = "minor" ]; then
261-
nextversion=${{ steps.nextversion.outputs.v_minor }}
303+
newversion=${{ steps.calculatenextversion.outputs.v_minor }}
262304
else
263-
nextversion=${{ steps.nextversion.outputs.v_patch }}
305+
newversion=${{ steps.calculatenextversion.outputs.v_patch }}
306+
fi;
307+
echo "version=$newversion" >> $GITHUB_OUTPUT
308+
309+
- name: Get Build Tag
310+
id: buildtag
311+
run: |
312+
# if custom tag is present, return it
313+
if [ "${{ github.event.inputs.customtag }}" != "" ]; then
314+
tag="${{ github.event.inputs.customtag }}"
315+
echo "tag=$tag" >> $GITHUB_OUTPUT
316+
exit 0
264317
fi;
318+
265319
source_branch_name="${GITHUB_REF##*/}"
266-
git_hash=$(git rev-parse --short "$GITHUB_SHA")
267-
268-
# for dev branches, prefix "-alpha.<commit-hash>"
269-
if [ $source_branch_name != "main" ]; then
270-
nextversion=$nextversion"-alpha."$git_hash
320+
if [ $source_branch_name = "main" ]; then
321+
if [ "${{ steps.bump.outputs.required }}"="false" ]; then
322+
# return current tag, if no new commits
323+
echo "no version bump required, proceeding with current version"
324+
tag=${{ steps.current_tag.outputs.tag }}
325+
else
326+
tag=${{ steps.newversion.outputs.version }}
327+
fi;
328+
else
329+
# if branch is feature branch, append alpha.<commit_hash> to the latest tag
330+
git_hash=$(git rev-parse --short "$GITHUB_SHA")
331+
tag=${{ steps.current_tag.outputs.tag }}"-alpha."$git_hash
271332
fi;
272-
273-
echo "next_version=$nextversion" >> $GITHUB_OUTPUT
333+
echo "tag=$tag" >> $GITHUB_OUTPUT
274334
275335
- uses: mukunku/[email protected]
336+
name: Check if the generated tag exists
276337
id: checkTag
277338
with:
278-
tag: ${{ steps.version.outputs.next_version }}
339+
tag: ${{ steps.buildtag.outputs.tag }}
279340

280341
- name: Publish version as a tag
281342
if: ${{ steps.checkTag.outputs.exists != 'true' }}
282343
run: |
283-
git tag ${{ steps.version.outputs.next_version }}
344+
git tag ${{ steps.buildtag.outputs.tag }}
284345
git push --tag
285346
286347
- name: Build and Push
@@ -290,7 +351,7 @@ jobs:
290351
file: ./airbyte-integrations/connectors/${{ github.event.inputs.connector }}/Dockerfile
291352
push: true
292353
platforms: linux/amd64
293-
tags: rudderstack/${{ github.event.inputs.connector }}:${{ steps.version.outputs.next_version }}
354+
tags: rudderstack/${{ github.event.inputs.connector }}:${{ steps.buildtag.outputs.tag }}
294355

295356

296357

0 commit comments

Comments
 (0)