Skip to content

Commit ad9dbba

Browse files
authored
Simplify npm package release by setting the version (#763)
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.
1 parent 72c480b commit ad9dbba

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

.github/workflows/goreleaser.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
with:
4646
node-version: 16
4747
registry-url: 'https://registry.npmjs.org'
48+
- run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
49+
- run: echo "Releasing version ${{ env.version }}""
50+
- run: yarn version --no-git-tag-version --new-version "${{ env.VERSION }}"
51+
working-directory: npm-distribution
4852
- run: npm publish --access public
4953
working-directory: npm-distribution
5054
env:

DEVELOPMENT.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ We adhere to the [general Sourcegraph principles for testing](https://docs.sourc
5656

5757
## Releasing
5858

59-
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`.
60-
2. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
61-
3. Update the `"version"` field in the file `npm-distribution/package.json` to match the version you are releasing.
62-
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.
63-
5. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
64-
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**:
59+
1. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
60+
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.
61+
3. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
62+
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**:
6563
1. The [curl commands in the README](README.markdown#installation) fetch the latest version above.
6664
2. The [releases section of the repo sidebar](https://github.com/sourcegraph/src-cli) shows the correct version.
67-
7. Make the necessary updates to the main Sourcegraph repo:
65+
5. Make the necessary updates to the main Sourcegraph repo:
6866
1. Update the `MinimumVersion` constant in the [src-cli package](https://github.com/sourcegraph/sourcegraph/tree/main/internal/src-cli/consts.go).
6967
2. Update the reference documentation by running `go generate ./doc/cli/references`.
7068
3. Commit the changes, and open a PR.

npm-distribution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sourcegraph/src",
3-
"version": "3.40.4",
3+
"version": "0.0.0-dev",
44
"description": "Sourcegraph CLI",
55
"repository": "git@github.com:sourcegraph/src-cli.git",
66
"author": "Code Intelligence at Sourcegraph",

release.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@ set -euf -o pipefail
55
read -p 'Have you read DEVELOPMENT.md? [y/N] ' -n 1 -r
66
echo
77
case "$REPLY" in
8-
Y|y) ;;
9-
*)
10-
echo 'Please read the Releasing section of DEVELOPMENT.md before running this script.'
11-
exit 1
12-
;;
8+
Y | y) ;;
9+
*)
10+
echo 'Please read the Releasing section of DEVELOPMENT.md before running this script.'
11+
exit 1
12+
;;
1313
esac
1414

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

20-
echo "Verifying that npm-distribution/package.json has the correct version"
21-
yarn --cwd="$PWD/npm-distribution" version --no-git-tag-version --new-version "$VERSION"
22-
git diff --exit-code
23-
2420
# Create a new tag and push it, this will trigger the goreleaser workflow in .github/workflows/goreleaser.yml
2521
git tag "${VERSION}" -a -m "release v${VERSION}"
2622
# We use `--atomic` so that we push the tag and the commit if the commit was or wasn't pushed before

0 commit comments

Comments
 (0)