-
Notifications
You must be signed in to change notification settings - Fork 41
124 lines (104 loc) · 2.88 KB
/
main.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: PI-CI
on:
push:
branches:
- '**'
env:
IMAGE_NAME: ptrsr/pi-ci
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Free up disk space on github runner
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
# android: false
# dotnet: false
# haskell: false
# large-packages: false
# swap-storage: false
- name: Checkout
uses: actions/checkout@v4
- name: Cache register
id: cache
uses: actions/cache@v4
with:
path: /tmp/image.tar
key: ${{ hashFiles('dockerfile') }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
docker buildx build \
-t ${{ env.IMAGE_NAME }} \
-o type=docker,dest=- \
. > /tmp/image.tar
test:
needs: build
runs-on: ubuntu-24.04
outputs:
publish: ${{ steps.check.outputs.publish }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache register
id: cache
uses: actions/cache@v4
with:
path: /tmp/image.tar
key: ${{ hashFiles('dockerfile') }}
- name: Load Docker image
run: docker load -i /tmp/image.tar
- name: Install dependencies
run: |
sudo apt-get install ansible
pip3 install docker-py
env:
PIP_BREAK_SYSTEM_PACKAGES: 1
- name: Run test
run: |
ansible-playbook \
-i test/hosts.yml \
test/main.yml
- uses: actions/upload-artifact@v4
with:
name: config
path: dist
- name: Check for Tag
id: check
run: |
git fetch --tags
if [[ ! -z "$(git tag --contains HEAD)" ]]; then
echo "publish=true" >> $GITHUB_OUTPUT
fi
publish:
if: needs.test.outputs.publish == 'true'
needs: test
runs-on: ubuntu-24.04
environment: docker-hub
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set tag variable
run: |
git fetch --tags
echo "TAG=$(git tag --contains HEAD)" >> $GITHUB_ENV
- name: Cache register
id: cache
uses: actions/cache@v4
with:
path: /tmp/image.tar
key: ${{ hashFiles('dockerfile') }}
- name: Load Docker image
run: docker load -i /tmp/image.tar
- name: Tag docker image
run: docker tag ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:${{ env.TAG }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Push to Docker Hub
run: docker push -a ${{ env.IMAGE_NAME }}