-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
62 lines (53 loc) · 1.62 KB
/
action.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
name: build-action
inputs:
registry_username:
required: true
registry_password:
required: true
runs:
using: composite
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check if commit already pushed to registry
id: check_registry
shell: bash
run: |
python3 -c "
import sys
import urllib.request
import json
import base64
with urllib.request.urlopen('https://ghcr.io/token?scope=repository:wappuradio/webbi:pull') as f:
token = json.load(f)['token']
req = urllib.request.Request(
'https://ghcr.io/v2/wappuradio/webbi/tags/list',
headers={'Authorization': f'Bearer {token}'}
)
with urllib.request.urlopen(req) as f:
if sys.argv[1] in json.load(f)['tags']:
print('exists=true')
else:
print('exists=false')" \
\
"${{ github.sha }}" \
>> $GITHUB_OUTPUT
- name: Log in to registry
if: steps.check_registry.outputs.exists == 'false'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.registry_username }}
password: ${{ inputs.registry_password }}
- name: Build and push
if: steps.check_registry.outputs.exists == 'false'
id: docker
uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/wappuradio/webbi:${{ github.ref_name }}
ghcr.io/wappuradio/webbi:${{ github.sha }}
outputs:
image:
value: ghcr.io/wappuradio/webbi:${{ github.sha }}