Skip to content

Commit 2c9828f

Browse files
committed
Adding publish dists github action
1 parent c045e08 commit 2c9828f

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed

.github/workflows/publish-dists.yml

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,71 @@ on:
99
jobs:
1010
build-and-push:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
package:
15-
- wallet-core
16-
- wallet-primitives
17-
- wallet-wdk
1812

1913
steps:
20-
- name: Checkout repo
21-
uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
2215
with:
2316
fetch-depth: 0
2417

25-
- name: Set up Node
26-
uses: actions/setup-node@v3
27-
with:
28-
node-version: 20
29-
30-
- name: Install deps
31-
run: npm ci
18+
- uses: ./.github/actions/install-dependencies
3219

3320
- name: Build package
34-
run: npm run build --workspace=packages/wallet/${{ matrix.package }}
21+
run: pnpm run build
3522

3623
- name: Prepare dist branch
3724
run: |
38-
PACKAGE=${{ matrix.package }}
39-
BRANCH="dists/$PACKAGE"
40-
PKG_DIR="packages/wallet/$PACKAGE"
41-
42-
git config user.name "github-actions"
43-
git config user.email "[email protected]"
44-
45-
mkdir /tmp/$PACKAGE
46-
cp -r $PKG_DIR/* /tmp/$PACKAGE
47-
cp -r $PKG_DIR/.* /tmp/$PACKAGE 2>/dev/null || true
48-
49-
cd /tmp/$PACKAGE
50-
git init
51-
git checkout -b $BRANCH
52-
git remote add origin https://github.com/${{ github.repository }}.git
53-
git add .
54-
git commit -m "Build: publish $PACKAGE dist"
55-
git push -f origin HEAD:$BRANCH
25+
PACKAGES=("services/identity-instrument" "wallet/core" "wallet/primitives" "wallet/wdk")
26+
27+
for PACKAGE in "${PACKAGES[@]}"; do
28+
BRANCH="dists/$PACKAGE"
29+
PKG_DIR="packages/$PACKAGE"
30+
31+
echo "📦 Publishing $PACKAGE to $BRANCH"
32+
33+
mkdir -p /tmp/$PACKAGE
34+
shopt -s dotglob
35+
cp -r $PKG_DIR/* /tmp/$PACKAGE || true
36+
37+
cd /tmp/$PACKAGE
38+
git init
39+
git checkout -b $BRANCH
40+
41+
git config user.name "github-actions"
42+
git config user.email "[email protected]"
43+
44+
echo "🔧 Rewriting workspace: deps in package.json..."
45+
node -e '
46+
const fs = require("fs");
47+
const path = require("path");
48+
const pkgPath = path.resolve("package.json");
49+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
50+
const repo = "0xsequence/sequence.js";
51+
const prefix = "dists/";
52+
53+
const branches = {
54+
"@0xsequence/identity-instrument": "dists/services/identity-instrument",
55+
"@0xsequence/wallet-core": "dists/wallet/core",
56+
"@0xsequence/wallet-primitives": "dists/wallet/primitives",
57+
"@0xsequence/wallet-wdk": "dists/wallet/wdk",
58+
};
59+
60+
const rewrite = (deps = {}) => {
61+
for (const k in deps) {
62+
if (deps[k].startsWith("workspace:")) {
63+
deps[k] = `github:${repo}#${branches[k]}`;
64+
console.log(`→ ${k} → ${deps[k]}`);
65+
}
66+
}
67+
};
68+
rewrite(pkg.dependencies);
69+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
70+
'
71+
72+
git add .
73+
git commit -m "Build: publish $PACKAGE dist"
74+
75+
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
76+
git push -f origin HEAD:$BRANCH
77+
78+
cd -
79+
done

0 commit comments

Comments
 (0)