forked from uptimekit/uptimekit
-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (157 loc) · 5.89 KB
/
release.yml
File metadata and controls
188 lines (157 loc) · 5.89 KB
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
name: Release
on:
push:
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_BASE: ghcr.io/${{ github.repository }}
jobs:
prepare:
name: Prepare Release
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: write
outputs:
packages: ${{ steps.detect.outputs.packages }}
has_releases: ${{ steps.detect.outputs.has_releases }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
- name: Extract Version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Set Versions
run: node scripts/set-version.js ${{ env.VERSION }}
- name: Update Lockfile
run: pnpm install --lockfile-only
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit and Sync
run: |
# Commit changes only if there are any
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "chore: release v${{ env.VERSION }}"
else
echo "No changes to commit. Version might have been manually bumped."
fi
# Push to release branch
git push origin HEAD:release
# Sync to development
git fetch origin release
git checkout development
git pull origin development
git merge origin/release
git push origin development
- name: Find All Packages with Dockerfiles
id: detect
run: |
PACKAGES="[]"
# Find all package.json files in apps and packages directories
PACKAGE_JSONS=$(find apps packages -maxdepth 2 -name "package.json" 2>/dev/null || true)
for PKG_FILE in $PACKAGE_JSONS; do
DIR=$(dirname "$PKG_FILE")
# Only include packages that have a Dockerfile
if [ -f "$DIR/Dockerfile" ]; then
NAME=$(node -p "require('./$PKG_FILE').name" 2>/dev/null || echo "")
VERSION=$(node -p "require('./$PKG_FILE').version" 2>/dev/null || echo "")
if [ -n "$NAME" ] && [ -n "$VERSION" ]; then
ITEM=$(jq -n \
--arg name "$NAME" \
--arg version "$VERSION" \
--arg dir "$DIR" \
'{name: $name, version: $version, dir: $dir}')
PACKAGES=$(echo "$PACKAGES" | jq -c --argjson item "$ITEM" '. + [$item]')
echo "Found: $NAME@$VERSION (dir: $DIR)"
fi
fi
done
# Use heredoc to safely output JSON
echo "packages<<EOF" >> $GITHUB_OUTPUT
echo "$PACKAGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
if [ "$PACKAGES" != "[]" ]; then
echo "has_releases=true" >> $GITHUB_OUTPUT
else
echo "has_releases=false" >> $GITHUB_OUTPUT
fi
echo "Packages for Docker build:"
echo "$PACKAGES" | jq .
publish-docker:
name: Publish Docker Images
needs: prepare
if: needs.prepare.outputs.has_releases == 'true'
runs-on: blacksmith-8vcpu-ubuntu-2404
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.prepare.outputs.packages) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: release
- name: Prepare Docker Metadata
id: prep
run: |
PACKAGE_NAME="${{ matrix.package.name }}"
# Remove scope if present (e.g. @uptimekit/dash -> dash)
APP_NAME=${PACKAGE_NAME#@*/}
APP_NAME=${APP_NAME#*/}
# Construct image name
IMAGE_NAME=${{ env.REGISTRY }}/${{ github.repository_owner }}/${APP_NAME}
# Lowercase just in case
IMAGE_NAME=$(echo "$IMAGE_NAME" | tr '[:upper:]' '[:lower:]')
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "app_name_clean=$APP_NAME" >> $GITHUB_OUTPUT
echo "app_dir=${{ matrix.package.dir }}" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ steps.prep.outputs.image_name }}
uptimekit/${{ steps.prep.outputs.app_name_clean }}
tags: |
type=semver,pattern={{version}},value=${{ matrix.package.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ matrix.package.version }}
type=semver,pattern={{major}},value=${{ matrix.package.version }}
type=raw,value=latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Docker Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Docker Image Publish
uses: useblacksmith/build-push-action@v2
with:
context: .
file: ${{ steps.prep.outputs.app_dir }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}