Skip to content

Commit d98eb22

Browse files
committed
change to new ci
1 parent e0f567b commit d98eb22

File tree

3 files changed

+170
-61
lines changed

3 files changed

+170
-61
lines changed

.github/workflows/build-ci.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Based heavily on the docker build action from immich (https://github.com/immich-app/immich/)
2+
3+
name: Docker
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
release:
12+
types: [published]
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build-pio:
20+
name: Build PlatformIO
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: actions/cache@v3
25+
with:
26+
path: |
27+
~/.cache/pip
28+
~/.platformio/.cache
29+
key: ${{ runner.os }}-pio
30+
- uses: actions/setup-python@v4
31+
with:
32+
python-version: '3.11'
33+
- name: Install PlatformIO Core
34+
run: pip install --upgrade platformio
35+
36+
- name: Build PlatformIO Project
37+
run: pio run --environment d1_mini
38+
39+
- name: Move and rename firmware
40+
run: mv .pio/build/d1_mini/firmware.bin ./firmware_os_esp8266.bin
41+
42+
- name: Upload firmware
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: firmware
46+
path: ./firmware_os_esp8266.bin
47+
build-docker:
48+
name: Build and Push
49+
runs-on: ubuntu-latest
50+
needs: [build-pio, build-ospi]
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v4
54+
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
- name: Login to GitHub Container Registry
62+
uses: docker/login-action@v3
63+
# Skip when PR from a fork
64+
if: ${{ !github.event.pull_request.head.repo.fork }}
65+
with:
66+
registry: ghcr.io
67+
username: ${{ env.ACT && github.actor || github.repository_owner }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Determine build cache output
71+
id: cache-target
72+
run: |
73+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
74+
# Essentially just ignore the cache output (PR can't write to registry cache)
75+
echo "cache-to=type=local,dest=/tmp/discard,ignore-error=true" >> $GITHUB_OUTPUT
76+
else
77+
echo "cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }}" >> $GITHUB_OUTPUT
78+
fi
79+
80+
- name: Build and push image
81+
uses: docker/[email protected]
82+
with:
83+
context: .
84+
file: ./Dockerfile
85+
platforms: linux/amd64,linux/arm/v7,linux/arm64
86+
# Skip pushing when PR from a fork
87+
push: ${{ !github.event.pull_request.head.repo.fork }}
88+
output: type=docker,dest=./output.tar
89+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }}
90+
cache-to: ${{ steps.cache-target.outputs.cache-to }}
91+
92+
- name: Upload image
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: docker-image
96+
path: ./output.tar
97+
expire-in: 1h
98+
release-pio:
99+
name: Release PlatformIO
100+
runs-on: ubuntu-latest
101+
needs: [ build-pio build-docker ]
102+
if: ${{ github.event_name == 'release' }}
103+
steps:
104+
- name: Download firmware
105+
uses: actions/download-artifact@v4
106+
with:
107+
name: firmware
108+
path: ./firmware
109+
110+
- name: Add firmware to release
111+
uses: softprops/action-gh-release@v2
112+
with:
113+
files: firmware/*
114+
115+
release-docker:
116+
name: Release Docker
117+
runs-on: ubuntu-latest
118+
needs: [ build-pio build-docker ]
119+
steps:
120+
- name: Download docker image
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: docker-image
124+
125+
- name: Login to GitHub Container Registry
126+
uses: docker/login-action@v3
127+
# Skip when PR from a fork
128+
if: ${{ !github.event.pull_request.head.repo.fork }}
129+
with:
130+
registry: ghcr.io
131+
username: ${{ env.ACT && github.actor || github.repository_owner }}
132+
password: ${{ secrets.GITHUB_TOKEN }}
133+
134+
- name: Login to GitHub Container Registry
135+
uses: docker/login-action@v3
136+
# Skip when PR from a fork
137+
if: ${{ !github.event.pull_request.head.repo.fork }}
138+
with:
139+
registry: ghcr.io
140+
username: ${{ env.ACT && github.actor || github.repository_owner }}
141+
password: ${{ secrets.GITHUB_TOKEN }}
142+
143+
- name: Generate docker image tags
144+
id: metadata
145+
uses: docker/metadata-action@v5
146+
with:
147+
flavor: |
148+
latest=auto
149+
images: |
150+
name=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}
151+
tags: |
152+
# Tag with branch name
153+
type=ref,event=branch
154+
# Tag with pr-number
155+
type=ref,event=pr
156+
# Tag with git tag on release
157+
type=ref,event=tag
158+
type=raw,value=release,enable=${{ github.event_name == 'release' }}
159+
160+
- name: Load image
161+
run: docker load -i ./docker-image/output.tar
162+
163+
- name: Build and push
164+
uses: docker/build-push-action@v6
165+
with:
166+
platforms: linux/amd64,linux/arm/v7,linux/arm64
167+
# Skip pushing when PR from a fork
168+
push: ${{ !github.event.pull_request.head.repo.fork }}
169+
tags: ${{ steps.metadata.outputs.tags }}
170+
labels: ${{ steps.metadata.outputs.labels }}

.github/workflows/c-cpp.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/docker-image.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)