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

Add util postversion hook to repush major version tag #9

Closed
domharrington opened this issue May 4, 2023 · 3 comments · Fixed by #20
Closed

Add util postversion hook to repush major version tag #9

domharrington opened this issue May 4, 2023 · 3 comments · Fixed by #20

Comments

@domharrington
Copy link
Member

Grab this from @kanadgupta

@kanadgupta
Copy link
Member

Background

The idea is to create additional tags for users' convenience so they can point to the latest non-breaking changes without having to make dependency updates for every single minor/patch change. So they can do this and just get everything within the v2 family of releases:

- name: Sync to ReadMe Micro
  uses: readmeio/readme-micro@v2

as opposed to this:

- name: Sync to ReadMe Micro
  uses: readmeio/readme-micro@v2.0.1

How we're doing this in rdme

Create a postversion script to the package.json file:

https://github.com/readmeio/rdme/blob/v8.4.0/package.json#L103

which invokes this ./bin/set-major-version-tag.js script:

https://github.com/readmeio/rdme/blob/v8.4.0/bin/set-major-version-tag.js

I'd recommend installing semver for this!

Now, when you bump the package version using npm version (let's say 2.0.1, for example), it'll automatically force-push the v2 tag to point to that same commit 🥳

@cvan
Copy link
Contributor

cvan commented Jun 2, 2023

oh nice. I was some GitHub actions that automatically handles this, in semver fashion. how do we feel about actions requiring actions? at least, there is some sense of peace in knowing the package will probably continue to be maintained without additional work on ReadMe's end.

@kanadgupta
Copy link
Member

GitHub's registry doesn't follow semver the same way npm does, it only uses existing git refs (i.e. branches, tags, SHAs)1. So you'll need to publish and force-update a v2 tag.

GitHub does this themselves with actions/checkout. We've been auto-publishing major tags like this in rdme and it's been quite successful in getting users onto the latest version in a timely manner.

Footnotes

  1. See GitHub's docs on this: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses

domharrington added a commit that referenced this issue Jul 3, 2023
…17)

| 🚥 Related to #9 and readmeio/micro#211 |
| :---------------- |

## 🧰 Changes

Adds the version number in the payload sent during Webhook events (e.g.,
<kbd>push</kbd>). The Micro UI then stores that in its DB to version
check sync'd repos against the latest published version.

### Additional context
The version is inferred from the `package.json` at the time of the
release (`git tag && npm version && npm publish`) to the
[`@readme/micro` npm
package](https://www.npmjs.com/package/@readme/micro). Why?

1. [GitHub's
`context`](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)
is inconsistent between webhook event types. `github.action_repository`
(e.g., <kbd>"readmeio/readme-micro"</kbd>) and `github.action_ref`
(e.g., <kbd>"refs/tags/2.3.0"</kbd>) are not guaranteed to be in the
response from every webhook type.
2. Bitbucket doesn't have a similar `context`. Getting the version would
require additional boilerplate code to, for example, parse the version
from the args passed, `process.argv`, where `micro` is invoked in the
`bitbucket-pipelines.yml` file: <kbd>script: npx @readme/micro@v2</kbd>.

## 🧬 QA & Testing

Run with debugging logs enabled. Ensure the version, without an `x`,
appears as a string formatted as `[\d]+.[\d]+.[\d]+` (e.g.,
<kbd>"2.3.0"</kbd>).

---------

Co-authored-by: Dom Harrington <domharrington@protonmail.com>
domharrington added a commit that referenced this issue Jul 7, 2023
domharrington added a commit that referenced this issue Jul 7, 2023
| 🚥 Fixes #9 |
| :---------------- |

## 🧰 Changes

GitHub Actions allows you to define a tag for an action to use that
doesn't have to be a fully qualified semver version. This means we can
publish v2.3.0 onto npm and then re-push that to v2 as a git tag. This
means we dont have to prompt users to upgrade any time we push a
non-breaking change. This is a pretty common pattern that GitHub does
themselves, and we also do it in rdme too!

So then instead of telling people to do this:

```yaml
- name: GitHub Action
  uses: readmeio/readme-micro@v2.3.0
```

We can just do this
```yaml
- name: GitHub Action
  uses: readmeio/readme-micro@v2
```

## 🧬 QA & Testing

If you run this:

```sh
./bin/set-major-version-tag.js
$ git tag v2 -f -m 'Top-level tag pointing to 2.3.0'
Updated tag 'v2' (was fc99ec6)
```

You'll see how it works. We've automatically wired this up to the
[postversion](https://docs.npmjs.com/cli/v7/commands/npm-version#description)
event which is after the new npm version has been created and the new
git tag is present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants