Skip to content

Create preview.yml#205

Open
peersky wants to merge 1 commit intomainfrom
peersky-patch-3
Open

Create preview.yml#205
peersky wants to merge 1 commit intomainfrom
peersky-patch-3

Conversation

@peersky
Copy link
Member

@peersky peersky commented Oct 6, 2025

This should create a preview package each time when release PR is updated

Summary by CodeRabbit

  • Chores
    • Added a deploy preview workflow for pull requests to produce prerelease packages and publish artifacts to the registry.
    • Ensures only one preview runs per pull request and skips forked contributions.
    • Exposes preview version and deployment details as workflow outputs for easier tracking.

@changeset-bot
Copy link

changeset-bot bot commented Oct 6, 2025

⚠️ No Changeset found

Latest commit: b3086ea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds a GitHub Actions workflow (Deploy Preview) for PRs to changeset-release/main that builds with Node 20, prepares a prerelease via Changesets, bumps version, extracts the version, and publishes dist artifacts to npm. Includes concurrency keyed by PR, fork-skip guard, and exposes outputs for deployment details and package version.

Changes

Cohort / File(s) Summary
CI workflow: Deploy Preview
\.github/workflows/preview.yml
New workflow triggered on PR events to changeset-release/main; guarded against forks; runs checkout, local setup action, Node 20 with pnpm cache, builds SDK, configures git, creates empty changeset, enters prerelease mode, versions via Changesets, extracts package version from package.json, publishes dist with changeset publish --no-git-checks; sets outputs deployment_details and contracts_package_version; uses NPM and GitHub tokens; concurrency scoped to PR number.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Developer
    participant GH as GitHub
    participant WF as Deploy Preview Workflow
    participant Job as deploy_preview (ubuntu-latest)
    participant NPM as npm Registry

    Dev->>GH: Open/Reopen/Synchronize PR -> base: changeset-release/main
    GH->>WF: Trigger workflow (if not from fork)
    alt Forked PR
        WF-->>Dev: Skipped (guard condition)
    else Internal PR
        WF->>Job: Start job (concurrency per PR)
        Job->>Job: actions/checkout (fetch-depth: 0)
        Job->>Job: Local setup action (.github/actions/setup)
        Job->>Job: Setup Node 20.x (pnpm cache, registry)
        Job->>Job: Build SDK
        Job->>Job: Configure git user/email
        Job->>Job: Create empty changeset
        Job->>Job: Enter prerelease mode (PR-scoped)
        Job->>Job: Version via Changesets
        Job->>Job: Read package.json -> extract version
        Job->>NPM: Publish dist (changeset publish --no-git-checks) using NPM_TOKEN
        NPM-->>Job: Publish result
        Job-->>WF: Set outputs (deployment_details, contracts_package_version)
        WF-->>Dev: Workflow completed
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through YAML fields so bright,
Spinning builds in PR light.
Version bumps and tokens true,
Publish hops to npm, woo!
Concurrency burrow keeps it neat—
Preview treats in every beat.
Thump-thump: a shipping feat! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Create preview.yml” directly reflects the primary change of adding a new GitHub Actions workflow file named preview.yml, making it concise and clearly related to the changeset. It succinctly conveys the main intent without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch peersky-patch-3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +13 to +62
runs-on: ubuntu-latest
concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
if: ${{ !github.event.pull_request.head.repo.fork }}
outputs:
deployment_details: ${{ steps.export_addresses.outputs.deployment_details }}
contracts_package_version: ${{ steps.get_version.outputs.package_version }}
steps:
- name: 'Checkout Code'
uses: actions/checkout@v4
with:
fetch-depth: 0 # Necessary for changesets to work correctly

- uses: './.github/setup'

- name: 'Setup Node.js for npm'
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'

- name: 'Build SDK'
run: pnpm build

- name: Setup git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Create empty changeset
run: pnpm changeset add --empty

- name: Enter prerelease mode
run: pnpm changeset pre enter pr-${{ github.event.pull_request.number }}

- name: Bump versions
run: pnpm changeset version

- name: Get package version
id: get_version
run: |
VERSION=$(jq -r .version package.json)
echo "package_version=$VERSION" >> $GITHUB_OUTPUT

- name: 'Publish Preview to npm'
run: cd ./dist && pnpm changeset publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

The best way to fix this problem is to add a permissions key with the lowest necessary privileges. Given the steps shown, there is no evidence in the snippet that the workflow requires write access to the repository (no steps create or push commits, create issues, or open pull requests). Therefore, setting permissions: contents: read at the job level is a safe and minimal fix. This change should be inserted directly below either the workflow's root (after the name line) or within the affected job (deploy_and_publish_contracts_preview) definition. As there may be multiple jobs in other contexts and the flagged line is within the job, adding permissions at the job level (line 13) covers only this job. Insert the permissions block immediately after runs-on: ubuntu-latest (line 13) to minimize impact and follow least privilege.

Suggested changeset 1
.github/workflows/preview.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml
--- a/.github/workflows/preview.yml
+++ b/.github/workflows/preview.yml
@@ -11,6 +11,8 @@
 jobs:
   deploy_and_publish_contracts_preview:
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
     concurrency:
      group: preview-${{ github.event.pull_request.number }}
      cancel-in-progress: true
EOF
@@ -11,6 +11,8 @@
jobs:
deploy_and_publish_contracts_preview:
runs-on: ubuntu-latest
permissions:
contents: read
concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/preview.yml (1)

7-62: Scope the GITHUB_TOKEN permissions

We’re relying on the default broad token scopes. Add an explicit permissions block (e.g., contents: read) and elevate only what this job truly needs (such as packages: write if required) to stay compliant with GitHub’s least-privilege guidance.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68cb18d and b3086ea.

📒 Files selected for processing (1)
  • .github/workflows/preview.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/preview.yml

19-19: property "export_addresses" is not defined in object type {get_version: {conclusion: string; outcome: string; outputs: {string => string}}}

(expression)

🪛 GitHub Check: CodeQL
.github/workflows/preview.yml

[warning] 13-62: Workflow does not contain permissions
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}

Comment on lines +19 to +20
deployment_details: ${{ steps.export_addresses.outputs.deployment_details }}
contracts_package_version: ${{ steps.get_version.outputs.package_version }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Define the export_addresses step or drop the job output

steps.export_addresses never exists, so deployment_details is always blank and anything consuming this output will silently get nothing. Either add the missing step (with id: export_addresses) that sets deployment_details, or remove the output until it’s implemented.

🧰 Tools
🪛 actionlint (1.7.7)

19-19: property "export_addresses" is not defined in object type {get_version: {conclusion: string; outcome: string; outputs: {string => string}}}

(expression)

🤖 Prompt for AI Agents
.github/workflows/preview.yml around lines 19-20: the job output references
steps.export_addresses.outputs.deployment_details but no step with id:
export_addresses exists, so deployment_details is always empty; either add a
step in the job with id: export_addresses that sets the deployment_details
output (using echo "::set-output name=deployment_details::value" or the newer
GITHUB_OUTPUT method) before referencing it, or remove the deployment_details
output line entirely until that step is implemented; make the change
consistently across jobs that consume this output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant