-
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (121 loc) · 4.73 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Release
on:
push:
branches:
- master
schedule:
- cron: "0 * * * *"
workflow_dispatch:
inputs:
forceBuild:
description: "Force image build"
required: false
default: false
type: boolean
env:
KLIPPER_REPOSITORY: https://github.com/klipper3d/klipper
MOONRAKER_REPOSITORY: https://github.com/Arksine/moonraker
IS_DEFAULT_BRANCH: ${{ endsWith(github.ref, github.event.repository.default_branch) }}
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
klipper_sha: ${{ steps.repo.outputs.klipper_sha }}
moonraker_sha: ${{ steps.repo.outputs.moonraker_sha }}
image_sha: ${{ steps.repo.outputs.image_sha }}
build_image: ${{ steps.check.outputs.build_image }}
steps:
- name: Get Klipper and Moonraker metadata
id: repo
run: |
KLIPPER_SHA=$(git ls-remote $KLIPPER_REPOSITORY HEAD | awk '{print $1}')
MOONRAKER_SHA=$(git ls-remote $MOONRAKER_REPOSITORY HEAD | awk '{print $1}')
IMAGE_SHA=$(echo $KLIPPER_SHA-$MOONRAKER_SHA | sha1sum | awk '{print $1}')
echo "klipper_sha=${KLIPPER_SHA}" >> $GITHUB_OUTPUT
echo "moonraker_sha=${MOONRAKER_SHA}" >> $GITHUB_OUTPUT
echo "image_sha=${IMAGE_SHA}" >> $GITHUB_OUTPUT
- name: Check if new Docker image should be built
id: check
run: |
BUILD_IMAGE=${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.forceBuild == 'true') }}
if ! "$BUILD_IMAGE"; then
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:sha-${{ steps.repo.outputs.image_sha }} > /dev/null || BUILD_IMAGE=true
fi
echo "build_image=${BUILD_IMAGE}" >> $GITHUB_OUTPUT
build:
name: Build and deploy
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.build_image == 'true' }}
permissions:
id-token: write
packages: write
contents: read
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare GitHub metadata
id: github_meta
run: |
REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
echo "repository_name=${REPOSITORY_NAME}" >> $GITHUB_OUTPUT
- name: Prepare Docker image metadata
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.github_meta.outputs.repository_name }}
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=klipper-sha-${{ needs.setup.outputs.klipper_sha }}
type=raw,value=moonraker-sha-${{ needs.setup.outputs.moonraker_sha }}
type=raw,value=sha-${{ needs.setup.outputs.image_sha }}
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: docker_push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
build-args: |
KLIPPER_REPOSITORY: ${{ env.KLIPPER_REPOSITORY }}
KLIPPER_SHA=${{ needs.setup.outputs.klipper_sha }}
MOONRAKER_REPOSITORY: ${{ env.MOONRAKER_REPOSITORY }}
MOONRAKER_SHA=${{ needs.setup.outputs.moonraker_sha }}
push: true
sbom: true
provenance: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
- name: Attest Docker Hub image
uses: actions/attest-build-provenance@v2
with:
subject-name: index.docker.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.github_meta.outputs.repository_name }}
subject-digest: ${{ steps.docker_push.outputs.digest }}
push-to-registry: true
- name: Attest Container Registry image
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.docker_push.outputs.digest }}
push-to-registry: true