-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (144 loc) · 5.81 KB
/
Copy pathpublish.yml
File metadata and controls
168 lines (144 loc) · 5.81 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
165
166
167
168
# Publish @indexnetwork/cli prereleases from dev and stable releases from main.
# Builds native binaries for all platforms before publishing.
# Skips if the version in package.json is already on npm.
#
# Requires: org-level NPM_TOKEN secret.
name: Publish
on:
push:
branches:
- dev
- main
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
jobs:
# ── Check version ─────────────────────────────────────────────────────
check:
runs-on: ubuntu-latest
name: Check if version needs publishing
outputs:
skip: ${{ steps.check.outputs.skip }}
version: ${{ steps.check.outputs.version }}
tag: ${{ steps.meta.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Determine publish version and tag
id: meta
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
if [ "${GITHUB_REF_NAME}" = "dev" ]; then
PUBLISH_VERSION="${BASE_VERSION}-rc.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}"
NPM_TAG="rc"
else
PUBLISH_VERSION="${BASE_VERSION}"
NPM_TAG="latest"
fi
echo "version=${PUBLISH_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${NPM_TAG}" >> "$GITHUB_OUTPUT"
- name: Check if version already published
id: check
run: |
NAME=$(node -p "require('./package.json').name")
VERSION="${{ steps.meta.outputs.version }}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if npm view "${NAME}@${VERSION}" version &>/dev/null; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already published — skipping."
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# ── Build platform binaries ───────────────────────────────────────────
build:
needs: check
if: needs.check.outputs.skip == 'false'
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
target: bun-linux-x64
npm-dir: linux-x64
binary-name: index-linux-x64
- os: ubuntu-24.04-arm
target: bun-linux-arm64
npm-dir: linux-arm64
binary-name: index-linux-arm64
- os: macos-latest
target: bun-darwin-x64
npm-dir: darwin-x64
binary-name: index-darwin-x64
- os: macos-latest
target: bun-darwin-arm64
npm-dir: darwin-arm64
binary-name: index-darwin-arm64
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.npm-dir }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Compile binary
run: |
mkdir -p dist
bun build src/main.ts --compile --target=${{ matrix.target }} --outfile dist/${{ matrix.binary-name }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.npm-dir }}
path: dist/${{ matrix.binary-name }}
retention-days: 1
# ── Publish all packages to npm ───────────────────────────────────────
publish:
needs: [check, build]
if: needs.check.outputs.skip == 'false'
runs-on: ubuntu-latest
name: Publish to npm
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: bun install
- name: Build JS fallback bundle
run: |
mkdir -p dist
bun build src/main.ts --outdir dist --target node --format esm --entry-naming index.js
- name: Download all platform binaries
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Place binaries into platform packages
run: |
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
mkdir -p "npm/$dir/bin"
cp "artifacts/$dir/index-$dir" "npm/$dir/bin/index"
chmod +x "npm/$dir/bin/index"
done
- name: Rewrite package versions for publish
run: |
VERSION="${{ needs.check.outputs.version }}"
node -e "const fs=require('fs'); const path='package.json'; const pkg=JSON.parse(fs.readFileSync(path,'utf8')); pkg.version=process.argv[1]; Object.keys(pkg.optionalDependencies||{}).forEach(k=>pkg.optionalDependencies[k]=process.argv[1]); fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');" "$VERSION"
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
node -e "const fs=require('fs'); const path='npm/' + process.argv[1] + '/package.json'; const pkg=JSON.parse(fs.readFileSync(path,'utf8')); pkg.version=process.argv[2]; fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');" "$dir" "$VERSION"
done
- name: Publish platform packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
echo "Publishing @indexnetwork/cli-$dir..."
npm publish --access public --tag "${{ needs.check.outputs.tag }}" "./npm/$dir"
done
- name: Publish main package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public --tag "${{ needs.check.outputs.tag }}"