Skip to content

Commit a62e089

Browse files
Dargon789github-advanced-security[bot]sourcery-ai[bot]
authored
Add workflow to publish package distributions (#152)
* Add workflow to publish package distributions Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> * Potential fix for code scanning alert no. 107: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> * Update .github/workflows/Publish-Dists.yml Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> * Update .github/workflows/Publish-Dists.yml Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> --------- Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent b43069d commit a62e089

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish Dists for Packages
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
build-and-push:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- uses: ./.github/actions/install-dependencies
22+
23+
- name: Build package
24+
run: pnpm run build
25+
26+
- name: Prepare dist branch
27+
run: |
28+
PACKAGES=("services/guard" "services/identity-instrument" "services/relayer" "wallet/core" "wallet/primitives" "wallet/wdk" "wallet/dapp-client")
29+
30+
for PACKAGE in "${PACKAGES[@]}"; do
31+
BRANCH="dists/$PACKAGE"
32+
PKG_DIR="packages/$PACKAGE"
33+
34+
echo "📦 Publishing $PACKAGE to $BRANCH"
35+
36+
mkdir -p "/tmp/$PACKAGE"
37+
cp -r "$PKG_DIR"/. "/tmp/$PACKAGE" || true
38+
39+
cd /tmp/$PACKAGE
40+
git init
41+
git checkout -b $BRANCH
42+
43+
git config user.name "github-actions"
44+
git config user.email "actions@github.com"
45+
46+
echo "🔧 Rewriting workspace: deps in package.json..."
47+
node -e '
48+
const fs = require("fs");
49+
const path = require("path");
50+
const pkgPath = path.resolve("package.json");
51+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
52+
const repo = "github:0xsequence/sequence.js";
53+
54+
const versions = {
55+
"@0xsequence/guard": `${repo}#dists/services/guard`,
56+
"@0xsequence/identity-instrument": `${repo}#dists/services/identity-instrument`,
57+
"@0xsequence/relayer": `${repo}#dists/services/relayer`,
58+
"@0xsequence/wallet-core": `${repo}#dists/wallet/core`,
59+
"@0xsequence/wallet-primitives": `${repo}#dists/wallet/primitives`,
60+
"@0xsequence/wallet-wdk": `${repo}#dists/wallet/wdk`,
61+
};
62+
63+
const rewrite = (deps = {}) => {
64+
for (const k in deps) {
65+
if (deps[k].startsWith("workspace:")) {
66+
const version = versions[k];
67+
68+
if (!version) {
69+
console.warn(`No version found for ${k}, skipping...`);
70+
continue;
71+
}
72+
73+
deps[k] = version;
74+
console.log(`→ ${k} → ${deps[k]}`);
75+
}
76+
}
77+
};
78+
79+
['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].forEach((field) => {
80+
if (pkg[field]) {
81+
rewrite(pkg[field]);
82+
}
83+
});
84+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
85+
'
86+
87+
git add .
88+
git commit -m "Build: publish $PACKAGE dist"
89+
90+
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
91+
git push -f origin HEAD:$BRANCH
92+
93+
cd -
94+
done

0 commit comments

Comments
 (0)