Skip to content

Allow to customize branch in runVersion #254

Closed

Description

@ernestognw

Description

Hello, we recently implemented an automated release cycle via Changesets in OpenZeppelin contracts and we had problems trying to create a custom Github Actions Workflow with chained jobs using needs: [...] because it was impossible to tell the Changesets Action what branch to use. I think it'd be ideal to define it as an input.

Basically, we just want to override this option.

Is there something to consider? We already merge the changesets integration but I'd love to send a PR with this change as well.

Activity

  1. Andarist commented on Jan 19, 2023

    @Andarist
    Member

    Hm, so you have a workflow that starts in branch A but one that creates a branch B (or something like that) and you want to create a versioning PR from changeset-release/B to B. Did I get this right?

  2. ernestognw commented on Jan 19, 2023

    @ernestognw
    ContributorAuthor

    That's correct, we need to chain the B branch creation with your action, but since the run starts in A, we can't customize it.

  3. Andarist commented on Jan 19, 2023

    @Andarist
    Member

    I would accept a PR for this - we can bikeshed the input's name in the review comments. For now let's just go with a simple branch

  4. ernestognw commented on Jan 19, 2023

    @ernestognw
    ContributorAuthor

    I would accept a PR for this - we can bikeshed the input's name in the review comments. For now let's just go with a simple branch

    Thanks for the fast response! I created a PR with the desired change. Would love also feedback for #250

  5. rohit-gohri commented on May 11, 2023

    @rohit-gohri

    We have a similar usecase to this:

    • Default branch: "develop" - Workflow runs here
    • Production branch: "main" - We want Version PR to target this
  6. typeofweb commented on May 26, 2023

    @typeofweb

    Hey @Andarist! Any updates on this? The PR is open and looks like a rather small change.

  7. bgfernandes commented on Jun 5, 2023

    @bgfernandes

    Hey all, this is very interesting for our use case as well, we have a monorepo and and to have a different release PR for each package in the monorepo, we are doing a github action for each package using changeset version --ignore <package1> --ignore <package2>, the problem is that they clash with each other on the branch name and can't create a second PR.

  8. nicvickeryw commented on Aug 10, 2023

    @nicvickeryw

    Hey all, this is very interesting for our use case as well, we have a monorepo and and to have a different release PR for each package in the monorepo, we are doing a github action for each package using changeset version --ignore <package1> --ignore <package2>, the problem is that they clash with each other on the branch name and can't create a second PR.

    We're in an almost identical situation, would love to have the ability to use separate branches for each changeset PR.

  9. rohit-gohri commented on Jan 29, 2024

    @rohit-gohri

    I wanted to test if the PR #255 would work but since actions runs from dist folder it's not possible to test the branch directly.
    Tried overwriting the GITHUB_REF option with an env var but Github actions doesn't allow overwriting GITHUB_* env vars.

    Would be happy to help move the PR forward

  10. rohit-gohri commented on Jan 30, 2024

    @rohit-gohri

    I ended up adding a hacky workflow that does the same thing as this action with custom branches:

    hacky workflow
      # Hack while custom branch is not officially supported in changeset action - https://github.com/changesets/action/issues/254
      release_pr:
        name: Release PR
        if: ${{ github.event_name == 'push' && github.ref_name == 'develop' }}
    
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
    
      - name: git config
        run: |
    	  git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com
    
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version-file: .nvmrc
          cache: 'yarn'
    
      - name: 📦 Install dependencies
        run: yarn install --immutable
    
      - name: Changeset status
        id: changeset-status
        shell: bash
        run: |
          mkdir -p out
          yarn run changeset status --since=origin/main --output out/changeset_status.json
          cat out/changeset_status.json | jq '.releases | length' > "out/releases_size.json"
          echo "release_size=$(cat out/releases_size.json)"  >> "$GITHUB_OUTPUT"
    
      - name: Create branch
        if: ${{ steps.changeset-status.outputs.release_size != '0' }}
        id: version
        shell: bash
        run: |
          set -x
          git branch -D changeset-release/${{ github.ref_name }} || true
          git checkout -b changeset-release/${{ github.ref_name }}
          git reset --hard ${{ github.sha }}
          yarn run version
          git push origin HEAD:changeset-release/${{ github.ref_name }} --force
          {
            echo 'changelog<<EOF'
            yarn run generate-changelog
            echo EOF
          } >> "$GITHUB_OUTPUT"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    
      - name: 🔀 Create Release PR
        if: ${{ steps.changeset-status.outputs.release_size != '0' }}
        uses: actions/github-script@v7
        env:
          RELEASE_NOTES: ${{ steps.version.outputs.changelog }}
        with:
          script: |
            let base = 'main';
            let head = 'changeset-release/${{ github.ref_name }}';
    
            let title = `Release PR`;
            let body = `${process.env.RELEASE_NOTES}`.trim();
    
            let searchQuery = `repo:${context.repo.owner}/${context.repo.repo}+state:open+head:${head}+base:${base}+is:pull-request`;
    
            const [existingPR] = (await github.rest.search.issuesAndPullRequests({
              q: searchQuery,
            })).data.items;
    
            if (existingPR) {
              await github.rest.pulls.update({
                owner: context.repo.owner,
                repo: context.repo.repo,
                pull_number: existingPR.number,
                base,
                body,
                title,
              });
            }
            else {
              await github.rest.pulls.create({
                owner: context.repo.owner,
                repo: context.repo.repo,
                draft: true,
                head,
                base,
                body,
                title,
              });
            }
    

    Maybe a better solution would be to instead solve #310 and #317 and let users handle the PR creation process on their own.
    Right now I had to create my own custom generate-changelog script and remove the action completely as there is no option to disable PR creation.

  11. bluwy commented on May 15, 2026

    @bluwy
    Member

    Fixed in #255

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions