|
| 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