Skip to content

Commit d836eed

Browse files
ci: add proper multi-platform release workflow
1 parent 0dd9410 commit d836eed

1 file changed

Lines changed: 105 additions & 90 deletions

File tree

.github/workflows/release.yml

Lines changed: 105 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,152 @@
11
name: Release
22

3-
# DISABLED: Uncomment the 'on' block below to enable releases
4-
# on:
5-
# push:
6-
# tags:
7-
# - 'v*'
8-
93
on:
10-
workflow_dispatch: # Manual trigger only for now
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version to release (e.g., 0.2.0)'
11+
required: true
12+
type: string
1113

1214
env:
1315
CARGO_TERM_COLOR: always
14-
REGISTRY: ghcr.io
15-
IMAGE_NAME: ${{ github.repository_owner }}/sentinel-js
16+
BINARY_NAME: sentinel-js-agent
1617

1718
jobs:
18-
publish:
19-
runs-on: ubuntu-latest
20-
if: false # Disabled - set to true to enable crates.io publishing
21-
steps:
22-
- uses: actions/checkout@v4
23-
24-
- name: Install Rust
25-
uses: dtolnay/rust-toolchain@stable
26-
27-
- name: Publish to crates.io
28-
run: cargo publish
29-
env:
30-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
31-
continue-on-error: true
32-
3319
build:
34-
runs-on: ubuntu-latest
35-
if: false # Disabled - set to true to enable builds
20+
name: Build ${{ matrix.target }}
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- target: x86_64-unknown-linux-gnu
27+
os: ubuntu-latest
28+
artifact: linux-x86_64
29+
- target: aarch64-unknown-linux-gnu
30+
os: ubuntu-latest
31+
artifact: linux-aarch64
32+
cross: true
33+
- target: aarch64-apple-darwin
34+
os: macos-latest
35+
artifact: darwin-aarch64
3636

3737
steps:
3838
- uses: actions/checkout@v4
3939

4040
- name: Install Rust
4141
uses: dtolnay/rust-toolchain@stable
42+
with:
43+
targets: ${{ matrix.target }}
4244

43-
- name: Install build dependencies
45+
- name: Install cross-compilation tools
46+
if: matrix.cross
4447
run: |
4548
sudo apt-get update
46-
sudo apt-get install -y protobuf-compiler
47-
48-
- name: Build release binary
49-
run: |
50-
cargo build --release
51-
strip target/release/sentinel-js-agent
49+
sudo apt-get install -y gcc-aarch64-linux-gnu
50+
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
5251
53-
- name: Prepare artifacts
54-
run: |
55-
mkdir -p artifacts
56-
cp target/release/sentinel-js-agent artifacts/
57-
58-
- name: Upload artifacts
59-
uses: actions/upload-artifact@v4
52+
- name: Cache cargo
53+
uses: actions/cache@v4
6054
with:
61-
name: sentinel-js-linux-amd64
62-
path: artifacts/
63-
retention-days: 7
64-
65-
docker:
66-
needs: build
67-
runs-on: ubuntu-latest
68-
if: false # Disabled - set to true to enable Docker builds
69-
permissions:
70-
contents: read
71-
packages: write
72-
73-
steps:
74-
- uses: actions/checkout@v4
55+
path: |
56+
~/.cargo/bin/
57+
~/.cargo/registry/index/
58+
~/.cargo/registry/cache/
59+
~/.cargo/git/db/
60+
target/
61+
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
62+
restore-keys: |
63+
${{ runner.os }}-${{ matrix.target }}-cargo-
7564
76-
- name: Download AMD64 artifact
77-
uses: actions/download-artifact@v4
78-
with:
79-
name: sentinel-js-linux-amd64
80-
path: artifacts/linux-amd64
65+
- name: Build release binary
66+
run: cargo build --release --target ${{ matrix.target }}
8167

82-
- name: Prepare artifact
83-
run: chmod +x artifacts/linux-amd64/sentinel-js-agent
68+
- name: Strip binary (Linux native)
69+
if: matrix.target == 'x86_64-unknown-linux-gnu'
70+
run: strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
8471

85-
- name: Set up Docker Buildx
86-
uses: docker/setup-buildx-action@v3
72+
- name: Strip binary (Linux cross)
73+
if: matrix.cross
74+
run: aarch64-linux-gnu-strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
8775

88-
- name: Log in to Container Registry
89-
uses: docker/login-action@v3
90-
with:
91-
registry: ${{ env.REGISTRY }}
92-
username: ${{ github.actor }}
93-
password: ${{ secrets.GITHUB_TOKEN }}
76+
- name: Strip binary (macOS)
77+
if: contains(matrix.target, 'darwin')
78+
run: strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}
9479

95-
- name: Extract version
80+
- name: Determine version
9681
id: version
97-
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
82+
run: |
83+
if [ -n "${{ inputs.version }}" ]; then
84+
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
85+
else
86+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
87+
fi
9888
99-
- name: Build and push image
100-
uses: docker/build-push-action@v5
89+
- name: Package binary
90+
run: |
91+
mkdir -p dist
92+
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/
93+
cd dist
94+
tar -czvf ${{ env.BINARY_NAME }}-${{ steps.version.outputs.version }}-${{ matrix.artifact }}.tar.gz ${{ env.BINARY_NAME }}
95+
96+
- name: Upload artifact
97+
uses: actions/upload-artifact@v4
10198
with:
102-
context: artifacts/linux-amd64
103-
file: ./Dockerfile
104-
target: prebuilt
105-
platforms: linux/amd64
106-
push: true
107-
tags: |
108-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
109-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
110-
provenance: false
99+
name: ${{ matrix.artifact }}
100+
path: dist/*.tar.gz
101+
retention-days: 1
111102

112103
release:
113-
needs: [build, docker]
104+
name: Create Release
105+
needs: build
114106
runs-on: ubuntu-latest
115-
if: false # Disabled - set to true to enable releases
116107
permissions:
117108
contents: write
118109

119110
steps:
120111
- uses: actions/checkout@v4
121112

122-
- name: Download AMD64 artifact
113+
- name: Determine version
114+
id: version
115+
run: |
116+
if [ -n "${{ inputs.version }}" ]; then
117+
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
118+
echo "tag=v${{ inputs.version }}" >> $GITHUB_OUTPUT
119+
else
120+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
121+
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
122+
fi
123+
124+
- name: Download all artifacts
123125
uses: actions/download-artifact@v4
124126
with:
125-
name: sentinel-js-linux-amd64
126-
path: artifacts/linux-amd64
127+
path: artifacts
128+
129+
- name: List artifacts
130+
run: find artifacts -type f
127131

128-
- name: Prepare release files
132+
- name: Collect release files
129133
run: |
130134
mkdir -p release
131-
mv artifacts/linux-amd64/sentinel-js-agent release/sentinel-js-agent-linux-amd64
135+
find artifacts -name '*.tar.gz' -exec mv {} release/ \;
136+
ls -la release/
137+
138+
- name: Delete existing release if exists
139+
run: gh release delete "${{ steps.version.outputs.tag }}" --yes || true
140+
env:
141+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132142

133143
- name: Create release
134-
uses: softprops/action-gh-release@v1
144+
uses: softprops/action-gh-release@v2
135145
with:
146+
tag_name: ${{ steps.version.outputs.tag }}
147+
name: v${{ steps.version.outputs.version }}
136148
files: release/*
149+
fail_on_unmatched_files: true
137150
generate_release_notes: true
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)