changesets / action

700 stars 249 forks source link

Github action setup question #386

Open ryanbas21 opened 3 months ago

ryanbas21 commented 3 months ago

I want to make sure I understand this correctly. My goal is for changesets to have this flow

feature branch -> merge develop -> create pr against master -> merge to master releases to npm.

on:
  push:
    branches:
      - develop
      - master

      ....rest of setup
     - name: publish
        uses: changesets/action@v1
        with:
          publish: pnpm release-packages ## command in root package.json that builds and publishes
          title: Release PR
          branch: master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_CONFIG_PROVENANCE: true

is this correct? I read a few issues and saw the PR that added the branch to it. the description of the config setting wasn't entirely clear to me though.

Andarist commented 3 months ago

I don't think branch is what you are looking for. It's a setting that you can use to override the source branch but you want to change the target branch of the versioning PR.

In the scenario that you describe, develop would contain all of the changeset files and landing your versioning PR would remove them... but only from master. How do you "backport" master to develop? do you immediately merge it back? force push?

ryanbas21 commented 3 months ago

Hi @Andarist I actually was able to just solve it, so i'll put what I did here. Yes - I have to rebase develop with master due to the new commit.

In this repo i'm using main instead of master so ignore the inconsistency.

branch seems to create release PR from develop -> main.

Then once I merge, main has a new commit from the changesets-release branch, that develop will not have.

On success of the changesets step, (cant forget the id on the publish step), I can rebase develop with the updated main.

 name: publish
        uses: changesets/action@v1
        id: changesets
        with:
          publish: pnpm release
          title: Release PR
          branch: main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_CONFIG_PROVENANCE: true

      - name: rebase develop with main on publish
        if: ${{ steps.changesets.outputs.published == 'true' }}
        run: |
          git checkout main
          git fetch --all
          git pull origin main

          git checkout develop
          git restore . # clears out the .npmrc change I dont want to commit.
          git rebase main
          git push -f
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This is how I was able to get changesets action working with a github flow. I genuinely prefer not using the github flow, but because we use it at work, I wanted to get a working example of it with changesets to present.

I'm using an NX monorepo, and in this case also using pnpm workspaces and it seems that this does the trick although i've only just now run the CI and published

If you see a problem with this flow please let me know :)