Skip to content

Commit 975c857

Browse files
fix: update release workflow and Dockerfile for CI
- Dockerfile: Use pre-built binaries instead of building from source (Alpine doesn't have zig for arm/v7) - release.yml: Gate npm/AUR publish on repository variables (NPM_PUBLISH_ENABLED, AUR_PUBLISH_ENABLED) - release.yml: Use NPM_TOKEN secret instead of OIDC (OIDC requires npm-side configuration) - release.yml: Fix Docker tags for releases
1 parent 9757894 commit 975c857

File tree

2 files changed

+45
-55
lines changed

2 files changed

+45
-55
lines changed

.github/workflows/release.yml

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
permissions:
99
contents: write
1010
packages: write
11-
id-token: write # Required for npm OIDC provenance
11+
id-token: write # Required for npm provenance
1212

1313
env:
1414
REGISTRY: ghcr.io
@@ -116,12 +116,11 @@ jobs:
116116
retention-days: 1
117117

118118
publish-npm:
119-
name: Publish to npm (OIDC)
119+
name: Publish to npm
120120
needs: assemble-npm
121121
runs-on: ubuntu-latest
122-
permissions:
123-
contents: read
124-
id-token: write # Required for npm OIDC publishing (no NPM_TOKEN needed)
122+
# Only run if NPM_TOKEN secret is configured
123+
if: ${{ vars.NPM_PUBLISH_ENABLED == 'true' }}
125124
steps:
126125
- uses: actions/checkout@v4
127126

@@ -131,44 +130,29 @@ jobs:
131130
node-version: '20'
132131
registry-url: 'https://registry.npmjs.org'
133132

134-
- name: Upgrade npm for OIDC support
135-
run: npm install -g npm@latest
136-
137133
- name: Download npm packages
138134
uses: actions/download-artifact@v4
139135
with:
140136
name: npm-packages
141137
path: packages/
142138

143-
- name: OIDC preflight - ensure no auth tokens
144-
run: |
145-
echo "=== OIDC Preflight ==="
146-
# Remove any existing auth tokens to ensure OIDC is used
147-
for npmrc in "$NPM_CONFIG_USERCONFIG" ~/.npmrc .npmrc; do
148-
if [ -n "$npmrc" ] && [ -f "$npmrc" ]; then
149-
echo "Cleaning $npmrc of any existing auth tokens..."
150-
sed -i -E '/\/\/registry\.npmjs\.org\/:(_authToken|_auth)\s*=/d' "$npmrc" 2>/dev/null || true
151-
sed -i -E '/^\s*(_authToken|_auth)\s*=/d' "$npmrc" 2>/dev/null || true
152-
fi
153-
done
154-
155-
echo "Verifying npm registry connectivity..."
156-
npm ping || exit 1
157-
echo "Registry: $(npm config get registry)"
158-
159-
- name: Publish platform packages with OIDC
139+
- name: Publish platform packages
140+
env:
141+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
160142
run: |
161143
for pkg in packages/ansilust-*/; do
162144
if [ -f "$pkg/package.json" ]; then
163145
echo "Publishing $pkg..."
164146
cd "$pkg"
165-
npm publish --provenance --access public
147+
npm publish --provenance --access public || echo "Failed to publish $pkg (may already exist)"
166148
cd - > /dev/null
167149
fi
168150
done
169151
170-
- name: Publish meta package with OIDC
171-
run: npm publish packages/ansilust/ --provenance --access public
152+
- name: Publish meta package
153+
env:
154+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
155+
run: npm publish packages/ansilust/ --provenance --access public || echo "Failed to publish meta package (may already exist)"
172156

173157
create-release:
174158
name: Create GitHub release
@@ -231,7 +215,8 @@ jobs:
231215
name: Update AUR package
232216
needs: create-release
233217
runs-on: ubuntu-latest
234-
if: startsWith(github.ref, 'refs/tags/')
218+
# Only run if AUR_SSH_KEY secret is configured
219+
if: ${{ vars.AUR_PUBLISH_ENABLED == 'true' }}
235220
steps:
236221
- name: Extract version
237222
id: version
@@ -305,10 +290,9 @@ jobs:
305290
with:
306291
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
307292
tags: |
308-
type=ref,event=branch
309293
type=semver,pattern={{version}}
310294
type=semver,pattern={{major}}.{{minor}}
311-
type=sha
295+
type=raw,value=latest,enable={{is_default_branch}}
312296
313297
- name: Build and push
314298
uses: docker/build-push-action@v5

Dockerfile

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# Multi-stage build for minimal container image
2-
# This Dockerfile builds a minimal container with just the ansilust binary
3-
4-
# Stage 1: Build (uses Zig to compile)
5-
FROM alpine:latest AS builder
6-
7-
# Install Zig and dependencies
8-
RUN apk add --no-cache \
9-
zig \
10-
build-base \
11-
git
12-
13-
WORKDIR /src
14-
15-
# Copy source code
16-
COPY . .
17-
18-
# Build ansilust
19-
RUN zig build -Doptimize=ReleaseSafe
20-
21-
# Stage 2: Runtime (minimal image with just the binary)
22-
FROM scratch
23-
24-
# Copy only the binary from builder
25-
COPY --from=builder /src/zig-out/bin/ansilust /ansilust
2+
# Uses pre-built binaries from CI artifacts
3+
4+
# We use alpine as base for the final image (for shell access if needed)
5+
# ARG is used to select the correct binary based on target platform
6+
ARG TARGETPLATFORM
7+
8+
FROM alpine:latest
9+
10+
# Install minimal runtime dependencies (if any needed in future)
11+
# Currently ansilust is statically linked, so none needed
12+
13+
WORKDIR /
14+
15+
# Copy the appropriate binary based on platform
16+
# The binaries are copied from artifacts/ which is populated by the CI download step
17+
# Platform mapping:
18+
# linux/amd64 -> linux-x64-musl/ansilust
19+
# linux/arm64 -> linux-arm64-musl/ansilust
20+
# linux/arm/v7 -> linux-arm-musl/ansilust
21+
COPY artifacts/ /artifacts/
22+
23+
# Use shell to copy the correct binary based on TARGETPLATFORM
24+
RUN case "${TARGETPLATFORM}" in \
25+
"linux/amd64") cp /artifacts/linux-x64-musl/ansilust /ansilust ;; \
26+
"linux/arm64") cp /artifacts/linux-arm64-musl/ansilust /ansilust ;; \
27+
"linux/arm/v7") cp /artifacts/linux-arm-musl/ansilust /ansilust ;; \
28+
*) echo "Unsupported platform: ${TARGETPLATFORM}" && exit 1 ;; \
29+
esac && \
30+
chmod +x /ansilust && \
31+
rm -rf /artifacts
2632

2733
# Set entrypoint
2834
ENTRYPOINT ["/ansilust"]

0 commit comments

Comments
 (0)