-
-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (87 loc) · 2.88 KB
/
build.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Build and push new releases to Docker Hub
on:
schedule:
- cron: "0 0 * * *"
jobs:
changes:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.get_tag.outputs.value }}
env:
repo: bojand/ghz
steps:
- name: Install skopeo
run: sudo apt install skopeo
- name: Get all tags that are not in DockerHub yet
id: get_tag
run: |
get_latest() {
local git=$(curl --silent "https://api.github.com/repos/bojand/ghz/git/refs/tags" | jq -r '.[].ref' | sed '1,66d' | sed 's/^refs\/tags\///g' | paste -d, -s)
local docker=$(skopeo inspect docker://obvionaoe/ghz | jq -r '.RepoTags[]' | sed '1d' | sort -V | paste -d, -s)
local result="\""
local flag=0
for i in ${git//,/ }
do
for j in ${docker//,/ }
do
if [[ "$i" == "$j" ]]; then
flag=1
break
fi
done
if [[ $flag -eq 1 ]]; then
flag=0
continue
fi
result+="$i,"
done
result=${result::-1}
if [ -z $result ]; then
result+="\"\""
else
result+="\""
fi
echo $result | jq 'split(",")'
}
delimiter="$(openssl rand -hex 8)"
echo "value<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$(get_latest)" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
docker:
needs: [ changes ]
if: ${{ needs.changes.outputs.tags != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
value: ${{ fromJson(needs.changes.outputs.tags) }}
steps:
- name: Cache Docker build layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
push: true
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ github.repository_owner }}/ghz:${{ matrix.value }},${{ github.repository_owner }}/ghz:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: APP_VERSION=${{ matrix.value }}