Add workflow to publish package distributions#152
Conversation
Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Reviewer's GuideIntroduces a GitHub Actions workflow that builds specific packages and publishes their built distributions to dedicated dist branches, rewriting workspace dependencies to point at those dist branches before force-pushing them to the repository. Sequence diagram for triggering and executing the dist publishing workflowsequenceDiagram
actor Dev
participant GitHub
participant Workflow_Publish_Dists as Workflow_Publish_Dists
participant Runner as GitHub_Runner
participant Repo as GitHub_Repository
Dev->>GitHub: Push to master or manual workflow_dispatch
GitHub->>Workflow_Publish_Dists: Trigger workflow
Workflow_Publish_Dists->>Runner: Start job build-and-push
Runner->>Repo: actions/checkout@v4 (fetch-depth 0)
Runner->>Runner: Run install-dependencies action
Runner->>Runner: Run pnpm run build
loop For each PACKAGE in PACKAGES
Runner->>Runner: Copy packages/PACKAGE to /tmp/PACKAGE
Runner->>Runner: git init and checkout branch dists/PACKAGE
Runner->>Runner: Rewrite workspace deps in package.json
Runner->>Repo: git push -f HEAD:dists/PACKAGE using GITHUB_TOKEN
end
Runner-->>Workflow_Publish_Dists: Job build-and-push completed
Workflow_Publish_Dists-->>GitHub: Report workflow status
GitHub-->>Dev: Show workflow result in checks
Flow diagram for per-package dist branch preparation and publishingflowchart TD
A[Start job build-and-push] --> B[Checkout repo with fetch-depth 0]
B --> C[Install dependencies via local action]
C --> D[Run pnpm run build]
D --> E[Iterate PACKAGES array]
subgraph Loop_per_PACKAGE
direction TB
E --> F[Set BRANCH to dists/PACKAGE and PKG_DIR to packages/PACKAGE]
F --> G[Create temp dir /tmp/PACKAGE]
G --> H[Copy PKG_DIR contents to temp dir]
H --> I[cd into /tmp/PACKAGE]
I --> J[git init]
J --> K[git checkout -b BRANCH]
K --> L[Configure git user github-actions]
L --> M[Run node script to rewrite workspace deps in package.json]
M --> N[git add .]
N --> O[git commit -m Build: publish PACKAGE dist]
O --> P[git remote add origin with GITHUB_TOKEN]
P --> Q[git push -f origin HEAD:BRANCH]
Q --> R[cd back]
R --> E
end
E --> S[All packages processed]
S --> T[End job]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues, and left some high level feedback:
- The bash step that copies and cd’s into package directories should quote variable expansions (e.g.
cp -r "$PKG_DIR"/* "/tmp/$PACKAGE",cd "/tmp/$PACKAGE") to avoid issues if paths ever contain spaces or unexpected globbing. - The Node script only rewrites
dependencies; if any of these packages reference workspace versions viadevDependencies,peerDependencies, oroptionalDependencies, consider extendingrewriteto cover those fields as well to keep dependency specs consistent across the dist branches.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The bash step that copies and cd’s into package directories should quote variable expansions (e.g. `cp -r "$PKG_DIR"/* "/tmp/$PACKAGE"`, `cd "/tmp/$PACKAGE"`) to avoid issues if paths ever contain spaces or unexpected globbing.
- The Node script only rewrites `dependencies`; if any of these packages reference workspace versions via `devDependencies`, `peerDependencies`, or `optionalDependencies`, consider extending `rewrite` to cover those fields as well to keep dependency specs consistent across the dist branches.
## Individual Comments
### Comment 1
<location> `.github/workflows/Publish-Dists.yml:24` </location>
<code_context>
+ 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")
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider making the shell block fail-fast for safer publishing.
Because the script doesn’t fail on all errors (aside from the explicit `|| true`), a partial or broken publish could slip through. Add `set -euo pipefail` at the top of this `run` block so unexpected failures (git/node/publish) stop the workflow instead of continuing.
Suggested implementation:
```
- name: Prepare dist branch
run: |
set -euo pipefail
PACKAGES=("services/guard" "services/identity-instrument" "services/relayer" "wallet/core" "wallet/primitives" "wallet/wdk" "wallet/dapp-client")
```
If there are further commands that were supposed to be in this `Prepare dist branch` step (e.g., git operations, build/publish commands), they should be appended below the `PACKAGES=(...)` line inside the same `run: |` block so that they also benefit from `set -euo pipefail`.
</issue_to_address>
### Comment 2
<location> `.github/workflows/Publish-Dists.yml:31-35` </location>
<code_context>
+ echo "📦 Publishing $PACKAGE to $BRANCH"
+
+ mkdir -p /tmp/$PACKAGE
+ shopt -s dotglob
+ cp -r $PKG_DIR/* /tmp/$PACKAGE || true
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Avoid relying on bash-specific `shopt` without explicitly pinning the shell.
This step depends on `shopt -s dotglob`, which only works in bash. While `ubuntu-latest` currently defaults to bash, that’s an implicit assumption. To make this robust, either set `shell: bash` for the step or use a more portable pattern like `cp -r "$PKG_DIR"/. "/tmp/$PACKAGE"` so it doesn’t break if the default shell changes.
```suggestion
echo "📦 Publishing $PACKAGE to $BRANCH"
mkdir -p "/tmp/$PACKAGE"
cp -r "$PKG_DIR"/. "/tmp/$PACKAGE" || true
```
</issue_to_address>
### Comment 3
<location> `.github/workflows/Publish-Dists.yml:66-68` </location>
<code_context>
+ if (deps[k].startsWith("workspace:")) {
+ const version = versions[k];
+
+ if (!version) {
+ console.warn(`No version found for ${k}, skipping...`);
+ continue;
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Leaving unknown workspace: deps unchanged may produce invalid published packages.
If a `workspace:` dependency key isn’t in `versions`, it’s only logged and left unchanged. That means the published `package.json` can still contain `workspace:` ranges, which package managers can’t install. Please either fail in this case or replace these with a valid fallback / skip publishing that package so that all published artifacts are installable.
</issue_to_address>
### Comment 4
<location> `.github/workflows/Publish-Dists.yml:77-78` </location>
<code_context>
+ }
+ };
+
+ rewrite(pkg.dependencies);
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
+ '
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Only transforming `dependencies` may miss other workspace references.
The current rewrite only covers `pkg.dependencies`, so any `workspace:` entries in `devDependencies`, `peerDependencies`, or `optionalDependencies` will remain unchanged and unusable in the dist output. Consider invoking `rewrite` for each of these fields to ensure all workspace references are handled consistently.
```suggestion
['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].forEach((field) => {
if (pkg[field]) {
rewrite(pkg[field]);
}
});
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ain 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>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
Summary by Sourcery
CI: