diff --git a/README.md b/README.md index 8fb35f9..49f2cca 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,51 @@ For example, you can add a step before running the Changesets GitHub Action: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} ``` +#### 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. + +```yml +name: Release + +on: + push: + branches: + - master + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + with: + # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits + fetch-depth: 0 + + - name: Setup Node.js 12.x + uses: actions/setup-node@v2 + with: + node-version: 12.x + + - name: Install Dependencies + run: yarn + + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/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 +``` + #### With version script If you need to add additional logic to the version command, you can do so by using a version script. diff --git a/action.yml b/action.yml index a20bda1..7dccd70 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,8 @@ outputs: publishedPackages: description: > 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: + description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality. branding: icon: "package" color: "blue"