Skip to content

Shopify/snapit

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

A screenshot of the snapit command being ran

/snapit

Create a snapshot NPM release with /snapit comment in a PR

This GitHub action allows for automation of Changesets Snapshot Release with the comment /snapit in a pull request. Snapshot releases are a way to release your changes for testing without updating the versions.

Usage

Create a .github/workflows/snapit.yml file with the following contents.

Deploy to NPM

name: Snapit

on:
  issue_comment:
    types:
      - created

jobs:
  snapit:
    name: Snapit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout default branch
        uses: actions/checkout@v4

      - name: Create snapshot version
        uses: Shopify/snapit@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        with:
          build_script: pnpm build # Optional
          trigger_comment: /snapit # Default value not required

Deploy to branch

This is useful when orchestrating releases outside of GitHub actions or with other package registries.

name: Snapit

on:
  issue_comment:
    types:
      - created

jobs:
  snapit:
    name: Snapit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout default branch
        uses: actions/checkout@v4

      - name: Create snapshot version
        uses: Shopify/snapit@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          branch: snapshot-release
          trigger_comment: /snapit # Default value not required

Environment Variables

GITHUB_TOKEN

The GITHUB_TOKEN is needed for changesets to look up the current changeset when creating a snapshot. You can use the automatically created ${{ secrets.GITHUB_TOKEN }} to authenticate in the workflow job.

NPM_TOKEN

A NPM_TOKEN needs to be created and added to the repository to publish packages from GitHub actions to the npm registry.

GitHub Action Inputs

Inputs (All Optional) Description
trigger_comment Default: /snapit. Comma seperated list of comments to write to trigger the creation of a snapshot.
comment_prefix Custom message to add to the beginning of the release GitHub comment. Default: "Test the snapshots by updating your package.json with the newly published versions:"
comment_suffix Custom message to add to the end of the release GitHub comment.
comment_packages Filter to include specific packages in the release GitHub comment. Separate multiple packages with commas.
comment_is_global If true, the generated GitHub comment will show the command to install your packages globally. Otherwise, shows a JSON example to update local dependencies.
cwd If specified, the action will run all commands for snapit in the specified directory.
branch Push the changes to a branch instead of publishing to the NPM registry.
post_install_script If specified, will run a script after dependencies are installed.
build_script The build script to run before publishing.
release_branch Default: changeset-release/main. If specified, will use this branch name in place of the default

Contributing

To contribute a change, bug fix or feature to snapit:

  1. Make a new branch my-branch
  2. Make the changes you need
  3. Run npm run build
  4. Push your changes to the branch
  5. In your repositories main branch point the .github/snapit.yml file to the shopify/snapit branch uses: Shopify/snapit@my-branch
  6. Create a pull request with changeset and write /snapit as a comment in the pull request

Changelog

v0.0.15

  • Add release_branch to configure the default release branch. Default is changeset-release/main.

v0.0.14

  • Improved error logging
  • build_script is now optional
  • Adds optional working_directory to run snap it commands from
  • Adds optional post_install script

v0.0.13

  • Add global_install to show global npm installation instructions on the generated GitHub comment.
  • Add github_comment_included_packages to allow including just some packages on the generated GitHub comment.
  • Rename custom_message to custom_message_prefix
  • Add custom_message_suffix

v0.0.12

  • Fix typo in snapshot comment message

v0.0.11

  • Capture snapshot versions before build_script

v0.0.10

  • Disallow private packages from being published
  • Check for snapshots before getting the timestamp
  • Skip packages that do not have a name or version

v0.0.9

  • Add branch to publish to other package services
  • Add custom_message to add a markdown string to the generated GitHub comment
  • Add missing comma to GitHub comment seperating versions

v0.0.8

  • Add space between package name and version in GitHub comment

v0.0.7

  • Simplify GitHub comment

v0.0.6

  • Add support for pnpm

v0.0.5

  • Reorder build_script to run after changeset version

v0.0.4

  • Improve error handling
  • Update action to use TypeScript

v0.0.3

  • Fix issue with Version Packages PRs not resetting changesets
  • Allow build_script to have && when multiple scripts are needed
  • Make build_script optional for projects that do not need a build

v0.0.2

  • Install comment recommends yarn add if the project has a yarn.lock
  • Fix issue with PR changes not being included in snapshot version
  • Optionally change the comment to trigger the snapshot with the comment_command input

v0.0.1

  • Initial version used by @shopify/polaris

About

Create a snapshot NPM release with /snapit comment in a PR

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 17