Skip to content

Commit e4d4ddd

Browse files
committed
fix: Optimize Docker builds and fix workflows
- Use cargo-chef for cached Docker builds (20min -> 2-3min) - Fix npm version conflict by checking current version - Add real homebrew formula update logic - homebrew-tap repository now exists
1 parent 3d43f0f commit e4d4ddd

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ jobs:
179179
- name: Update package version
180180
working-directory: ./kanuni-npm
181181
run: |
182-
npm version ${{ needs.create-release.outputs.version }} --no-git-tag-version
182+
CURRENT_VERSION=$(node -p "require('./package.json').version")
183+
if [ "$CURRENT_VERSION" != "${{ needs.create-release.outputs.version }}" ]; then
184+
npm version ${{ needs.create-release.outputs.version }} --no-git-tag-version
185+
else
186+
echo "Version already set to ${{ needs.create-release.outputs.version }}"
187+
fi
183188
184189
- name: Publish to npm
185190
working-directory: ./kanuni-npm
@@ -248,7 +253,31 @@ jobs:
248253

249254
- name: Update Formula
250255
run: |
251-
# This would update the formula with new URLs and SHA256
252-
echo "Updating Homebrew formula for version ${{ needs.create-release.outputs.version }}"
253-
# Script to update formula would go here
256+
VERSION="${{ needs.create-release.outputs.version }}"
257+
258+
# Download SHA256 checksums from the release
259+
curl -L -o darwin-x64.sha256 "https://github.com/v-lawyer/kanuni-cli/releases/download/v${VERSION}/kanuni-darwin-x64.tar.gz.sha256"
260+
curl -L -o darwin-arm64.sha256 "https://github.com/v-lawyer/kanuni-cli/releases/download/v${VERSION}/kanuni-darwin-arm64.tar.gz.sha256"
261+
curl -L -o linux-x64.sha256 "https://github.com/v-lawyer/kanuni-cli/releases/download/v${VERSION}/kanuni-linux-x64.tar.gz.sha256"
262+
curl -L -o linux-arm64.sha256 "https://github.com/v-lawyer/kanuni-cli/releases/download/v${VERSION}/kanuni-linux-arm64.tar.gz.sha256"
263+
264+
# Extract SHA values
265+
DARWIN_X64_SHA=$(cut -d' ' -f1 < darwin-x64.sha256)
266+
DARWIN_ARM64_SHA=$(cut -d' ' -f1 < darwin-arm64.sha256)
267+
LINUX_X64_SHA=$(cut -d' ' -f1 < linux-x64.sha256)
268+
LINUX_ARM64_SHA=$(cut -d' ' -f1 < linux-arm64.sha256)
269+
270+
# Update the formula
271+
sed -i "s/version \".*\"/version \"${VERSION}\"/" Formula/kanuni.rb
272+
sed -i "s|download/v.*/kanuni-darwin-x64|download/v${VERSION}/kanuni-darwin-x64|g" Formula/kanuni.rb
273+
sed -i "s|download/v.*/kanuni-darwin-arm64|download/v${VERSION}/kanuni-darwin-arm64|g" Formula/kanuni.rb
274+
sed -i "s|download/v.*/kanuni-linux-x64|download/v${VERSION}/kanuni-linux-x64|g" Formula/kanuni.rb
275+
sed -i "s|download/v.*/kanuni-linux-arm64|download/v${VERSION}/kanuni-linux-arm64|g" Formula/kanuni.rb
276+
277+
# Commit and push
278+
git config user.name "GitHub Actions"
279+
git config user.email "actions@github.com"
280+
git add Formula/kanuni.rb
281+
git commit -m "Update kanuni to ${VERSION}"
282+
git push
254283
continue-on-error: true

Dockerfile

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
1-
# Multi-stage build for Kanuni CLI
1+
# Multi-stage build for Kanuni CLI with cargo-chef for caching
22
# Supports both AMD64 and ARM64 architectures
33

4-
# Build stage
4+
# Stage 1: Planner
5+
FROM rust:slim AS planner
6+
RUN cargo install cargo-chef
7+
WORKDIR /build
8+
COPY Cargo.toml ./
9+
COPY src ./src
10+
RUN cargo chef prepare --recipe-path recipe.json
11+
12+
# Stage 2: Cacher
13+
FROM rust:slim AS cacher
14+
RUN cargo install cargo-chef
15+
WORKDIR /build
16+
RUN apt-get update && apt-get install -y \
17+
pkg-config \
18+
libssl-dev \
19+
&& rm -rf /var/lib/apt/lists/*
20+
COPY --from=planner /build/recipe.json recipe.json
21+
RUN cargo chef cook --release --recipe-path recipe.json
22+
23+
# Stage 3: Builder
524
FROM rust:slim AS builder
25+
WORKDIR /build
626

727
# Install dependencies for building
828
RUN apt-get update && apt-get install -y \
929
pkg-config \
1030
libssl-dev \
1131
&& rm -rf /var/lib/apt/lists/*
1232

13-
# Create app directory
14-
WORKDIR /build
33+
# Copy cached dependencies
34+
COPY --from=cacher /build/target target
35+
COPY --from=cacher /usr/local/cargo /usr/local/cargo
1536

1637
# Copy project files
1738
COPY Cargo.toml ./
1839
COPY src ./src
1940

20-
# Build the binary
41+
# Build the binary (will use cached dependencies)
2142
RUN cargo build --release
2243

2344
# Runtime stage

0 commit comments

Comments
 (0)