From a133e7f6557de32f2266053253647100d5eb31fa Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 13 Apr 2024 22:32:13 +0100 Subject: [PATCH] [ci] tagging --- .github/get-tags.py | 20 ++++++++++++++++++++ .github/workflows/publish.yml | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 .github/get-tags.py diff --git a/.github/get-tags.py b/.github/get-tags.py new file mode 100755 index 00000000..a8ded364 --- /dev/null +++ b/.github/get-tags.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +from subprocess import check_output +import sys + +branch = check_output(["git", "branch", "--show-current"], text=True).strip() +describe = check_output(["git", "describe", "--tags"], text=True).strip() +tag = describe.split("-")[0][1:] +a, b, c = tag.split(".") + +if branch == "main": + print("tags=latest") +elif branch.startswith("branch-2."): + if "-" in describe: + print(f"tags={a},{a}.{b}") + else: + print(f"tags={a},{a}.{b},{a}.{b}.{c}") +else: + print("Only run from main or branch-2.X") + sys.exit(1) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 48e0233e..822643a6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,8 @@ on: types: completed workflow_dispatch: push: - tags: - - 'v*' + branches: + - 'branch-2.*' jobs: publish: @@ -23,13 +23,22 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.workflow_run.head_sha }} + fetch-tags: true + fetch-depth: 0 - name: Checkout main commit if: ${{ github.event_name != 'workflow_run' }} uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 - name: Set build vars run: | echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV echo "BUILD_HASH=$GITHUB_SHA" >> $GITHUB_ENV + - name: Get tags + id: get-tags + shell: bash + run: ./.github/get-tags.py >> $GITHUB_OUTPUT - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@main with: @@ -39,4 +48,4 @@ jobs: cache: ${{ github.event_name != 'schedule' }} buildoptions: "--build-arg RUN_TESTS=false" buildargs: BUILD_TIME,BUILD_HASH - tag_semver: true + tags: "${{ steps.get-tags.outputs.tags }}"