Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Publish canary version on PRs to develop #1334

Closed
wants to merge 12 commits into from

Conversation

olivermrbl
Copy link
Contributor

@olivermrbl olivermrbl commented Apr 13, 2022

What
Publish versions on pull requests to branch develop

Why
To be able to get versions with small fixes or features out to users immediately

How
Using a GitHub action, we:

  • Build all packages
  • Format the branch to be used as version name
  • Publish versions of all changed packages with formatted version name

When formatting the branch name we replace all special characters with -, so a branch like feat/test-this_action will have a canary version called feat-test-this-action.

@olivermrbl olivermrbl requested a review from a team as a code owner April 13, 2022 13:21
@olivermrbl olivermrbl changed the title [testing] chore: Publish canary version on PRs to develop chore: Publish canary version on PRs to develop Apr 13, 2022
@srindom
Copy link
Collaborator

srindom commented Apr 14, 2022

Two things:

  1. I don't think it is necessary to do the bootstrap and build - if you run lerna publish locally it builds before publishing.

  2. Should we force publish?

@adrien2p
Copy link
Member

adrien2p commented Apr 16, 2022

Do you really think a version for each PR on develop is a good idea? a PR can be broken, un needed, wrong etc... and therefore the version as well.
What we could do is when something is merged on the develop branch then we create a new beta version from develop instead ?

@olivermrbl
Copy link
Contributor Author

olivermrbl commented Apr 18, 2022

What we could do is when something is merged on the develop branch then we create a new beta version from develop instead ?

I don't see any harm in publishing canary versions for all PRs to develop tbh. Thing is, when we are building on admin and core simultaneously, the canary versions will ensure, that we are never blocked due to a hanging PR or new release.

Additionally, these versions allow devs. to quickly test out the feature giving us shorter time to feedback.

We are also planning on adding a pipeline for deploying a canary version with tag develop 👍

@olivermrbl
Copy link
Contributor Author

I don't see any harm in publishing canary versions for all PRs to develop tbh

One thing we could do is to only run the publishing job, if all tests are successful @adrien2p

@olivermrbl olivermrbl force-pushed the chore/publish-canary-ci branch from 6e5455d to 5e0161e Compare April 18, 2022 13:07
@olivermrbl olivermrbl force-pushed the chore/publish-canary-ci branch from 5756c46 to 0495626 Compare April 18, 2022 15:04
@olivermrbl olivermrbl force-pushed the chore/publish-canary-ci branch from 31a134b to 77ea1e0 Compare May 30, 2022 19:23
@pKorsholm
Copy link
Contributor

Great idea, I love this.

Wrt. the canary for develop can I think we can get two birds with one stone and encapsulate the entire workflow in a single, separate, workflow file.

Github actions can have [multiple triggers](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#using-activity-types-and-filters-with-multiple-events) and support triggers based on the [completion of previous workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run). If we combine this we should be able to create a separate workflow that runs when develop is pushed (or a different develop event), as well as whenever the pipeline has concluded.

I think it could look something like this:

name: Publish Canary

on:
  push:
    branches: [develop]
  workflow_run:
    workflows: ["Medusa Pipeline"]
    types:
      - completed

jobs:
  publish:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.ref == 'refs/heads/develop' }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.5
        with:
          fetch-depth: 0

      - name: Setup Node.js environment
        uses: actions/setup-node@v2.4.1
        with:
          node-version: "14"
          cache: "yarn"
          registry-url: "https://registry.npmjs.org"
      - name: "Get Branch Name"
        run: |
          BRANCH_NAME="${GITHUB_HEAD_REF}"
          echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
      - name: Format Version Name
        run: |
          VERSION_NAME=`echo ${{ env.BRANCH_NAME }} | sed "s/[/_]/-/g"`
          echo "VERSION_NAME=${VERSION_NAME}" >> $GITHUB_ENV
      - name: Authenticate with NPM
        run: |
          echo "@oliverjuhl:registry=http://registry.npmjs.org/" > .npmrc
          echo "registry=http://registry.npmjs.org/" >> .npmrc
          echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
          npm whoami
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Publish Canary
        run: lerna publish --yes --canary --preid ${{ env.VERSION_NAME }} --dist-tag ${{ env.VERSION_NAME }} --force-publish="*"
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 just few comments

jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.ref == 'refs/heads/develop' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why do we have to check the ref here since it is on push to develop?

with:
fetch-depth: 0

- name: Setup Node.js environment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: we should probably add a step to stop previous same workflow in order to avoid situations where we push 10 new versions when we merge ten branches 😅

@olivermrbl
Copy link
Contributor Author

olivermrbl commented Jun 4, 2022

Wrt. the canary for develop can I think we can get two birds with one stone and encapsulate the entire workflow in a single, separate, workflow file.

Great suggestion @pKorsholm - thanks!

@adrien2p

question: why do we have to check the ref here since it is on push to develop?

As @pKorsholm mentions, we now encapsulate the publishing of canary versions for all PRs opened to develop as well as when develop is pushed in a single file and workflow, hence why we need the ref check.

Update: I now see, that it's only on push to develop. We should add a trigger for pull requests to develop as well to support the first case from my previous comment. I'll play around with it and report back

name: Publish Canary

on:
push:
Copy link
Member

@adrien2p adrien2p Jun 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:
on: ["push","pull_request"] if it is possible? 😊

@adrien2p
Copy link
Member

adrien2p commented Jun 4, 2022

Update: I now see, that it's only on push to develop. We should add a trigger for pull requests to develop as well to support the first case from my previous comment. I'll play around with it and report back

No problem, do we also want to to be triggered for forked repository that open a pr?

@pKorsholm
Copy link
Contributor

Can we wait to merge this for a bit. Just a consideration, we should probably have a special canary package listed as well and publish versions to that rather than the release package.

Versions bloat the json downloaded when installing, and this might not be an issue now, but if it is ever growing it might hurt us in like 10.000 publishes 😅

@olivermrbl
Copy link
Contributor Author

Closed in favor of #1746

@olivermrbl olivermrbl closed this Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants