From 3c28e4e06b6eaf131a510552ab3890c1adfa043b Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Wed, 5 Oct 2022 11:19:59 +0800 Subject: [PATCH] fix: Print scip-ruby version, not Sorbet version. --- docs/scip-ruby/CONTRIBUTING.md | 25 ++++++++++++++-- scip_indexer/SCIPIndexer.cc | 18 ++++++++++- tools/scripts/publish-scip-ruby.sh | 48 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100755 tools/scripts/publish-scip-ruby.sh diff --git a/docs/scip-ruby/CONTRIBUTING.md b/docs/scip-ruby/CONTRIBUTING.md index d42d3f2ef..417f54a2b 100644 --- a/docs/scip-ruby/CONTRIBUTING.md +++ b/docs/scip-ruby/CONTRIBUTING.md @@ -25,6 +25,7 @@ see the [Design Decisions doc][]. - [Debugging Bazel](#debugging-bazel) - [Debugging on Linux](#debugging-on-linux) - [Creating PRs](#creating-prs) +- [Syncing Sorbet upstream](#syncing-sorbet-upstream) - [Cutting a release](#cutting-a-release) - Troubleshooting - [Known build issues][] @@ -322,10 +323,30 @@ gh pr create -R sourcegraph/scip-ruby This will correctly use the `scip-ruby/master` branch as the target. +## Syncing Sorbet upstream + +1. Create a temporary branch and perform a merge. It doesn't matter + if the code compiles or not, only try to fix conflicts reasonably. + Do NOT modify existing commits/rewrite history here. +2. Create a new commit updating the `scip_ruby_sync_upstream_sorbet_sha` value. +3. If there are compilation/test failures, fix them in a single follow-up commit. + In total, we will have N+1 or N+2 commits in the PR, with N from Sorbet. +4. Once tests are passing, temporarily turn on 'Allow merge commits' in the admin settings. + Merge the PR and turn off merging in the admin settings. + ## Cutting a release -Push a tag matching `scip-ruby-v*` to `scip-ruby/master`. -A CI job should automatically trigger a release. +1. Add release notes to the [CHANGELOG](/CHANGELOG.md). +2. Bump `scip_ruby_version` in `SCIPIndexer.cc`. + +Run the release script: + +```bash +NEW_VERSION=M.N.P ./tools/scripts/publish-scip-ruby.sh +``` + +If there are any errors, fix those and re-run. +A CI job will be kicked off to trigger a release. See the [release workflow](/.github/workflows/release.yml) for details. ## Troubleshooting diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index a324ef609..975a91bb9 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -22,6 +22,7 @@ #include "ast/Trees.h" #include "ast/treemap/treemap.h" #include "cfg/CFG.h" +#include "common/EarlyReturnWithCode.h" #include "common/common.h" #include "common/sort.h" #include "core/Error.h" @@ -58,6 +59,11 @@ static uint32_t fnv1a_32(const string &s) { return h; } +const char scip_ruby_version[] = "0.1.2"; + +// Last updated: https://github.com/sourcegraph/scip-ruby/pull/104 +const char scip_ruby_sync_upstream_sorbet_sha[] = "bb35f6d1d075b27c3296c2eee85cba5c2de8c60f"; + namespace sorbet::scip_indexer { // TODO(varun): This is an inline workaround for https://github.com/sorbet/sorbet/issues/5925 @@ -1157,7 +1163,7 @@ class SCIPSemanticExtension : public SemanticExtension { } scip::ToolInfo toolInfo; toolInfo.set_name("scip-ruby"); - toolInfo.set_version(sorbet_version); + toolInfo.set_version(scip_ruby_version); *toolInfo.add_arguments() = "FIXME"; // FIXME(varun): GlobalState doesn't have access to CLI arguments. 🙁 scip::Metadata metadata; @@ -1263,6 +1269,16 @@ class SCIPSemanticExtensionProvider : public SemanticExtensionProvider { cxxopts::value()); }; unique_ptr readOptions(cxxopts::ParseResult &providedOptions) const override { + if (providedOptions.count("version") > 0) { + // HACK: Just modify the version in place instead of duplicating the logic in sorbet_version.c + // There is some 'sed' replacement going on in that file. + fmt::print("scip-ruby {}\nBased on Sorbet {} {}\n", + absl::StrReplaceAll(sorbet_full_version_string, + {{sorbet_version, scip_ruby_version}, + {fmt::format(".{}", sorbet_build_scm_commit_count), ""}}), + sorbet_version, scip_ruby_sync_upstream_sorbet_sha); + throw sorbet::EarlyReturnWithCode(0); + } if (providedOptions.count("index-file") > 0) { return make_unique( providedOptions["index-file"].as(), diff --git a/tools/scripts/publish-scip-ruby.sh b/tools/scripts/publish-scip-ruby.sh new file mode 100755 index 000000000..ccf91757a --- /dev/null +++ b/tools/scripts/publish-scip-ruby.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -euo pipefail + +{ + +if [ -z "${NEW_VERSION:-}" ]; then + echo "error: Missing value for environment variable NEW_VERSION" + echo "hint: Invoke this script as NEW_VERSION=M.N.P ./tools/scripts/publish-scip-ruby.sh" + exit 1 +fi + +if ! grep -q "## v$NEW_VERSION" CHANGELOG.md; then + echo "error: Missing CHANGELOG entry for v$NEW_VERSION" + echo "note: CHANGELOG entries are required for publishing releases" + exit 1 +fi + +if ! grep -q "const char scip_ruby_version\[\] = \"$NEW_VERSION\"" scip_indexer/SCIPIndexer.cc; then + echo "error: SCIP_RUBY_VERSION in SCIPIndexer.cc doesn't match NEW_VERSION=$NEW_VERSION" + exit 1 +fi + +if ! git diff --quiet; then + echo "error: Found unstaged changes; aborting." + exit 1 +fi + +if ! git diff --quiet --cached; then + echo "error: Found staged-but-uncommitted changes; aborting." + exit 1 +fi + +if ! git remote -v | grep "origin" | grep -q "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/sourcegraph/scip-ruby.git"; then + echo "error: remote 'origin' doesn't point to sourcegraph/scip-ruby" + exit 1 +fi + +if ! git rev-parse --abbrev-ref HEAD | grep -q "scip-ruby/master"; then + echo "error: Releases should be published from scip-ruby/master but HEAD is on a different branch" >&2 + exit 1 +fi + +} >&2 + +TAG="scip-ruby-v$NEW_VERSION" +git tag "$TAG" +git push origin "$TAG"