-
Notifications
You must be signed in to change notification settings - Fork 1
117 lines (104 loc) · 3.57 KB
/
tii-depthai-ctrl.yaml
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
name: tii-depthai-ctrl
on:
push:
pull_request:
workflow_dispatch:
inputs:
build_amd64:
description: 'Build for AMD64'
required: true
default: true
type: boolean
build_arm64:
description: 'Build for ARM64'
required: true
default: false
type: boolean
build_riscv64:
description: 'Build for RISCV64'
required: true
default: false
type: boolean
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Determine platforms
id: platforms
run: |
qemu_platforms=""
docker_platforms=""
default_branch="${{ github.event.repository.default_branch }}"
matrix_list=()
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/$default_branch" ]]; then
matrix_list=("amd64" "arm64" "riscv64")
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.base_ref }}" == "$default_branch" ]]; then
matrix_list=("amd64" "arm64" "riscv64")
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.inputs.build_amd64 }}" == 'true' ]]; then
matrix_list+=("amd64")
fi
if [[ "${{ github.event.inputs.build_arm64 }}" == 'true' ]]; then
matrix_list+=("arm64")
fi
if [[ "${{ github.event.inputs.build_riscv64 }}" == 'true' ]]; then
matrix_list+=("riscv64")
fi
else
# Maybe push or some other trigger
matrix_list=("amd64")
fi
for platform in "${matrix_list[@]}"; do
qemu_platforms+="$platform,"
docker_platforms+="linux/$platform,"
done
echo "qemu=${qemu_platforms%?}" >> $GITHUB_OUTPUT
echo "docker=${docker_platforms%?}" >> $GITHUB_OUTPUT
echo "Building for $qemu_platforms"
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ steps.platforms.outputs.qemu }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/tiiuae/tii-depthai-ctrl
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Format tags as registry refs
id: registry_refs
env:
TAGS: ${{ steps.meta.outputs.json }}
run: |
echo tags=$(echo $TAGS | jq '.tags[] | "type=registry,ref=" + . | @text') >> $GITHUB_OUTPUT
- name: Build container image and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: ${{ steps.platforms.outputs.docker }}
push: true
no-cache: false
cache-from: ${{ steps.registry_refs.outputs.tags }}
cache-to: inline
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}