forked from 0xsequence/sequence.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Add workflow to publish package distributions #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af72299
Add workflow to publish package distributions
Dargon789 3084a54
Potential fix for code scanning alert no. 107: Workflow does not cont…
Dargon789 81bd07f
Update .github/workflows/Publish-Dists.yml
Dargon789 e8f8712
Update .github/workflows/Publish-Dists.yml
Dargon789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.