forked from pyouroboros/ouroboros
-
-
Notifications
You must be signed in to change notification settings - Fork 5
147 lines (145 loc) · 4.84 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Build
on:
release:
types: [published]
jobs:
test:
name: Docker Test on ubuntu-latest
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
driver-opts: network=host
- name: Update Version String
run: |
sed -i -r 's/VERSION = "custom"/VERSION = "0.0+test"/' pyouroboros/__init__.py
echo $?\
- name: Build Docker
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
cache-from: type=gha,scope=main
cache-to: type=gha,mode=max,scope=main
tags: localhost:5000/tester/ouroboros:test
- name: Test with Docker
run: |
sudo mkdir -p /app/pyouroboros/hooks
docker run --rm --name ouroboros -v /var/run/docker.sock:/var/run/docker.sock localhost:5000/tester/ouroboros:test --run-once --dry-run --log-level debug
build:
name: Docker Build on ubuntu-latest
runs-on: ubuntu-latest
needs: test
steps:
- name: Check Credentials
id: check_credentials
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_CLITOKEN: ${{ secrets.DOCKER_CLITOKEN }}
run: |
if [ "${DOCKER_USER}" == "" ]; then
echo "Missing User"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
elif [ "${DOCKER_CLITOKEN}" == "" ]; then
echo "Missing Cli Token"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
else
echo "All secrets present"
echo "missingsecrets=no" >> $GITHUB_OUTPUT
fi
- name: Checkout Repository
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get Revision Variables
id: build_env
run: |
echo ${GITHUB_REF:10}
echo "branch=${GITHUB_REF:10}" >> $GITHUB_OUTPUT
- name: Set up QEMU
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64,arm
- name: Set up Docker Buildx
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: docker/setup-buildx-action@v3
with:
version: latest
- name: Login to DockerHub Registry
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_CLITOKEN }}
logout: true
- name: Login to GitHub Container Registry
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
- name: Update Version String
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
env:
OUROBOROS_VERSION: ${{ steps.build_env.outputs.branch }}
run: |
sed -i -r 's/VERSION = "custom"/VERSION = "'$OUROBOROS_VERSION'"/' pyouroboros/__init__.py
echo $?\
- name: Build and Push Docker
if: contains(steps.check_credentials.outputs.missingsecrets, 'no')
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
cache-from: type=gha,scope=main
cache-to: type=gha,mode=max,scope=main
tags: |
${{ secrets.DOCKER_USER }}/ouroboros:${{ steps.build_env.outputs.branch }}
${{ secrets.DOCKER_USER }}/ouroboros:latest
ghcr.io/${{ github.repository_owner }}/ouroboros:${{ steps.build_env.outputs.branch }}
ghcr.io/${{ github.repository_owner }}/ouroboros:latest
cleanup:
name: Cleanup Cache
runs-on: ubuntu-latest
needs: [test, build]
steps:
- name: Cleanup Cache
run: |
gh extension install actions/gh-actions-cache
REPO="${{ github.repository }}"
BRANCH="${{ github.ref }}"
echo "Fetching list of cache keys"
cacheKeys=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeys
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}