-
-
Notifications
You must be signed in to change notification settings - Fork 119
189 lines (163 loc) · 5.81 KB
/
build-nightly.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Build Nightly
run-name: Build Nightly ${{ inputs.dry_run && '(🧪 Dry-Run)' || '' }}
on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run'
type: boolean
default: true
env:
DOCKER_IMG: artalk/artalk-go
PLATFORMS: 'linux/amd64,linux/arm64,linux/arm/v7'
DOCKER_BUILD_ARGS: |-
SKIP_UI_BUILD=true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check should run
if: github.event_name == 'schedule'
run: |
if [[ "$(git log --since='24 hours ago' | wc -l)" -eq 0 ]] || \
[[ "$GITHUB_REPOSITORY" != "ArtalkJS/Artalk" ]]; then
echo "Skipping automatic run"
exit 78
fi
# https://github.com/docker/metadata-action
- name: Gen docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_IMG }}
tags: |
type=raw,value=nightly
# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}
# https://github.com/docker/setup-buildx-action
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
# Build UI outside of Docker to speed up cross-platform builds
- name: Build UI
run: |
make build-frontend
- name: Build `linux/amd64` and Load locally
uses: docker/build-push-action@v5
with:
load: true # automatically load the single-platform build result to `docker images`
push: false
context: .
file: ./Dockerfile
platforms: 'linux/amd64'
build-args: ${{ env.DOCKER_BUILD_ARGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# https://github.com/docker/build-push-action
- name: Build Multi-Platform Docker Images and Push
uses: docker/build-push-action@v5
if: ${{ !inputs.dry_run }}
with:
push: true
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
build-args: ${{ env.DOCKER_BUILD_ARGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
# Export docker image
- name: Export Docker Image
id: docker_image
run: |
FILENAME="docker_image_nigthly_$(date +'%Y%m%d')_linux_amd64.tar"
docker save -o $FILENAME ${{ env.DOCKER_IMG }}
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
# Frontend
- name: Pack frontend
id: pack_frontend
run: |
FILENAME="frontend_nigthly_$(date +'%Y%m%d').tar.gz"
PKG_FILE=$(pnpm pack -C ui/artalk --pack-destination ../.. | tail -n 1)
mv $PKG_FILE $FILENAME
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
# App
- name: Pack app
id: pack_app
run: |
DEST="artalk_nigthly_$(date +'%Y%m%d')_linux_amd64"
FILENAME="$DEST.tar.gz"
mkdir -p $DEST
# bin file
docker run --rm --entrypoint cat ${{ env.DOCKER_IMG }} /artalk > "$DEST/artalk"
chmod +x "$DEST/artalk"
# doc file
cp conf/artalk.example.yml "$DEST/artalk.yml"
cp README.md LICENSE CHANGELOG.md "$DEST"
tar -czf $FILENAME $DEST
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
# Generate CHANGELOG
- name: Generate Changelog
run: |
# install git-chglog
curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \
| grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog
CHANGELOG=$(git-chglog --config .github/chglog/config.yml --next-tag nightly nightly)
echo -e "$CHANGELOG" > release.md
echo -e "\n\nDocker Pull Command:\n\n\`\`\`sh\ndocker pull artalk/artalk-go:nightly\n\`\`\`" >> release.md
# checksums.txt
- name: Calculate checksums.txt
id: checksums
env:
DIST_FILES: |-
${{ steps.docker_image.outputs.filename }}
${{ steps.pack_app.outputs.filename }}
${{ steps.pack_frontend.outputs.filename }}
run: |
sha256sum $DIST_FILES > checksums.txt
echo -e "DIST_FILES<<EOF" >> $GITHUB_ENV
echo -e "$DIST_FILES\n" >> $GITHUB_ENV
echo -e "checksums.txt" >> $GITHUB_ENV
echo -e "EOF" >> $GITHUB_ENV
echo "RELEASE_NAME=Nightly Release $(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v2
with:
draft: ${{ inputs.dry_run }}
prerelease: true
name: ${{ env.RELEASE_NAME }}
body_path: release.md
files: |
${{ env.DIST_FILES }}
checksums.txt