diff --git a/.github/workflows/Publish-Dists.yml b/.github/workflows/Publish-Dists.yml new file mode 100644 index 000000000..59b761d5a --- /dev/null +++ b/.github/workflows/Publish-Dists.yml @@ -0,0 +1,94 @@ +name: Publish Dists for Packages + +permissions: + contents: write + +on: + workflow_dispatch: + push: + branches: + - master + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: ./.github/actions/install-dependencies + + - name: Build package + run: pnpm run build + + - name: Prepare dist branch + run: | + PACKAGES=("services/guard" "services/identity-instrument" "services/relayer" "wallet/core" "wallet/primitives" "wallet/wdk" "wallet/dapp-client") + + for PACKAGE in "${PACKAGES[@]}"; do + BRANCH="dists/$PACKAGE" + PKG_DIR="packages/$PACKAGE" + + echo "📦 Publishing $PACKAGE to $BRANCH" + + mkdir -p "/tmp/$PACKAGE" + cp -r "$PKG_DIR"/. "/tmp/$PACKAGE" || true + + cd /tmp/$PACKAGE + git init + git checkout -b $BRANCH + + git config user.name "github-actions" + git config user.email "actions@github.com" + + echo "🔧 Rewriting workspace: deps in package.json..." + node -e ' + const fs = require("fs"); + const path = require("path"); + const pkgPath = path.resolve("package.json"); + const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); + const repo = "github:0xsequence/sequence.js"; + + const versions = { + "@0xsequence/guard": `${repo}#dists/services/guard`, + "@0xsequence/identity-instrument": `${repo}#dists/services/identity-instrument`, + "@0xsequence/relayer": `${repo}#dists/services/relayer`, + "@0xsequence/wallet-core": `${repo}#dists/wallet/core`, + "@0xsequence/wallet-primitives": `${repo}#dists/wallet/primitives`, + "@0xsequence/wallet-wdk": `${repo}#dists/wallet/wdk`, + }; + + const rewrite = (deps = {}) => { + for (const k in deps) { + if (deps[k].startsWith("workspace:")) { + const version = versions[k]; + + if (!version) { + console.warn(`No version found for ${k}, skipping...`); + continue; + } + + deps[k] = version; + console.log(`→ ${k} → ${deps[k]}`); + } + } + }; + + ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].forEach((field) => { + if (pkg[field]) { + rewrite(pkg[field]); + } + }); + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); + ' + + git add . + git commit -m "Build: publish $PACKAGE dist" + + git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git + git push -f origin HEAD:$BRANCH + + cd - + done