Skip to content

Commit e9a5512

Browse files
authored
feat: add nightly and release workflows for Docker image publishing
1 parent f490062 commit e9a5512

2 files changed

Lines changed: 139 additions & 15 deletions

File tree

.github/workflows/nightly.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Development Docker Image (Nightly)
2+
3+
on:
4+
schedule:
5+
# Run every night at 5:00 UTC
6+
- cron: '0 5 * * *'
7+
push:
8+
branches:
9+
- dev
10+
workflow_dispatch: # Allow manual triggering
11+
12+
env:
13+
REGISTRY: docker.io
14+
IMAGE_NAME: sillyangel/mice
15+
16+
jobs:
17+
check_changes:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
should_build: ${{ steps.check.outputs.should_build }}
21+
steps:
22+
- name: Check out the repo
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # Get full history to check for changes
26+
ref: dev # Always checkout dev branch
27+
28+
- name: Check for changes since last nightly build
29+
id: check
30+
run: |
31+
# Get the last commit hash from the previous nightly build
32+
LAST_NIGHTLY_COMMIT=$(gh api repos/${{ github.repository }}/actions/runs \
33+
--jq '.workflow_runs[] | select(.name == "Development Docker Image (Nightly)" and .conclusion == "success") | .head_sha' \
34+
| head -1 || echo "")
35+
36+
CURRENT_COMMIT=${{ github.sha }}
37+
38+
echo "Last nightly commit: $LAST_NIGHTLY_COMMIT"
39+
echo "Current commit: $CURRENT_COMMIT"
40+
41+
# If we don't have a previous commit or commits are different, we should build
42+
if [ -z "$LAST_NIGHTLY_COMMIT" ] || [ "$LAST_NIGHTLY_COMMIT" != "$CURRENT_COMMIT" ]; then
43+
echo "Changes detected or first nightly build"
44+
echo "should_build=true" >> $GITHUB_OUTPUT
45+
else
46+
echo "No changes since last nightly build"
47+
echo "should_build=false" >> $GITHUB_OUTPUT
48+
fi
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
push_to_registry:
53+
runs-on: ubuntu-latest
54+
needs: check_changes
55+
if: needs.check_changes.outputs.should_build == 'true' && github.ref_name == 'dev'
56+
permissions:
57+
packages: write
58+
contents: read
59+
attestations: write
60+
id-token: write
61+
steps:
62+
- name: Check out the repo
63+
uses: actions/checkout@v4
64+
with:
65+
ref: dev # Always checkout dev branch
66+
67+
- name: Login to Docker Hub
68+
uses: docker/login-action@v3
69+
with:
70+
username: ${{ secrets.DOCKERHUB_USERNAME }}
71+
password: ${{ secrets.DOCKERHUB_TOKEN }}
72+
73+
- name: Set up Node.js
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: '22'
77+
78+
- name: Get version from package.json
79+
id: app_version
80+
run: |
81+
VERSION=$(node -p "require('./package.json').version")
82+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
83+
84+
- name: Docker metadata (tags, labels)
85+
id: meta
86+
uses: docker/metadata-action@v5
87+
with:
88+
images: ${{ env.IMAGE_NAME }}
89+
tags: |
90+
type=raw,value=nightly
91+
type=raw,value=dev-latest
92+
type=sha,prefix=dev-
93+
labels: |
94+
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
95+
org.opencontainers.image.licenses=MIT
96+
org.opencontainers.image.description=Nightly development build
97+
98+
99+
- name: Set up QEMU
100+
uses: docker/setup-qemu-action@v3
101+
102+
- name: Setup Docker buildx
103+
uses: docker/setup-buildx-action@v3
104+
105+
- name: Build and push
106+
id: build
107+
uses: docker/build-push-action@v5
108+
with:
109+
context: .
110+
push: true
111+
tags: ${{ steps.meta.outputs.tags }}
112+
labels: ${{ steps.meta.outputs.labels }}
113+
platforms: |
114+
linux/amd64
115+
linux/arm64/v8
116+
cache-from: type=gha
117+
cache-to: type=gha,mode=max
118+
119+
- name: Generate artifact attestation
120+
uses: actions/attest-build-provenance@v1
121+
with:
122+
subject-name: ${{ env.IMAGE_NAME }}
123+
subject-digest: ${{ steps.build.outputs.digest }}
124+
push-to-registry: true
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Publish Docker Image
1+
name: Development Docker Image
22

33
on:
44
push:
5-
tags:
6-
- '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]'
75
branches:
86
- main
7+
tags:
8+
- '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]'
99

1010
env:
1111
REGISTRY: docker.io
@@ -41,18 +41,18 @@ jobs:
4141
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
4242
4343
- name: Docker metadata (tags, labels)
44-
id: meta
45-
uses: docker/metadata-action@v5
46-
with:
47-
images: ${{ env.IMAGE_NAME }}
48-
tags: |
49-
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
50-
type=raw,value=${{ steps.app_version.outputs.version }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
51-
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
52-
type=sha
53-
labels: |
54-
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
55-
org.opencontainers.image.licenses=MIT
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
50+
type=raw,value=${{ steps.app_version.outputs.version }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
51+
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
52+
type=sha,prefix=main-,enable=${{ github.ref_name == 'main' }}
53+
labels: |
54+
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
55+
org.opencontainers.image.licenses=MIT
5656
5757
5858
- name: Set up QEMU

0 commit comments

Comments
 (0)