Skip to content

Commit

Permalink
feat: add release PR workflow (#4849)
Browse files Browse the repository at this point in the history
Co-authored-by: Trent Mick <trentm@gmail.com>
  • Loading branch information
pichlermarc and trentm authored Aug 1, 2024
1 parent 30a46ae commit b2778e1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 127 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/create-or-update-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Create or Update Release PR

on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: Release type
options:
- patch
- minor
release_scope:
type: choice
description: Release Scope
options:
- experimental
- sdk
- all

jobs:
create-or-update-release-pr:
runs-on: ubuntu-latest
steps:
- name: Fork
run: gh repo fork open-telemetry/opentelemetry-js
env:
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
repository: opentelemetrybot/opentelemetry-js
ref: main
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
- name: Sync with upstream
run: |
git remote show origin
git remote add upstream https://github.com/open-telemetry/opentelemetry-js.git
git fetch upstream
git reset --hard upstream/main
git push origin main --force
- uses: actions/setup-node@v4
with:
cache: 'npm'
cache-dependency-path: package-lock.json
node-version: 22
- run: npm install -g npm@latest

- run: npm ci

- name: Create/Update Release PR
run: |
git config user.name opentelemetrybot
git config user.email 107717825+opentelemetrybot@users.noreply.github.com
npm run github:create_or_update_release_pr
env:
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
RELEASE_SCOPE: ${{ github.event.inputs.release_scope }}
RELEASE_KIND: ${{ github.event.inputs.release_scope }}:${{ github.event.inputs.release_type }}
RELEASE_PR_REMOTE: origin
RELEASE_PR_OWNER: opentelemetrybot
184 changes: 61 additions & 123 deletions doc/contributing/releasing.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,61 @@
# Releasing OpenTelemetry Packages

This document explains how to publish all OT modules at version x.y.z. Ensure that you’re following semver when choosing a version number.

Release Process:

- [Release Process (Maintainers only)](#release-process)
- [Update to latest locally](#update-to-latest-locally)
- [Create a new branch](#create-a-new-branch)
- [Prepare each package for release](#prepare-each-package-for-release)
- [Use the Changelog to create a GitHub Release](#use-the-changelog-to-create-a-github-release)
- [Generate the changelog with lerna](#generate-the-changelog-with-lerna)
- [How to use](#how-to-use)
- [Update Changelog file](#update-changelog-file)
- [Create a new PR](#create-a-new-pr)
- [Merge and pull](#merge-and-pull)
- [Publish all packages](#publish-all-packages)
- [Publish the GitHub Release](#publish-the-github-release)
- [Update CHANGELOG](#update-changelog)
- [Known Issues](#known-issues)

## Release Process

### Update to latest locally

Use `git fetch` and `git checkout origin/main` to ensure you’re on the latest commit. Make sure you have no unstaged changes. Ideally, also use `git clean -dfx` to remove all ignored and untracked files.

### Create a new branch

Create a new branch called `x.y.z-proposal` from the current commit.

### Prepare each package for release

Decide on the next `major.minor.patch` release number based on [semver](http://semver.org/) guidelines.

- Use `npm install` command to initialize all package directories
- Use `lerna publish --skip-npm --no-git-tag-version --no-push` to bump the version in all `package.json`
- Use `npm run bootstrap` to generate latest `version.ts` files

### Use the Changelog to create a GitHub Release

#### Generate the changelog with lerna

Since we use `lerna`, we can use [lerna-changelog](https://github.com/lerna/lerna-changelog#lerna-changelog)

##### How to use

Pass your [github token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) to generate the changelog automatically.
For security reasons, when you create a Github token, select the permissions: under **repo**, select **Access public repositories**, **Access commit status**.

In your terminal, execute the following command:

```bash
GITHUB_AUTH=<your token> lerna-changelog
```

It will print something like:

```md
### Unreleased (2018-05-24)

##### :bug: Bug Fix
* [#198](https://github.com/my-org/my-repo/pull/198) Avoid an infinite loop ([@helpful-hacker](https://github.com/helpful-hacker))

##### :house: Internal
* [#183](https://github.com/my-org/my-repo/pull/183) Standardize error messages ([@careful-coder](https://github.com/careful-coder))

##### Commiters: 2
- Helpful Hacker ([@helpful-hacker](https://github.com/helpful-hacker))
- [@careful-coder](https://github.com/careful-coder)
```

By default lerna-changelog will show all pull requests that have been merged since the latest tagged commit in the repository. That is however only true for pull requests **with certain labels applied** (see [lerna.json](lerna.json) for authorized labels).

You can also use the `--from` and `--to` options to view a different range of pull requests:

```sh
GITHUB_AUTH=xxxxx lerna-changelog --from=v1.0.0 --to=v2.0.0
```

##### Update Changelog file

From what `lerna-changelog` has generated, starts new Unreleased label. Follow the example set by recent Released label.

On [GitHub Releases](https://github.com/open-telemetry/opentelemetry-js/releases), follow the example set by recent releases to populate a summary of changes, as well as a list of commits that were applied since the last release. Save it as a draft, don’t publish it. Don’t forget the tag -- call it `vx.y.z` and leave it pointing at `main` for now (this can be changed as long as the GitHub release isn’t published).

### Create a new PR

Create a pull request titled `chore: x.y.z release proposal`. The commit body should just be a link to the draft notes. Someone who can access draft notes should approve it, looking in particular for test passing, and whether the draft notes are satisfactory.

### Merge and pull

Merge the PR, and pull the changes locally (using the commands in the first step). Ensure that `chore: x.y.z release proposal` is the most recent commit.

### Publish all packages

Go into each directory and use `npm publish` (requires permissions) to publish the package. You can use the following script to automate this.

```bash
#!/bin/bash

for dir in $(ls packages); do
pushd packages/$dir
npm publish
popd
done
```

Check your e-mail and make sure the number of “you’ve published this module” emails matches the number you expect.

### Publish the GitHub Release

Publish the GitHub release, ensuring that the tag points to the newly landed commit corresponding to release proposal `x.y.z`.

### Update CHANGELOG

- After releasing is done, update the [CHANGELOG.md](https://github.com/open-telemetry/opentelemetry-js/blob/main/CHANGELOG.md) and start new Unreleased label.
- Create a new commit with the exact title: `Post Release: update CHANGELOG.md`.
- Go through PR review and merge it to GitHub main branch.

### Known Issues

- The `examples/` and `getting-started/` folders are not part of lerna packages, we need to manually bump the version in `package.json`.
# Releasing

This document is aimed at Maintainers and describes how to release a new version of the packages contained in this repository.
We aim to eventually automate this process as much as possible.

## Create a release PR

1. Go to the [Release PR Workflow](https://github.com/open-telemetry/opentelemetry-js/actions/workflows/create-or-update-release.yml)
2. Click "Run workflow"
3. For `Release Type`, select if you want to create a release PR for a new `minor` or `patch` version.
4. For `Release Scope`, select if you want to release
- `experimental` (all packages under `./experimental/packages`)
- `sdk` (all packages under `./packages/` and `./experimental/packages`)
- `all` (all packages under `./api/`, `./packages/` and `./experimental/packages`)

> [!TIP]
> If there was a commit to `main`, after PR creation simply run the workflow again before merging it.
> Re-running it will update the PR with the contents from `main` and will update the PR body too.
## Review and merge the release PR

1. Review the PR generated via the workflow (it will be titled `chore: prepare next release` and opened by the @opentelemetrybot user)
2. Once approved, merge the PR

## Publish to NPM

### Prerequisites

1. Ensure you have access to the [`opentelemetry` npm organization](https://www.npmjs.com/org/opentelemetry)
2. Go to your npm user's `Access Tokens` page
3. Click `Generate New Token` -> `Granular Access Token` (2FA prompt will pop up)
4. Input all required fields
- recommended: set the expiry date on the token to 1 day
- recommended: set a CIDR range to only allow your IP
5. Under `Packages and Scopes`
- set `Permissions` to `Read and Write`
- Select `Only Select packages and scopes`, choose `@opentelemetry`

### Publishing

1. Check out the commit created by merging the release PR
2. run `git clean -fdx --exclude <whatever you want to keep, e.g. .idea, .vscode>`
3. run `npm ci`
4. run `npm run compile`
5. run `NODE_AUTH_TOKEN=<token generated earlier> npm run release:publish`

> [!IMPORTANT]
> Delete the token once you're done publishing
## Create GitHub Releases

1. Check out the commit created by merging the release PR
2. Run
- `npm run _github:draft_release:experimental`, if you published an `all`, `sdk` or `experimental` release
- `npm run _github:draft_release:stable`, if you published an `all` or `sdk` release
- `npm run _github:draft_release:api` if you published an `all` release
3. Verify that the contents of the created draft releases (title, changelog, selected commit)
4. Publish the releases
- uncheck `Set as a pre-release` for all releases
- uncheck `Set as the latest release` for all releases except for the `stable` SDK release. This will ensure that the
`stable` SDK release consistently shows up as latest under `Releases` when navigating to the project page.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prepare_release:sdk:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_patch && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:prepare_stable",
"prepare_release:sdk:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_minor && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:prepare_stable",
"prepare_release:all:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:version_minor && cd api/ && npm version minor && cd .. && lerna run align-api-deps && npm run _restore:package-json && npm run _changelog:prepare_all",
"release:publish": "lerna publish from-package --no-push --no-private --no-git-tag-version --no-verify-access",
"release:publish": "lerna publish --concurrency 1 from-package --no-push --no-private --no-git-tag-version --no-verify-access",
"comment_internal": "echo scripts below this line are for internal use",
"_check:no_changes": "if [ ! -z \"$(git status -uall --porcelain)\" ]; then echo Please ensure all changes are committed; exit 1; fi",
"_backup:package-json": "cp package.json package.json.backup",
Expand All @@ -60,13 +60,14 @@
"_github:draft_release:api": "node scripts/extract-latest-release-notes.js ./api/CHANGELOG.md && VERSION=$(node scripts/get-version.js ./api/package.json | grep -oP '^\\d+\\.\\d+\\.\\d+$') && gh release create --draft --notes-file ./.tmp/release-notes.md --target main --title api/v$VERSION api/v$VERSION",
"_github:draft_release:experimental": "node scripts/extract-latest-release-notes.js ./experimental/CHANGELOG.md && VERSION=$(node scripts/get-version.js ./experimental/packages/ | grep -oP '^\\d+\\.\\d+\\.\\d+$') && gh release create --draft --notes-file ./.tmp/release-notes.md --target main --title experimental/v$VERSION experimental/v$VERSION",
"_github:draft_release:stable": "node scripts/extract-latest-release-notes.js ./CHANGELOG.md && VERSION=$(node scripts/get-version.js ./packages/ | grep -oP '^\\d+\\.\\d+\\.\\d+$') && gh release create --draft --notes-file ./.tmp/release-notes.md --target main --title v$VERSION v$VERSION",
"_github:update_release_pr_body_from_file": "gh pr edit $RELEASE_PR_OWNER:release/next-version --body-file ./.tmp/release-notes.md",
"_github:update_release_pr_body_from_file": "gh pr edit --repo open-telemetry/opentelemetry-js $RELEASE_PR_OWNER:release/next-version --body-file ./.tmp/release-notes.md",
"_github:update_release_pr_body:all": "node scripts/extract-latest-release-notes.js api/CHANGELOG.md ./CHANGELOG.md experimental/CHANGELOG.md && npm run _github:update_release_pr_body_from_file",
"_github:update_release_pr_body:stable": "node scripts/extract-latest-release-notes.js ./CHANGELOG.md experimental/CHANGELOG.md && npm run _github:update_release_pr_body_from_file",
"_github:update_release_pr_body:sdk": "node scripts/extract-latest-release-notes.js ./CHANGELOG.md experimental/CHANGELOG.md && npm run _github:update_release_pr_body_from_file",
"_github:update_release_pr_body:experimental": "node scripts/extract-latest-release-notes.js experimental/CHANGELOG.md && npm run _github:update_release_pr_body_from_file",
"_verify_release_kind": "echo $RELEASE_KIND | grep -oP '^(all|sdk|experimental):(minor|patch)$'",
"_verify_release_remote": "git remote get-url $RELEASE_PR_REMOTE",
"_github:update_release_branch": "npm run _verify_release_kind && npm run _verify_release_remote && (git checkout main && git pull upstream main && git branch -D release/next-version; git checkout -b release/next-version && npm run prepare_release:$RELEASE_KIND && git commit -am \"chore: prepare release\" && git push $RELEASE_PR_REMOTE --force release/next-version)"
"_github:update_release_branch": "npm run _verify_release_kind && npm run _verify_release_remote && (git checkout main && git pull upstream main && git branch -D release/next-version; git checkout -b release/next-version && npm run prepare_release:$RELEASE_KIND && git commit -am \"chore: prepare release\" && git push --set-upstream $RELEASE_PR_REMOTE --force release/next-version)",
"github:create_or_update_release_pr": "npm run _github:update_release_branch && (gh pr create --repo open-telemetry/opentelemetry-js --title 'chore: prepare next release' --body ''; npm run _github:update_release_pr_body:$RELEASE_SCOPE)"
},
"repository": "open-telemetry/opentelemetry-js",
"keywords": [
Expand Down

0 comments on commit b2778e1

Please sign in to comment.