-
-
Notifications
You must be signed in to change notification settings - Fork 114
59 lines (51 loc) · 1.71 KB
/
tag-pushed.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: tag-pushed
on:
push:
tags:
- '\d+\.\d+\.\d+'
jobs:
ci-build-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check if tag belongs to the latest major release or is higher
id: check_tag
run: |
highest_tag=$(git tag -l | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" | sort -rV | head -n1)
highest_major=$(echo $highest_tag | cut -d '.' -f 1)
test -n "$highest_major"
current_tag=${{ github.ref_name }}
current_major=$(echo $current_tag | cut -d '.' -f 1)
test -n "$current_major"
if [ $current_major -ge $highest_major ]; then
echo "is_latest_major=true" >> $GITHUB_OUTPUT
else
echo "is_latest_major=false" >> $GITHUB_OUTPUT
fi
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ github.repository }}
flavor: |
latest=false
tags: |
type=raw,value=latest,enable=${{ steps.check_tag.outputs.is_latest_major }}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{version}}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}