From 5fe29b51a2515a67f247c6d3b93276f7817817bf Mon Sep 17 00:00:00 2001 From: courier-new Date: Thu, 13 Oct 2022 12:17:10 -0700 Subject: [PATCH 1/5] WIP actions workflow --- .github/workflows/goreleaser2.yml | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/goreleaser2.yml diff --git a/.github/workflows/goreleaser2.yml b/.github/workflows/goreleaser2.yml new file mode 100644 index 0000000000..5de86df32e --- /dev/null +++ b/.github/workflows/goreleaser2.yml @@ -0,0 +1,75 @@ +name: GoReleaser + +on: + push: + # TODO: Restore me + # tags: + # - '*' + # - '!latest' + +jobs: + goreleaser-pre: + name: prepare-previous-release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Fetch last tag + id: last_tag + run: echo "::set-output name=tag::$((git tag --sort=taggerdate | tail -1))" + - name: Show last tag + run: | + echo "Output from last tag: ${{steps.last-tag.outputs.tag}}" + # - name: Checkout Homebrew tap + # - name: Copy main release formula file to versioned formula file + # - name: Rename formula classname to match + # - name: Commit result + # goreleaser: + # name: release + # runs-on: ubuntu-latest + # needs: goreleaser-pre + # steps: + # - name: Checkout + # uses: actions/checkout@v3 + # with: + # fetch-depth: 0 + # - name: Set up Go + # uses: actions/setup-go@v3 + # with: + # go-version: 1.18 + # - run: go get -d -t ./... + # - run: go test -i ./... + # - run: go test -race -v ./... + # - run: echo "${DOCKER_PASSWORD}" | docker login -u=sourcegraphci --password-stdin + # env: + # DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + # - name: Run GoReleaser + # uses: goreleaser/goreleaser-action@v2 + # with: + # version: latest + # args: release --rm-dist + # env: + # # Use separate access token, because we need a scope:repo token to publish the brew formula. + # GITHUB_TOKEN: ${{ secrets.GH_PAT }} + # npm: + # runs-on: ubuntu-latest + # needs: goreleaser + # steps: + # - name: Checkout + # uses: actions/checkout@v3 + # with: + # fetch-depth: 0 + # - uses: actions/setup-node@v3 + # with: + # node-version: 16 + # registry-url: 'https://registry.npmjs.org' + # - run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + # - run: echo "Releasing version ${{ env.version }}" + # - run: yarn version --no-git-tag-version --new-version "${{ env.VERSION }}" + # working-directory: npm-distribution + # - run: npm publish --access public + # working-directory: npm-distribution + # env: + # NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} From 1a43f06ec16889f6d47aa9c5b04b932f54fc99aa Mon Sep 17 00:00:00 2001 From: courier-new Date: Thu, 13 Oct 2022 12:22:09 -0700 Subject: [PATCH 2/5] Temporarily disable other actions for testing --- .github/workflows/go-ci.yml | 4 +++- .github/workflows/go-lint.yml | 4 +++- .github/workflows/goreleaser-check.yml | 4 +++- .github/workflows/goreleaser2.yml | 2 +- .github/workflows/lsif.yml | 5 ++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go-ci.yml b/.github/workflows/go-ci.yml index 5f5f19d1fa..4c019dfc1f 100644 --- a/.github/workflows/go-ci.yml +++ b/.github/workflows/go-ci.yml @@ -1,7 +1,9 @@ name: Go CI on: - - push + push: + branches: + - main jobs: go-test: diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml index cb1accdbe3..14703d51c7 100644 --- a/.github/workflows/go-lint.yml +++ b/.github/workflows/go-lint.yml @@ -1,7 +1,9 @@ name: Go Lint on: - - push + push: + branches: + - main jobs: go-test: diff --git a/.github/workflows/goreleaser-check.yml b/.github/workflows/goreleaser-check.yml index d5723607a0..68b3faa199 100644 --- a/.github/workflows/goreleaser-check.yml +++ b/.github/workflows/goreleaser-check.yml @@ -1,7 +1,9 @@ name: GoReleaser check on: - - push + push: + branches: + - main jobs: goreleaser: diff --git a/.github/workflows/goreleaser2.yml b/.github/workflows/goreleaser2.yml index 5de86df32e..9629e39c96 100644 --- a/.github/workflows/goreleaser2.yml +++ b/.github/workflows/goreleaser2.yml @@ -1,4 +1,4 @@ -name: GoReleaser +name: GoReleaser WIP on: push: diff --git a/.github/workflows/lsif.yml b/.github/workflows/lsif.yml index 62db1f0b9d..bb7e7c7ec9 100644 --- a/.github/workflows/lsif.yml +++ b/.github/workflows/lsif.yml @@ -1,6 +1,9 @@ name: LSIF on: - - push + push: + branches: + - main + jobs: lsif-go: runs-on: ubuntu-latest From 94479f3318b48bb060449212784a35d0fb666284 Mon Sep 17 00:00:00 2001 From: courier-new Date: Thu, 13 Oct 2022 12:29:44 -0700 Subject: [PATCH 3/5] WIP --- .github/workflows/goreleaser2.yml | 93 ++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/.github/workflows/goreleaser2.yml b/.github/workflows/goreleaser2.yml index 9629e39c96..38c410a594 100644 --- a/.github/workflows/goreleaser2.yml +++ b/.github/workflows/goreleaser2.yml @@ -9,28 +9,59 @@ on: jobs: goreleaser-pre: - name: prepare-previous-release + 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 last tag - id: last_tag - run: echo "::set-output name=tag::$((git tag --sort=taggerdate | tail -1))" - - name: Show last tag + - name: Fetch latest and second-latest tags run: | - echo "Output from last tag: ${{steps.last-tag.outputs.tag}}" - # - name: Checkout Homebrew tap - # - name: Copy main release formula file to versioned formula file - # - name: Rename formula classname to match - # - name: Commit result - # goreleaser: - # name: release - # runs-on: ubuntu-latest - # needs: goreleaser-pre - # steps: + 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: courier-new/homebrew-src-cli-test + 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 }} + - name: Rename formula classname + run: | + sed -i 's/class SrcCli/class ${{ env.versioned_classname }}/' ${{ env.versioned_formula_file }} + cat ${{ 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 + outputs: + second_latest_tag: ${{ needs.goreleaser-pre.outputs.second_latest_tag }} + latest_tag: ${{ needs.goreleaser-pre.outputs.latest_tag }} + steps: + - name: Psyche! + run: echo "Hi!" # - name: Checkout # uses: actions/checkout@v3 # with: @@ -53,6 +84,38 @@ 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: + name: Create new release version symlink + runs-on: ubuntu-latest + needs: goreleaser + steps: + - name: Set variables + run: | + echo "old_symlink_name=src-cli@${{ needs.goreleaser.outputs.second_latest_tag }}" >> $GITHUB_ENV + echo "new_symlink_name=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: courier-new/homebrew-src-cli-test + fetch-depth: 0 + token: ${{ secrets.BOT_CROSS_REPO_PAT }} + - name: Replace symlink + run: | + cd Aliases + 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 From 03f5628bb448109b46ab4ce4ea75fdad8846ccb0 Mon Sep 17 00:00:00 2001 From: courier-new Date: Thu, 13 Oct 2022 18:26:25 -0700 Subject: [PATCH 4/5] Cleanup --- .github/workflows/go-ci.yml | 4 +- .github/workflows/go-lint.yml | 4 +- .github/workflows/goreleaser-check.yml | 4 +- .github/workflows/goreleaser.yml | 89 ++++++++++++++++ .github/workflows/goreleaser2.yml | 138 ------------------------- .github/workflows/lsif.yml | 4 +- 6 files changed, 93 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/goreleaser2.yml diff --git a/.github/workflows/go-ci.yml b/.github/workflows/go-ci.yml index 4c019dfc1f..5f5f19d1fa 100644 --- a/.github/workflows/go-ci.yml +++ b/.github/workflows/go-ci.yml @@ -1,9 +1,7 @@ name: Go CI on: - push: - branches: - - main + - push jobs: go-test: diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml index 14703d51c7..cb1accdbe3 100644 --- a/.github/workflows/go-lint.yml +++ b/.github/workflows/go-lint.yml @@ -1,9 +1,7 @@ name: Go Lint on: - push: - branches: - - main + - push jobs: go-test: diff --git a/.github/workflows/goreleaser-check.yml b/.github/workflows/goreleaser-check.yml index 68b3faa199..d5723607a0 100644 --- a/.github/workflows/goreleaser-check.yml +++ b/.github/workflows/goreleaser-check.yml @@ -1,9 +1,7 @@ name: GoReleaser check on: - push: - branches: - - main + - push jobs: goreleaser: 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/goreleaser2.yml b/.github/workflows/goreleaser2.yml deleted file mode 100644 index 38c410a594..0000000000 --- a/.github/workflows/goreleaser2.yml +++ /dev/null @@ -1,138 +0,0 @@ -name: GoReleaser WIP - -on: - push: - # TODO: Restore me - # tags: - # - '*' - # - '!latest' - -jobs: - 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: courier-new/homebrew-src-cli-test - 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 }} - - name: Rename formula classname - run: | - sed -i 's/class SrcCli/class ${{ env.versioned_classname }}/' ${{ env.versioned_formula_file }} - cat ${{ 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 - outputs: - second_latest_tag: ${{ needs.goreleaser-pre.outputs.second_latest_tag }} - latest_tag: ${{ needs.goreleaser-pre.outputs.latest_tag }} - steps: - - name: Psyche! - run: echo "Hi!" - # - name: Checkout - # uses: actions/checkout@v3 - # with: - # fetch-depth: 0 - # - name: Set up Go - # uses: actions/setup-go@v3 - # with: - # go-version: 1.18 - # - run: go get -d -t ./... - # - run: go test -i ./... - # - run: go test -race -v ./... - # - run: echo "${DOCKER_PASSWORD}" | docker login -u=sourcegraphci --password-stdin - # env: - # DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - # - name: Run GoReleaser - # uses: goreleaser/goreleaser-action@v2 - # with: - # version: latest - # args: release --rm-dist - # env: - # # Use separate access token, because we need a scope:repo token to publish the brew formula. - # GITHUB_TOKEN: ${{ secrets.GH_PAT }} - - goreleaser-post: - name: Create new release version symlink - runs-on: ubuntu-latest - needs: goreleaser - steps: - - name: Set variables - run: | - echo "old_symlink_name=src-cli@${{ needs.goreleaser.outputs.second_latest_tag }}" >> $GITHUB_ENV - echo "new_symlink_name=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: courier-new/homebrew-src-cli-test - fetch-depth: 0 - token: ${{ secrets.BOT_CROSS_REPO_PAT }} - - name: Replace symlink - run: | - cd Aliases - 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 - # steps: - # - name: Checkout - # uses: actions/checkout@v3 - # with: - # fetch-depth: 0 - # - uses: actions/setup-node@v3 - # with: - # node-version: 16 - # registry-url: 'https://registry.npmjs.org' - # - run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - # - run: echo "Releasing version ${{ env.version }}" - # - run: yarn version --no-git-tag-version --new-version "${{ env.VERSION }}" - # working-directory: npm-distribution - # - run: npm publish --access public - # working-directory: npm-distribution - # env: - # NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/lsif.yml b/.github/workflows/lsif.yml index bb7e7c7ec9..363fa8a5c3 100644 --- a/.github/workflows/lsif.yml +++ b/.github/workflows/lsif.yml @@ -1,8 +1,6 @@ name: LSIF on: - push: - branches: - - main + - push jobs: lsif-go: From 88704afdc2b8a76ee2affa35435aa8d3a152fef7 Mon Sep 17 00:00:00 2001 From: courier-new Date: Thu, 13 Oct 2022 18:43:02 -0700 Subject: [PATCH 5/5] Update README --- README.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) 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