Giter Club home page Giter Club logo

yarn-changeset-action's Introduction

Changesets Release Action

This is fork for Yarn 2+ (only) support

Solving problems of original action:

  • It doesn't update lockfile on version bumping
  • It doesn't handle workspace protocol on publishing

This action for Changesets creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on your configured baseBranch, the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.

Usage

Inputs

  • autoPublish - The flag to enable auto-publishing packages. Default to false
  • dedupe - The flag to enable auto-deduplication of dependencies. Default to false
  • commit - The commit message to use. Default to Version Packages
  • title - The pull request title. Default to Version Packages
  • setupGitUser - Sets up the git user for commits as "github-actions[bot]". Default to true
  • createGithubReleases - A boolean value to indicate whether to create Github releases after publish or not. Default to true
  • cwd - Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()

Outputs

  • published - A boolean value to indicate whether a publishing is happened or not
  • publishedPackages - A JSON array to present the published packages. The format is [{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]
  • hasChangesets - A boolean about whether there were changesets
  • pullRequestNumber - A numeric string to indicate created or updated pull request

Example workflow:

Without Publishing

Create a file at .github/workflows/release.yml with the following content.

name: Release

on:
  push:
    branches:
      - main

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: Setup Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn

      - name: Install Dependencies
        run: yarn install --immutable

      - name: Create Release Pull Request
        uses: cometkim/yarn-changeset-action@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

With Publishing

Before you can setup this action with publishing, you'll need to have an npm token that can publish the packages in the repo you're setting up the action for and doesn't have 2FA on publish enabled (2FA on auth can be enabled). You'll also need to add it as a secret on your GitHub repo with the name NPM_TOKEN. Once you've done that, you can create a file at .github/workflows/release.yml with the following content.

name: Release

on:
  push:
    branches:
      - main

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: Setup Node.js 18.x
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn

      - name: Install Dependencies
        run: yarn install --immutable

      - name: Create Release Pull Request or Publish to npm
        id: changesets
        uses: cometkim/yarn-changeset-action@v1
        with:
          autoPublish: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Send a Slack notification if a publish happens
        if: steps.changesets.outputs.published == 'true'
        # You can do something when a publish happens.
        run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"

Custom Publishing

If you want to hook into when publishing should occur but have your own publishing functionality you can utilize the hasChangesets output.

Note that you might need to account for things already being published in your script because a commit without any new changesets can always land on your base branch after a successful publish. In such a case you need to figure out on your own how to skip over the actual publishing logic or handle errors gracefully as most package registries won't allow you to publish over already published version.

name: Release

on:
  push:
    branches:
      - main

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: Setup Node.js 18.x
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn

      - name: Install Dependencies
        run: yarn install --immutable

      - name: Create Release Pull Request or Publish to npm
        id: changesets
        uses: cometkim/yarn-changeset-action@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish
        if: steps.changesets.outputs.hasChangesets == 'false'
        # You can do something when a publish should happen.
        run: yarn publish

yarn-changeset-action's People

Contributors

akphi avatar andarist avatar brianespinosa avatar christopherbiscardi avatar cometkim avatar danieldelcore avatar dependabot[bot] avatar dmregister avatar emmatown avatar emmenko avatar github-actions[bot] avatar glasser avatar harrysolovay avatar iansan5653 avatar irrationnelle avatar jackleslie avatar jacobwgillespie avatar john-u avatar jonrohan avatar kevinpschaaf avatar luisherranz avatar noviny avatar ocavue avatar orta avatar roystons avatar wweaver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.