Skip to content

Commit

Permalink
Simplify npm package release by setting the version (#763)
Browse files Browse the repository at this point in the history
Previously, you had to manually open a PR to bump up the version in package.json.
Now, the version is automatically bumped during the release pipeline.
  • Loading branch information
olafurpg authored Jun 3, 2022
1 parent 72c480b commit ad9dbba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
- run: echo "Releasing version ${{ env.version }}""
- run: yarn version --no-git-tag-version --new-version "${{ env.VERSION }}"
working-directory: npm-distribution
- run: npm publish --access public
working-directory: npm-distribution
env:
Expand Down
12 changes: 5 additions & 7 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ We adhere to the [general Sourcegraph principles for testing](https://docs.sourc

## Releasing

1. If this is a non-patch release, update the changelog. Add a new section `## $MAJOR.MINOR` to [`CHANGELOG.md`](https://github.com/sourcegraph/src-cli/blob/main/CHANGELOG.md#unreleased) immediately under `## Unreleased changes`. Add new empty `Added`, `Changed`, `Fixed`, and `Removed` sections under `## Unreleased changes`.
2. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
3. Update the `"version"` field in the file `npm-distribution/package.json` to match the version you are releasing.
4. Open a pull request with the new changelog and updated `npm-distribution/package.json` version. Get the pull request merged before completing the next step.
5. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
6. GitHub will automatically perform the release via the [goreleaser action](https://github.com/sourcegraph/src-cli/actions?query=workflow%3AGoreleaser). Once it has finished, **you need to confirm**:
1. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
2. (optional) If this is a non-patch release, update the changelog. Add a new section `## $MAJOR.MINOR` to [`CHANGELOG.md`](https://github.com/sourcegraph/src-cli/blob/main/CHANGELOG.md#unreleased) immediately under `## Unreleased changes`. Add new empty `Added`, `Changed`, `Fixed`, and `Removed` sections under `## Unreleased changes`. Open a pull request with the new changelog. Get the pull request merged before completing the next step.
3. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
4. GitHub will automatically perform the release via the [goreleaser action](https://github.com/sourcegraph/src-cli/actions?query=workflow%3AGoreleaser). Once it has finished, **you need to confirm**:
1. The [curl commands in the README](README.markdown#installation) fetch the latest version above.
2. The [releases section of the repo sidebar](https://github.com/sourcegraph/src-cli) shows the correct version.
7. Make the necessary updates to the main Sourcegraph repo:
5. Make the necessary updates to the main Sourcegraph repo:
1. Update the `MinimumVersion` constant in the [src-cli package](https://github.com/sourcegraph/sourcegraph/tree/main/internal/src-cli/consts.go).
2. Update the reference documentation by running `go generate ./doc/cli/references`.
3. Commit the changes, and open a PR.
Expand Down
2 changes: 1 addition & 1 deletion npm-distribution/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sourcegraph/src",
"version": "3.40.4",
"version": "0.0.0-dev",
"description": "Sourcegraph CLI",
"repository": "[email protected]:sourcegraph/src-cli.git",
"author": "Code Intelligence at Sourcegraph",
Expand Down
14 changes: 5 additions & 9 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ set -euf -o pipefail
read -p 'Have you read DEVELOPMENT.md? [y/N] ' -n 1 -r
echo
case "$REPLY" in
Y|y) ;;
*)
echo 'Please read the Releasing section of DEVELOPMENT.md before running this script.'
exit 1
;;
Y | y) ;;
*)
echo 'Please read the Releasing section of DEVELOPMENT.md before running this script.'
exit 1
;;
esac

if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "\$VERSION is not in MAJOR.MINOR.PATCH format"
exit 1
fi

echo "Verifying that npm-distribution/package.json has the correct version"
yarn --cwd="$PWD/npm-distribution" version --no-git-tag-version --new-version "$VERSION"
git diff --exit-code

# Create a new tag and push it, this will trigger the goreleaser workflow in .github/workflows/goreleaser.yml
git tag "${VERSION}" -a -m "release v${VERSION}"
# We use `--atomic` so that we push the tag and the commit if the commit was or wasn't pushed before
Expand Down

0 comments on commit ad9dbba

Please sign in to comment.