-
Notifications
You must be signed in to change notification settings - Fork 3
164 lines (148 loc) · 4.95 KB
/
Copy pathpublish.yml
File metadata and controls
164 lines (148 loc) · 4.95 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
159
160
161
162
163
164
name: Publish npm
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: read
id-token: write
jobs:
publish-binaries:
name: Publish ${{ matrix.package }}
runs-on: ${{ matrix.runner }}
environment: npm
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
package: linux-x64
os: linux
cpu: x64
binary: agent-database-cli
- target: aarch64-unknown-linux-gnu
runner: ubuntu-latest
package: linux-arm64
os: linux
cpu: arm64
binary: agent-database-cli
- target: x86_64-apple-darwin
runner: macos-14
package: darwin-x64
os: darwin
cpu: x64
binary: agent-database-cli
- target: aarch64-apple-darwin
runner: macos-14
package: darwin-arm64
os: darwin
cpu: arm64
binary: agent-database-cli
- target: x86_64-pc-windows-msvc
runner: windows-latest
package: win32-x64
os: win32
cpu: x64
binary: agent-database-cli.exe
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Upgrade npm
shell: bash
run: npm install -g npm@11.5.1
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install Linux ARM64 linker
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Configure Linux ARM64 linker
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"
- name: Build binary
run: cargo build --release --bin agent-database-cli --target ${{ matrix.target }}
- name: Stage binary package
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="$(node -p "require('./package.json').version")"
fi
PKG_DIR="packages/${{ matrix.package }}"
mkdir -p "$PKG_DIR/bin"
cp "target/${{ matrix.target }}/release/${{ matrix.binary }}" "$PKG_DIR/bin/${{ matrix.binary }}"
chmod +x "$PKG_DIR/bin/${{ matrix.binary }}" || true
sed \
-e "s#__NAME__#@agent-database-cli/${{ matrix.package }}#g" \
-e "s#__VERSION__#${VERSION}#g" \
-e "s#__TARGET__#${{ matrix.target }}#g" \
-e "s#__OS__#${{ matrix.os }}#g" \
-e "s#__CPU__#${{ matrix.cpu }}#g" \
npm/package-template.json > "$PKG_DIR/package.json"
- name: Publish binary package
shell: bash
working-directory: packages/${{ matrix.package }}
run: |
set -euo pipefail
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="$(node -p "require('../../package.json').version")"
fi
PACKAGE="@agent-database-cli/${{ matrix.package }}"
if npm publish --access public; then
exit 0
fi
if [ "$(npm view "${PACKAGE}@${VERSION}" version 2>/dev/null || true)" = "${VERSION}" ]; then
echo "${PACKAGE}@${VERSION} already published, skip"
exit 0
fi
exit 1
publish-main:
name: Publish main package
runs-on: ubuntu-latest
environment: npm
needs: publish-binaries
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: npm
- name: Upgrade npm
run: npm install -g npm@11.5.1
- name: Install main package dependencies
run: npm install --omit=optional --package-lock=false --ignore-scripts --no-audit --no-fund
- name: Publish main package
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="$(node -p "require('./package.json').version")"
fi
PACKAGE="agent-database-cli"
if npm publish --access public; then
exit 0
fi
if [ "$(npm view "${PACKAGE}@${VERSION}" version 2>/dev/null || true)" = "${VERSION}" ]; then
echo "${PACKAGE}@${VERSION} already published, skip"
exit 0
fi
exit 1