From 0c42d8b8ed82d8e25b04605182a8b83e464a737a Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Wed, 10 Aug 2022 12:38:18 +0800 Subject: [PATCH] ci: Build Gems for releases and upload them. --- .github/workflows/build-gems.sh | 48 +++++++++++ .github/workflows/release.yml | 20 +++-- README.md | 97 +++++++++++++++++++++++ gems/scip-ruby/.gitignore | 2 + gems/scip-ruby/scip-ruby.template.gemspec | 22 +++++ 5 files changed, 183 insertions(+), 6 deletions(-) create mode 100755 .github/workflows/build-gems.sh create mode 100644 README.md create mode 100644 gems/scip-ruby/.gitignore create mode 100644 gems/scip-ruby/scip-ruby.template.gemspec diff --git a/.github/workflows/build-gems.sh b/.github/workflows/build-gems.sh new file mode 100755 index 0000000000..f3f1bc3da3 --- /dev/null +++ b/.github/workflows/build-gems.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# For local testing, do a build and invoke this script from the root +# of the repo with: +# +# NAME="scip-ruby-debug" VERSION="0.0.0" .github/workflows/build-gems.sh + +# Based on build-static-release.sh + +set -eux + +if [ -z "${VERSION:-}" ]; then + echo 'Missing value for $VERSION environment variable' + exit 1 +fi +if [ -z "${NAME:-}" ]; then + echo 'Missing value for $NAME environment variable' + exit 1 +fi + +mkdir -p gems/scip-ruby/bin +cp bazel-bin/main/scip-ruby gems/scip-ruby/bin/scip-ruby +GEMSPEC="$NAME.gemspec" +cleanup() { + rm -rf gems/scip-ruby/bin + rm -rf "gems/scip-ruby/$GEMSPEC" +} +trap cleanup EXIT + +pushd gems/scip-ruby + +cat scip-ruby.template.gemspec \ + | sed -e "s/VERSION_PLACEHOLDER/$VERSION/" -e "s/NAME_PLACEHOLDER/$NAME/" \ + > "$GEMSPEC" + +if [ "$(uname -s)" == "Darwin" ]; then + # Darwin 20 ~ macOS 11 (Big Sur) was released in mid-2020. + # We can publish older releases if someone asks for them. + for i in {20..22}; do + sed -i.bak "s/Gem::Platform::CURRENT/'universal-darwin-$i'/" "$GEMSPEC" + gem build "$GEMSPEC" + mv "$GEMSPEC.bak" "$GEMSPEC" + done +else + gem build "$GEMSPEC" +fi + +popd diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 85c416f67d..50c630a11a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,16 +77,24 @@ jobs: path: log - name: ${{ format('📦 Upload binary ({0})', matrix.config) }} run: | - ls bazel-out - BASE_NAME="scip-ruby-debug" + SUFFIX="-debug" if [ "$CFG" == "release" ]; then - BASE_NAME="scip-ruby" + SUFFIX="" fi - outBinaryPath="$BASE_NAME-$OS-$(uname -m)" - builtBinaryPath="$(find bazel-out/ -type f -name 'scip-ruby')" - mv "$builtBinaryPath" "$outBinaryPath" + outBinaryPath="$scip-ruby-$OS-$(uname -m)${SUFFIX}" + cp bazel-bin/main/scip-ruby "$outBinaryPath" gh release upload "${GITHUB_REF/refs\/tags\//}" "$outBinaryPath" + echo "suffix=$SUFFIX" >> "$GITHUB_ENV" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} OS: ${{ env.OS }} CFG: ${{ matrix.config }} + - name: ${{ format('💎 Build Gem(s) ({0})', matrix.config) }} + run: | + NAME="scip-ruby${{ env.suffix }}" \ + VERSION="${GITHUB_REF/refs\/tags\/scip-ruby-v/}" \ + .github/workflows/build-gems.sh + - name: ${{ format('📦 Upload Gem(s) to GitHub ({0})', matrix.config) }} + run: gh release upload "${GITHUB_REF/refs\/tags\//}" gems/scip-ruby/*.gem + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md new file mode 100644 index 0000000000..07ba24dadd --- /dev/null +++ b/README.md @@ -0,0 +1,97 @@ +# scip-ruby + +Experimental [SCIP](https://github.com/sourcegraph/scip) indexer for Ruby. + +If you have any questions, bug reports, feature requests or feedback, +please [file an issue](https://github.com/sourcegraph/scip-ruby/issues). + +## Supported Configurations + +scip-ruby piggybacks on top of +the [Sorbet](https://github.com/sorbet/sorbet) type-checker. +If you use Sorbet in your project, follow the instructions below. + +Projects which do not use Sorbet are not supported. + +Supported platforms: +- x86_64 Linux +- x86_64 macOS +- arm64 macOS (via Rosetta) + + + + + +## Install and Index + +You can download a +[release binary](https://github.com/sourcegraph/scip-ruby/releases) +and run it directly, similar to invoking Sorbet. + +``` +OS="$(uname -s | tr '[:upper:]' '[:lower:]')" \ +RELEASE_URL="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/sourcegraph/scip-ruby/releases/latest/download" \ +curl -L "$RELEASE_URL/scip-ruby-$OS-x86_64" -o scip-ruby + +chmod +x scip-ruby + +# If using in CI with 'set -e', make sure to wrap the +# scip-ruby invocation in 'set +e' followed by 'set -e' +# so that indexing failures are non-blocking. +./scip-ruby --index-file index.scip --gem-metadata "my-gem-name@vM.N.P" +``` + +The generated index can be uploaded to a Sourcegraph instance +using the [Sourcegraph CLI](https://github.com/sourcegraph/src-cli). + +## Contributing + +See the [Contributing docs](./scip-ruby-CONTRIBUTING.md). diff --git a/gems/scip-ruby/.gitignore b/gems/scip-ruby/.gitignore new file mode 100644 index 0000000000..f2d13343bd --- /dev/null +++ b/gems/scip-ruby/.gitignore @@ -0,0 +1,2 @@ +bin/ +*.gem diff --git a/gems/scip-ruby/scip-ruby.template.gemspec b/gems/scip-ruby/scip-ruby.template.gemspec new file mode 100644 index 0000000000..d30b68cfb0 --- /dev/null +++ b/gems/scip-ruby/scip-ruby.template.gemspec @@ -0,0 +1,22 @@ +# See build-gems.sh for how this file is used. + +Gem::Specification.new do |spec| + spec.name = 'NAME_PLACEHOLDER' + spec.version = 'VERSION_PLACEHOLDER' + spec.summary = 'A SCIP indexer for Ruby' + spec.description = 'Wrapper for the scip-ruby binary' + spec.authors = ['Sourcegraph'] + spec.email = 'code-intel@sourcegraph.com' + spec.files = ['bin/scip-ruby'] # Populated by build-gems.sh + spec.executables = [] + spec.license = 'Apache-2.0' + spec.homepage = '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/sourcegraph/scip-ruby' + spec.metadata = { + "source_code_uri" => "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/sourcegraph/scip-ruby" + } + + # bin/scip-ruby is a native binary, so we are platform dependent + spec.platform = Gem::Platform::CURRENT + + spec.required_ruby_version = ['>= 2.3.0'] +end