diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 1b1f1a4ba1..5b75b12f00 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -7,9 +7,63 @@ on: - '!latest' jobs: + # goreleaser-pre copies the main formula in our Homebrew tap for the last release + # (second latest tag) to a versioned formula, so that it is preserved when goreleaser + # runs and overwrites the main formula with the latest build. + goreleaser-pre: + name: Copy previous release + runs-on: ubuntu-latest + outputs: + second_latest_tag: ${{ env.second_latest_tag }} + latest_tag: ${{ env.latest_tag }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Fetch latest and second-latest tags + run: | + echo "second_latest_tag=$(git tag --sort=taggerdate | tail -2 | sed -n 1p)" >> $GITHUB_ENV + echo "latest_tag=$(git tag --sort=taggerdate | tail -1)" >> $GITHUB_ENV + - name: Set versioning variables + run: | + echo "versioned_formula_file=Formula/src-cli@${{ env.second_latest_tag }}.rb" >> $GITHUB_ENV + echo "versioned_classname=SrcCliAT$(echo ${{ env.second_latest_tag }} | sed 's/\.//g')" >> $GITHUB_ENV + - name: Log variables + run: | + echo "Second latest tag: ${{ env.second_latest_tag }}" + echo "Versioned formula file: ${{ env.versioned_formula_file }}" + echo "Versioned classname: ${{ env.versioned_classname }}" + - name: Checkout Homebrew tap + uses: actions/checkout@v3 + with: + repository: sourcegraph/homebrew-src-cli + fetch-depth: 0 + token: ${{ secrets.BOT_CROSS_REPO_PAT }} + - name: Copy main release formula file to versioned formula file + run: cp Formula/src-cli.rb ${{ env.versioned_formula_file }} + # Homebrew expects the name of the class in a versioned formula file to be of the + # format {Formula}AT{Major}{Minor}{Patch}, but the main formula classname is just + # {Formula}, so we manually patch the name: SrcCli -> SrcCliAT### + - name: Rename formula classname + run: sed -i 's/class SrcCli/class ${{ env.versioned_classname }}/' ${{ env.versioned_formula_file }} + - name: Commit result + run: | + git config user.name sourcegraph-bot + git config user.email sourcegraph-bot-github@sourcegraph.com + git add . + git commit -m "Copy previous release" + git push + goreleaser: name: release runs-on: ubuntu-latest + needs: goreleaser-pre + # Passthrough for the outputs from the first job so that they're also available in + # goreleaser-post + outputs: + second_latest_tag: ${{ needs.goreleaser-pre.outputs.second_latest_tag }} + latest_tag: ${{ needs.goreleaser-pre.outputs.latest_tag }} steps: - name: Checkout uses: actions/checkout@v3 @@ -33,6 +87,41 @@ jobs: env: # Use separate access token, because we need a scope:repo token to publish the brew formula. GITHUB_TOKEN: ${{ secrets.GH_PAT }} + + # goreleaser-post updates the symlink name to refer to the new release version. The + # symlink enables users to install the latest src-cli with the versioned command: + # $ brew install sourcegraph/src-cli/src-cli@X.Y.Z + # alongside the command to install it via the main formula: + # $ brew install sourcegraph/src-cli/src-cli + goreleaser-post: + name: Create new release version symlink + runs-on: ubuntu-latest + needs: goreleaser + steps: + - name: Set variables + run: | + echo "old_symlink_name=Aliases/src-cli@${{ needs.goreleaser.outputs.second_latest_tag }}" >> $GITHUB_ENV + echo "new_symlink_name=Aliases/src-cli@${{ needs.goreleaser.outputs.latest_tag }}" >> $GITHUB_ENV + - name: Log variables + run: | + echo "Old symlink: ${{ env.old_symlink_name }}" + echo "New symlink: ${{ env.new_symlink_name }}" + - name: Checkout Homebrew tap + uses: actions/checkout@v3 + with: + repository: sourcegraph/homebrew-src-cli + fetch-depth: 0 + token: ${{ secrets.BOT_CROSS_REPO_PAT }} + - name: Replace symlink + run: mv ${{ env.old_symlink_name }} ${{ env.new_symlink_name }} + - name: Commit result + run: | + git config user.name sourcegraph-bot + git config user.email sourcegraph-bot-github@sourcegraph.com + git add . + git commit -m "Update latest release symlink" + git push + npm: runs-on: ubuntu-latest needs: goreleaser diff --git a/.github/workflows/lsif.yml b/.github/workflows/lsif.yml index 62db1f0b9d..363fa8a5c3 100644 --- a/.github/workflows/lsif.yml +++ b/.github/workflows/lsif.yml @@ -1,6 +1,7 @@ name: LSIF on: - push + jobs: lsif-go: runs-on: ubuntu-latest diff --git a/README.markdown b/README.markdown index e0f01030d4..78671a454c 100644 --- a/README.markdown +++ b/README.markdown @@ -41,6 +41,14 @@ curl -L https://sourcegraph.example.com/.api/src-cli/src_darwin_amd64 -o /usr/lo chmod +x /usr/local/bin/src ``` +or, if you know the specific version to target, for example 3.43.2: + +```bash +brew install sourcegraph/src-cli/src-cli@3.43.2 +``` + +> Note: Versioned formulas are available on Homebrew for Sourcegraph versions 3.43.2 and later. + ### Installation: Linux #### Latest version