@@ -2,8 +2,8 @@ name: publish-docker
22
33on :
44 push :
5- tags :
6- - " v* "
5+ branches :
6+ - main
77 workflow_dispatch :
88
99jobs :
1515 steps :
1616 - name : Checkout
1717 uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
1820
1921 - name : Set up QEMU
2022 uses : docker/setup-qemu-action@v3
@@ -28,15 +30,57 @@ jobs:
2830 username : ${{ secrets.DOCKERHUB_USERNAME }}
2931 password : ${{ secrets.DOCKERHUB_TOKEN }}
3032
33+ - name : Resolve next Docker version (v1.0.N)
34+ id : version
35+ env :
36+ DOCKERHUB_NAMESPACE : ecrum19
37+ DOCKERHUB_REPO : vcf-rdfizer
38+ run : |
39+ python - <<'PY'
40+ import json
41+ import os
42+ import re
43+ import subprocess
44+ import urllib.request
45+
46+ namespace = os.environ["DOCKERHUB_NAMESPACE"]
47+ repo = os.environ["DOCKERHUB_REPO"]
48+ pattern = re.compile(r"^v1\.0\.(\d+)$")
49+
50+ def parse_max(tags):
51+ max_n = -1
52+ for tag in tags:
53+ m = pattern.match(tag)
54+ if m:
55+ max_n = max(max_n, int(m.group(1)))
56+ return max_n
57+
58+ max_n = -1
59+ try:
60+ url = f"https://hub.docker.com/v2/repositories/{namespace}/{repo}/tags?page_size=100"
61+ while url:
62+ with urllib.request.urlopen(url, timeout=20) as resp:
63+ payload = json.load(resp)
64+ max_n = max(max_n, parse_max([item.get("name", "") for item in payload.get("results", [])]))
65+ url = payload.get("next")
66+ except Exception:
67+ tags = subprocess.check_output(["git", "tag"], text=True).splitlines()
68+ max_n = max(max_n, parse_max(tags))
69+
70+ next_version = f"v1.0.{max_n + 1}"
71+ print(f"Next Docker version: {next_version}")
72+
73+ with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
74+ f.write(f"next_version={next_version}\n")
75+ PY
76+
3177 - name : Docker metadata
3278 id : meta
3379 uses : docker/metadata-action@v5
3480 with :
3581 images : ecrum19/vcf-rdfizer
3682 tags : |
37- type=semver,pattern={{version}},value=${{ github.ref_name }}
38- type=semver,pattern={{major}}.{{minor}},value=${{ github.ref_name }}
39- type=semver,pattern={{major}},value=${{ github.ref_name }}
83+ type=raw,value=${{ steps.version.outputs.next_version }}
4084 type=raw,value=latest
4185
4286 - name : Build and push
0 commit comments