-
Notifications
You must be signed in to change notification settings - Fork 1
279 lines (254 loc) · 10.3 KB
/
release.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
---
name: Release
on:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
permissions:
contents: read
packages: write
jobs:
github_release:
name: GitHub Release
runs-on: ubuntu-24.04
permissions:
contents: write
issues: write
pull-requests: write
outputs:
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
persist-credentials: false
- name: Configure Git signing
run: |
echo "${{ secrets.BOT_GPG_PRIVATE_KEY }}" | gpg --import
git config --global user.signingkey ${{ secrets.BOT_GPG_KEY_ID }}
git config --global commit.gpgsign true
git config --global commit.signoff true
git config --global user.name 'GitHub Actions Bot'
git config --global user.email '[email protected]'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install semantic release and plugins
run: |
npm install -g [email protected] \
conventional-changelog-cli \
conventional-changelog-conventionalcommits \
@semantic-release/changelog \
@semantic-release/exec \
@semantic-release/git \
@semantic-release/github
- name: Create a release if needed
id: semantic
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: "GitHub Actions Bot"
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_COMMITTER_NAME: "GitHub Actions Bot"
GIT_COMMITTER_EMAIL: "[email protected]"
run: |
# Create first release if not exists using gh cli - Initial Release Version 0.1.0
# This is an HACK because semantic release doesn't support versions under 1.0.0
# But if we already have a release then it respects it and start to increment from there
if ! gh release view 0.1.0 >/dev/null 2>&1; then
gh release create 0.1.0 --title "Initial Release" --notes "Initial Release" --target main
exit 0
fi
# Run semantic-release in dry-run first to capture version
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true)
# Check if there are no changes
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then
echo "No new release needed"
echo "new_release_published=false" >> $GITHUB_OUTPUT
exit 0
fi
# Extract version from dry run output
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version"
exit 1
fi
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
# Run actual release
if semantic-release; then
echo "Successfully released version $VERSION"
echo "new_release_published=true" >> $GITHUB_OUTPUT
else
echo "Release failed"
exit 1
fi
# build_binaries:
# name: Build static binaries
# needs: github_release
# if: needs.github_release.outputs.new_release_published == 'true'
# timeout-minutes: 15
# permissions:
# contents: write
# strategy:
# fail-fast: false
# matrix:
# include:
# - os: ubuntu-24.04
# target: x86_64-unknown-linux-musl
# - os:
# - self-hosted
# - k8s
# - ubuntu-22.04-arm64
# target: aarch64-unknown-linux-musl
# - os: macos-latest
# target: x86_64-apple-darwin
# - os: macos-latest
# target: aarch64-apple-darwin
# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# ref: ${{ github.ref }}
# persist-credentials: false
# - name: Update Cargo.toml version
# run: |
# echo "Updating to version ${{ needs.github_release.outputs.new_release_version }}"
# if [[ "$RUNNER_OS" == "macOS" ]]; then
# sed -i '' "s/^version = .*/version = \"${{ needs.github_release.outputs.new_release_version }}\"/" Cargo.toml
# else
# sed -i "s/^version = .*/version = \"${{ needs.github_release.outputs.new_release_version }}\"/" Cargo.toml
# fi
# - name: Install Rust
# uses: actions-rust-lang/[email protected]
# with:
# toolchain: stable
# override: true
# - name: Cache Rust dependencies
# uses: actions/cache@v4
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# target/
# key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ matrix.target }}-cargo
# - name: Add target ${{ matrix.target }}
# run: rustup target add ${{ matrix.target }}
# - name: Add build tools for musl target instead of glibc
# if: ${{ !startsWith(matrix.os, 'macos') }}
# run: |
# sudo apt-get update && sudo apt-get install --no-install-recommends -y \
# curl \
# ca-certificates \
# build-essential \
# clang \
# llvm \
# pkg-config \
# wget \
# musl-tools \
# libssl-dev \
# && sudo rm -rf /var/lib/apt/lists/* \
# && cd /tmp \
# && wget https://musl.cc/x86_64-linux-musl-cross.tgz \
# && wget https://musl.cc/aarch64-linux-musl-cross.tgz \
# && tar -xzf x86_64-linux-musl-cross.tgz \
# && tar -xzf aarch64-linux-musl-cross.tgz \
# && sudo mv x86_64-linux-musl-cross aarch64-linux-musl-cross /opt/ \
# && rm -rf *.tgz
# - name: Build binary for ${{ matrix.target }}
# if: ${{ !startsWith(matrix.os, 'macos') }}
# env:
# PKG_CONFIG_ALLOW_CROSS: 1
# RUSTFLAGS: "-C target-feature=+crt-static -C linker=clang"
# CC: clang
# AR: llvm-ar
# OPENSSL_DIR: /usr
# OPENSSL_LIB_DIR: /usr/lib
# OPENSSL_INCLUDE_DIR: /usr/include
# OPENSSL_STATIC: 1
# run: |
# cargo build --release --no-default-features --target ${{ matrix.target }}
# - name: Build binary for ${{ matrix.target }}
# if: ${{ startsWith(matrix.os, 'macos') }}
# env:
# RUSTFLAGS: "-C target-feature=+crt-static"
# run: |
# cargo build --release --no-default-features --target ${{ matrix.target }}
# - name: Rename binary to the published name
# run: |
# mv target/${{ matrix.target }}/release/coder target/${{ matrix.target }}/release/coder_${{ matrix.target }}
# - name: Upload to GitHub Release
# uses: softprops/action-gh-release@v2
# with:
# files: target/${{ matrix.target }}/release/coder_${{ matrix.target }}
# tag_name: ${{ needs.github_release.outputs.new_release_version }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_containers:
name: B&P Containers
needs: github_release
if: needs.github_release.outputs.new_release_published == 'true'
timeout-minutes: 35
permissions:
packages: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-musl
- os:
- self-hosted
- k8s
target: aarch64-unknown-linux-musl
container:
image: gcr.io/kaniko-project/executor:v1.23.2-debug
options: --entrypoint=""
runs-on: ${{ matrix.os }}
steps:
- name: Authenticate with GHCR
run: |
mkdir -p /kaniko/.docker
cat << EOF > /kaniko/.docker/config.json
{
"auths": {
"ghcr.io": {
"auth": "$(echo -n ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} | base64)"
}
}
}
EOF
- name: Build and push
env:
REPOSITORY_NAME: coder
REPOSITORY_OWNER: ${{ github.repository_owner }}
CONTAINER_REGISTRY: ghcr.io
VERSION: ${{ needs.github_release.outputs.new_release_version }}
run: |
/kaniko/executor \
--context="${{ github.repositoryUrl }}#${{ github.ref }}" \
--dockerfile=Dockerfile \
--target=minimal \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }}:latest \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }}:minimal \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }}:minimal-${{ env.VERSION }} \
--build-arg=TARGET_ARCH=${{ matrix.target }} \
--label="org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--label="org.opencontainers.image.version=${{ env.VERSION }}" \
--label="org.opencontainers.image.revision=${{ github.sha }}" \
--label="org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--label="org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}" \
--label="org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/main/README.md" \
--label="org.opencontainers.image.title=Coder" \
--label="org.opencontainers.image.description=The AI-Powered Coder without tools" \
--label="org.opencontainers.image.licenses=MIT" \
--label="org.opencontainers.image.vendor=${{ github.repository_owner }}" \
--cache=true \
--cache-repo=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }}/cache