question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to combine `version` & `publish` commands together for protected branches

See original GitHub issue

Problem

Hello there In monorepos with main branch protected with pull request necessity, I think it is better to only add changesets to the pull request (summary & bump types can be reviewed by contributors also) & finally by merging to the main branch, changesets github action would “version & publish” to the registry itself. Right now, as I inspected the whole doc and API, after merging to the main branch, again another PR is created by the action & by merging the subsequent PR, publishing would happen. I think the PR creation by the action in this scenario is redundant completely.

It would be great if we could config the action in a way so that “version & publish” commands are run one after another.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Sep 7, 2022

Yeah, the main problem here is that you need to bump versions and remove the changeset files from git - both of those usually require an additional commit to be created. If that would happen whenever you merge something to your base branch then it would become quite cumbersome to work with and more prone to race conditions as people are able to branch off your base at any point in time. However, I think that I’ve seen people using such custom workflows with Changesets - so it’s definitely possible.

While for some projects that extra PR might be redundant - for other projects it’s quite nice as “batching” multiple PRs into one is desirable. Imagine that you’d have two concurrent PRs introducing major changesets for package A. Your intention is probably to release a single major version of your package and not two.

0reactions
danawoodmancommented, Sep 26, 2022

Ok, I’ve finally managed to get this working. It’s a bit hacky but seems reliable:

name: Release

on:
  push:
    branches: main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  release:
    # prevents this action from running on forks
    if: github.repository == 'your-org/your-repo'
    name: Release
    timeout-minutes: 15
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
        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
        uses: actions/setup-node@v3
        with:
          node-version: 17.x
          cache: "npm"
      - name: Install dependencies
        run: npm install --frozen-lockfile
      - name: Build
        run: npm run build
      - name: Create release pull request
        id: changesets
        uses: changesets/action@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Merge pull request
        if: steps.changesets.outputs.pullRequestNumber > 0
        uses: actions/github-script@v6
        with:
          script: |
            const owner = "your-org";
            const repo = "your-repo";
            const head = "changeset-release/main";
            const pull_number = "${{ steps.changesets.outputs.pullRequestNumber }}"
            await github.rest.pulls.merge({ owner, repo, pull_number, merge_method: "squash"});
      - name: Publish to npm
        if: steps.changesets.outputs.pullRequestNumber > 0
        uses: changesets/action@v1
        with:
          publish: npm run release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How GitLab Permissions and Protected Branches Keep Your ...
By basing permissions on simple principles and adding protected branches, GitLab allows you to set up any type of workflow, while protecting ...
Read more >
Release-it with with 2 protected prerelease branches and 1 ...
Hi all I try to set up release-it so that we can create releases based on merging into our prerelease and release branches....
Read more >
How do I solve merge conflicts on a protected branch?
git merge origin/release --no-ff # merge in the release branch; Resolve all the conflicts and commit. push -u merge-release-into-master # Push ...
Read more >
Limit pushes and merges to branches in AWS CodeCommit
Other developers can still pull from the branch, make their own branches, and create pull requests, but they cannot push or merge changes...
Read more >
How to set up Git branch protection rules - Security Boulevard
Branch Name – Name of the branch to be protected. · Allowed To Merge – You can select the role that is allowed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found