-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (135 loc) · 4.31 KB
/
Copy pathrelease.yml
File metadata and controls
158 lines (135 loc) · 4.31 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
name: Release
on:
push:
branches: [main]
permissions:
contents: write
issues: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
jobs:
# First, check if a release is needed
check-release:
name: Check Release
runs-on: ubuntu-latest
outputs:
new_release: ${{ steps.semantic.outputs.new_release_published }}
new_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci --omit=optional
- name: Semantic Release (dry run)
id: semantic
uses: cycjimmy/semantic-release-action@v4
with:
dry_run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Build binaries for all platforms
build:
name: Build (${{ matrix.platform }})
needs: check-release
if: needs.check-release.outputs.new_release == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: aarch64-apple-darwin
platform: darwin-arm64
binary: treble
- os: macos-latest
target: x86_64-apple-darwin
platform: darwin-x64
binary: treble
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
platform: linux-x64
binary: treble
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
platform: linux-arm64
binary: treble
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Set version in Cargo.toml
run: sed -i'' -e 's/^version = ".*"/version = "${{ needs.check-release.outputs.new_version }}"/' Cargo.toml
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build
run: cargo build --release --target ${{ matrix.target }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Prepare binary
shell: bash
run: |
mkdir -p dist/${{ matrix.platform }}
cp target/${{ matrix.target }}/release/${{ matrix.binary }} dist/${{ matrix.platform }}/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.platform }}
path: dist/${{ matrix.platform }}
# Publish release and npm packages
publish:
name: Publish
needs: [check-release, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci --omit=optional
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare platform packages
run: |
for platform in darwin-arm64 darwin-x64 linux-x64 linux-arm64; do
mkdir -p npm/$platform/bin
if [ -d "artifacts/binary-$platform" ]; then
cp artifacts/binary-$platform/* npm/$platform/bin/
chmod +x npm/$platform/bin/* 2>/dev/null || true
fi
done
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
- name: Publish platform packages
run: |
for platform in darwin-arm64 darwin-x64 linux-x64 linux-arm64; do
cd npm/$platform
npm publish --access public || true
cd ../..
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish main package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}