Skip to content

Commit 8b22da1

Browse files
chore/release: open the sourcegraph MinimumVersion bump PR automatically
Every Sourcegraph instance serves the src-cli version pinned in sourcegraph/sourcegraph `internal/src-cli/consts.go` (`MinimumVersion`) from `/.api/src-cli/version`, so a release is invisible to instances until someone also hand-edits that constant, `dev/tool_deps.bzl`, and `MODULE.bazel.lock`. That step is easy to forget: src-cli 8.0.0 shipped in September and sourcegraph.com still recommends 7.6.0. The release workflow now runs a `sourcegraph_bump` job after every new latest release. It checks out sourcegraph/sourcegraph, applies the three edits with the tarball checksums from the release's `checksums.txt`, regenerates the lockfile with `bazel mod tidy`, verifies the pins with `bazel fetch`, and opens a `src-cli-bump/<version>` PR with the platform team as reviewer. The job lives in its own workflow so it can also be run by hand for a release whose PR was never opened. ## Test Plan Ran `dev/open-sourcegraph-bump-pr.sh` locally with `VERSION=8.0.0` and `OPEN_PR=0` against a sourcegraph checkout at `16a472ea69e`: the diff matched the shape of sourcegraph/sourcegraph#14574 (3 files, 11 lines, including the regenerated `bzlTransitiveDigest` entries) and `bazel fetch` pulled both tarballs with the new checksums. The GitHub job itself only runs on a tag, so it has not been exercised yet. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1a3bd-c619-7427-a499-52a596adc40b
1 parent 2cf148e commit 8b22da1

4 files changed

Lines changed: 168 additions & 22 deletions

File tree

‎.github/workflows/goreleaser.yml‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ on:
2727
#
2828
# 1. Build and publish the new release to a versioned Homebrew formula
2929
#
30-
# This action contains 5 jobs to accommodate both cases:
30+
# This action contains 6 jobs to accommodate both cases:
3131
#
32-
# release_type [always] - checks tags, determines if we're case 1. or case 2.
33-
# goreleaser_pre [if case 1.] - copies the main formula to a versioned formula
34-
# goreleaser [always] - runs tests, builds + publishes with goreleaser
35-
# goreleaser_post [if case 1.] - updates symlink to latest version
36-
# npm [always] - publishes to npm
32+
# release_type [always] - checks tags, determines if we're case 1. or case 2.
33+
# goreleaser_pre [if case 1.] - copies the main formula to a versioned formula
34+
# goreleaser [always] - runs tests, builds + publishes with goreleaser
35+
# goreleaser_post [if case 1.] - updates symlink to latest version
36+
# npm [always] - publishes to npm
37+
# sourcegraph_bump [if case 1.] - opens the sourcegraph/sourcegraph PR that pins the new version
3738
jobs:
3839
# release_type compares the current tag to the highest versioned tag available on the
3940
# repo to determine if this release is for a new latest version or a patch of an older
@@ -259,3 +260,14 @@ jobs:
259260
working-directory: npm-distribution
260261
env:
261262
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
263+
264+
# sourcegraph_bump opens the sourcegraph/sourcegraph PR that raises MinimumVersion and
265+
# the Bazel src-cli pins to this release, so instances start serving it from
266+
# /.api/src-cli/. A patch of an older version does not change what instances serve.
267+
sourcegraph_bump:
268+
needs: goreleaser
269+
if: needs.goreleaser.outputs.is_latest_version == 1
270+
uses: ./.github/workflows/sourcegraph-bump.yml
271+
with:
272+
version: ${{ github.ref_name }}
273+
secrets: inherit
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Open sourcegraph/sourcegraph version bump PR
2+
3+
# Opens the sourcegraph/sourcegraph PR that pins a published src-cli release
4+
# (MinimumVersion, Bazel tool_deps, MODULE.bazel.lock) and asks the platform
5+
# team to review it. See dev/open-sourcegraph-bump-pr.sh.
6+
#
7+
# Called by goreleaser.yml after a new latest release, or run by hand for a
8+
# release whose bump PR was never opened:
9+
# gh workflow run sourcegraph-bump.yml -R sourcegraph/src-cli -f version=8.0.0
10+
on:
11+
workflow_dispatch:
12+
inputs:
13+
version:
14+
description: Published src-cli release tag, for example 8.0.0
15+
required: true
16+
type: string
17+
workflow_call:
18+
inputs:
19+
version:
20+
required: true
21+
type: string
22+
23+
jobs:
24+
sourcegraph_bump:
25+
name: Open sourcegraph/sourcegraph PR
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout src-cli
29+
uses: actions/checkout@v7
30+
- name: Checkout sourcegraph/sourcegraph
31+
uses: actions/checkout@v7
32+
with:
33+
repository: sourcegraph/sourcegraph
34+
path: sourcegraph
35+
token: ${{ secrets.BOT_CROSS_REPO_PAT }}
36+
- name: Configure git
37+
run: |
38+
git config user.name sourcegraph-bot
39+
git config user.email sourcegraph-bot-github@sourcegraph.com
40+
working-directory: sourcegraph
41+
- name: Bump src-cli and open the PR
42+
run: dev/open-sourcegraph-bump-pr.sh
43+
env:
44+
VERSION: ${{ inputs.version }}
45+
SOURCEGRAPH_DIR: ${{ github.workspace }}/sourcegraph
46+
GH_TOKEN: ${{ secrets.BOT_CROSS_REPO_PAT }}

