Skip to content

Commit 5bdcbe4

Browse files
committed
Faet: unifed github ci
1 parent f6b8cc2 commit 5bdcbe4

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: container-images
22

3-
43
on:
54
push:
65
branches: [ "main" ]
@@ -19,10 +18,32 @@ jobs:
1918
- uses: docker/setup-qemu-action@v3
2019
- uses: docker/setup-buildx-action@v3
2120

22-
- run: echo "IMAGE_TAG=main" >> $GITHUB_ENV
23-
if: github.ref_name == 'main'
24-
- run: echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
25-
if: startsWith(github.ref, 'refs/tags/v')
21+
- name: Set ALL_TAGS
22+
env:
23+
REPOSITORY: '${{ github.repository }}'
24+
run: |
25+
# tag main if main branch
26+
if [[ "${{ github.ref_name }}" == "main" ]]; then
27+
image_tags=("main")
28+
# tag with tag name if tag
29+
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
30+
image_tags=("${{ github.ref_name }}")
31+
# tag with latest if tag is a new major, minor or patch version
32+
if [[ "${{ github.ref_name}}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
33+
image_tags+=("latest")
34+
fi
35+
fi
36+
37+
lc_repo=${REPOSITORY,,}
38+
39+
image_paths=()
40+
for tag in ${image_tags[@]}; do
41+
image_paths+=("ghcr.io/$lc_repo:$tag")
42+
done
43+
44+
# join with ',' and then skip first character
45+
ALL_TAGS=$(printf ',%s' "${image_paths[@]}")
46+
echo "ALL_TAGS=${ALL_TAGS:1}" >>$GITHUB_ENV
2647
2748
- name: Login to ghcr.io
2849
uses: docker/login-action@v3
@@ -31,29 +52,10 @@ jobs:
3152
username: ${{ github.actor }}
3253
password: ${{ secrets.GITHUB_TOKEN }}
3354

34-
#- name: Login to docker.io
35-
# uses: docker/login-action@v2
36-
# with:
37-
# username: ${{ secrets.DOCKER_HUB_UID }}
38-
# password: ${{ secrets.DOCKER_HUB_PAT }}
39-
40-
- name: Build and push image for tags
41-
uses: docker/build-push-action@v5
42-
if: startsWith(github.ref, 'refs/tags/v')
43-
with:
44-
context: . # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
45-
push: true
46-
tags: |
47-
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}
48-
ghcr.io/${{ github.repository }}:latest
49-
50-
- name: Build and push image for main
55+
- name: Build and push default image
5156
uses: docker/build-push-action@v5
52-
if: github.ref_name == 'main'
5357
with:
5458
context: . # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
55-
# platforms: linux/amd64,linux/arm64
59+
platforms: linux/amd64,linux/arm64
5660
push: true
57-
tags: |
58-
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}
59-
61+
tags: ${{ env.ALL_TAGS }}

0 commit comments

Comments
 (0)