[ci] tagging

This commit is contained in:
Shish 2024-04-13 22:32:13 +01:00 committed by Shish
parent 426f30e8d5
commit a133e7f655
2 changed files with 32 additions and 3 deletions

20
.github/get-tags.py vendored Executable file
View file

@ -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)

View file

@ -9,8 +9,8 @@ on:
types: completed types: completed
workflow_dispatch: workflow_dispatch:
push: push:
tags: branches:
- 'v*' - 'branch-2.*'
jobs: jobs:
publish: publish:
@ -23,13 +23,22 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.workflow_run.head_sha }} ref: ${{ github.event.workflow_run.head_sha }}
fetch-tags: true
fetch-depth: 0
- name: Checkout main commit - name: Checkout main commit
if: ${{ github.event_name != 'workflow_run' }} if: ${{ github.event_name != 'workflow_run' }}
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Set build vars - name: Set build vars
run: | run: |
echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
echo "BUILD_HASH=$GITHUB_SHA" >> $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 - name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@main uses: elgohr/Publish-Docker-Github-Action@main
with: with:
@ -39,4 +48,4 @@ jobs:
cache: ${{ github.event_name != 'schedule' }} cache: ${{ github.event_name != 'schedule' }}
buildoptions: "--build-arg RUN_TESTS=false" buildoptions: "--build-arg RUN_TESTS=false"
buildargs: BUILD_TIME,BUILD_HASH buildargs: BUILD_TIME,BUILD_HASH
tag_semver: true tags: "${{ steps.get-tags.outputs.tags }}"