‎DEVELOPMENT.md‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,12 @@ We adhere to the general Sourcegraph principles for testing, as well as the Go s
7979
npm show @sourcegraph/src version
8080
```
8181
3. The [releases section of the repo sidebar](https://github.com/sourcegraph/src-cli) shows the correct version.
82-
5. Make the necessary updates to the main Sourcegraph repo:
83-
1. Update the `MinimumVersion` constant in the [src-cli package](https://github.com/sourcegraph/sourcegraph/tree/main/internal/src-cli/consts.go).
84-
2. Update the `SRC_CLI_VERSION` in [tool_deps.bzl](https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph@f88ee515885e1761f002f8adcc73560bcb2573ee/-/blob/dev/tool_deps.bzl?L6)
85-
3. Update the sha256 hashes for the two `src-cli-*` targets in [tool_deps.bzl](https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/dev/tool_deps.bzl). The easiest way to do this is to run the following command after updating `SRC_CLI_VERSION`, and extract the correct checksums for each target from the error message:
86-
```shell
87-
$ bazel build @src-cli-linux-amd64//:src-cli-linux-amd64 \
88-
@src-cli-darwin-arm64//:src-cli-darwin-arm64
89-
90-
ERROR: java.io.IOException: Error downloading [...]_linux-amd64.tar.gz [...] Checksum was <new linux-amd64 checksum>
91-
92-
[...]
93-
```
94-
After updating the checksums, rerun the command to verify that the values are correct.
95-
4. Run `sg generate bazel` and `sg bazel configure` (this may not result in any changes)
96-
4. Commit the changes, and open a PR.
97-
6. Once the version bump PR is merged and the commit is live on dotcom, check that the [curl commands in the README](README.md#installation) also fetch the new latest version.
82+
4. The action opened a `src-cli-bump/$VERSION` pull request in [sourcegraph/sourcegraph](https://github.com/sourcegraph/sourcegraph/pulls?q=is%3Apr+head%3Asrc-cli-bump%2F) with the platform team as reviewer. It raises `MinimumVersion` in `internal/src-cli/consts.go`, which every instance serves from `/.api/src-cli/version`, and the `SRC_CLI_VERSION` pin and checksums in `dev/tool_deps.bzl`. If the job failed, rerun it with:
83+
```shell
84+
gh workflow run sourcegraph-bump.yml -R sourcegraph/src-cli -f version=$VERSION
85+
```
86+
or run [`dev/open-sourcegraph-bump-pr.sh`](dev/open-sourcegraph-bump-pr.sh) locally against a sourcegraph checkout.
87+
5. Get the version bump PR merged. Once the commit is live on dotcom, check that the [curl commands in the README](README.md#installation) also fetch the new latest version.
9888

9989
### Patch releases
10090

‎dev/open-sourcegraph-bump-pr.sh‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Opens the sourcegraph/sourcegraph pull request that pins a newly released src-cli version:
4+
#
5+
# internal/src-cli/consts.go MinimumVersion, served by /.api/src-cli/version on every instance
6+
# dev/tool_deps.bzl SRC_CLI_VERSION and the sha256 of the two release tarballs
7+
# MODULE.bazel.lock regenerated by `bazel mod tidy`
8+
#
9+
# Run by .github/workflows/goreleaser.yml after a new latest release. To run locally:
10+
#
11+
# VERSION=8.0.0 SOURCEGRAPH_DIR=~/git/common-repos/sourcegraph/worktrees/main OPEN_PR=0 dev/open-sourcegraph-bump-pr.sh
12+
#
13+
# Environment:
14+
# VERSION src-cli release tag, already published on GitHub (required)
15+
# SOURCEGRAPH_DIR checkout of sourcegraph/sourcegraph to edit (required)
16+
# OPEN_PR 0 edits the checkout and stops, 1 also commits, pushes, and opens the PR (default 1)
17+
# REVIEWER_TEAM GitHub team requested as reviewer on the PR (default platform)
18+
# GH_TOKEN token with push access to sourcegraph/sourcegraph, used by git and gh when OPEN_PR=1
19+
20+
set -euo pipefail
21+
22+
: "${VERSION:?set VERSION to the src-cli release, for example 8.0.0}"
23+
: "${SOURCEGRAPH_DIR:?set SOURCEGRAPH_DIR to a sourcegraph/sourcegraph checkout}"
24+
OPEN_PR="${OPEN_PR:-1}"
25+
REVIEWER_TEAM="${REVIEWER_TEAM:-platform}"
26+
BRANCH="src-cli-bump/${VERSION}"
27+
RELEASE_ASSETS="https://github.com/sourcegraph/src-cli/releases/download/${VERSION}"
28+
29+
echo "--- Reading tarball checksums from the ${VERSION} release"
30+
checksums=$(curl --silent --show-error --fail --location "${RELEASE_ASSETS}/src-cli_${VERSION}_checksums.txt")
31+
checksum_for() {
32+
awk -v file="src-cli_${VERSION}_$1.tar.gz" '$2 == file { print $1 }' <<<"${checksums}"
33+
}
34+
linux_amd64_sha256=$(checksum_for linux_amd64)
35+
darwin_arm64_sha256=$(checksum_for darwin_arm64)
36+
if [[ -z ${linux_amd64_sha256} || -z ${darwin_arm64_sha256} ]]; then
37+
echo "src-cli_${VERSION}_checksums.txt does not list both linux_amd64 and darwin_arm64 tarballs:" >&2
38+
echo "${checksums}" >&2
39+
exit 1
40+
fi
41+
echo "linux_amd64: ${linux_amd64_sha256}"
42+
echo "darwin_arm64: ${darwin_arm64_sha256}"
43+
44+
cd "${SOURCEGRAPH_DIR}"
45+
46+
echo "--- Updating internal/src-cli/consts.go and dev/tool_deps.bzl"
47+
sed -i.bak -E "s/^const MinimumVersion = \"[^\"]+\"/const MinimumVersion = \"${VERSION}\"/" internal/src-cli/consts.go
48+
rm internal/src-cli/consts.go.bak
49+
# The sha256 to replace is the first one after each src-cli http_archive name.
50+
awk -v version="${VERSION}" -v linux="${linux_amd64_sha256}" -v darwin="${darwin_arm64_sha256}" '
51+
/^SRC_CLI_VERSION = "/ { sub(/"[^"]*"/, "\"" version "\"") }
52+
/name = "src-cli-linux-amd64"/ { pending = linux }
53+
/name = "src-cli-darwin-arm64"/ { pending = darwin }
54+
pending != "" && /sha256 = "/ { sub(/sha256 = "[^"]*"/, "sha256 = \"" pending "\""); pending = "" }
55+
{ print }
56+
' dev/tool_deps.bzl >dev/tool_deps.bzl.new && mv dev/tool_deps.bzl.new dev/tool_deps.bzl
57+
58+
echo "--- Regenerating MODULE.bazel.lock"
59+
bazel mod tidy
60+
61+
echo "--- Verifying the pinned tarballs download with the new checksums"
62+
bazel fetch @src-cli-linux-amd64//:src-cli-linux-amd64 @src-cli-darwin-arm64//:src-cli-darwin-arm64
63+
64+
git --no-pager diff --stat
65+
if [[ ${OPEN_PR} != 1 ]]; then
66+
echo "OPEN_PR=${OPEN_PR}: leaving the changes uncommitted in ${SOURCEGRAPH_DIR}"
67+
exit 0
68+
fi
69+
70+
echo "--- Committing and pushing ${BRANCH}"
71+
git checkout -b "${BRANCH}"
72+
git add internal/src-cli/consts.go dev/tool_deps.bzl MODULE.bazel.lock
73+
git commit -m "chore/src-cli: update src-cli to ${VERSION}"
74+
git push --set-upstream origin "${BRANCH}"
75+
76+
echo "--- Opening the pull request"
77+
pull_request_url=$(gh pr create \
78+
--title "chore/src-cli: update src-cli to ${VERSION}" \
79+
--label no-changelog \
80+
--body "src-cli ${VERSION} is published on GitHub, Homebrew, and npm, but \`/.api/src-cli/version\` on every Sourcegraph instance keeps recommending the \`MinimumVersion\` pinned here. This raises the pin so instances serve the new release.
81+
82+
Opened automatically by the src-cli [Build and Release](https://github.com/sourcegraph/src-cli/actions/workflows/goreleaser.yml) workflow for https://github.com/sourcegraph/src-cli/releases/tag/${VERSION}.
83+
84+
- Raise \`MinimumVersion\` in \`internal/src-cli/consts.go\`
85+
- Update \`SRC_CLI_VERSION\` and the tarball checksums in \`dev/tool_deps.bzl\`
86+
- Regenerate \`MODULE.bazel.lock\` with \`bazel mod tidy\`
87+
88+
## Test Plan
89+
90+
CI. The workflow verified the checksums with:
91+
92+
\`\`\`shell
93+
bazel fetch @src-cli-linux-amd64//:src-cli-linux-amd64 @src-cli-darwin-arm64//:src-cli-darwin-arm64
94+
\`\`\`")
95+
echo "${pull_request_url}"
96+
gh api --method POST "repos/sourcegraph/sourcegraph/pulls/${pull_request_url##*/}/requested_reviewers" \
97+
-f "team_reviewers[]=${REVIEWER_TEAM}" >/dev/null
98+
echo "Requested review from @sourcegraph/${REVIEWER_TEAM}"

0 commit comments

Comments
 (0)