Skip to content

Commit c858825

Browse files
committed
Update README, add more comments
1 parent 8fb7009 commit c858825

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

.github/workflows/goreleaser.yml

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,39 @@ name: GoReleaser
33
on:
44
- push
55

6+
# There are two cases where this GitHub action will run:
7+
#
8+
# 1. We are releasing a new latest version for src-cli, as a major, minor, or patch
9+
# update, for instance 4.0.2 -> 4.1.0, OR
10+
# 2. We are releasing a new minor/patch version for an older major/minor version of
11+
# src-cli, for instance if the latest version is 4.0.2 and we're releasing 3.43.3
12+
#
13+
# In both cases, we want to run both goreleaser and npm to publish new versions in all the
14+
# places we care about. For goreleaser publishing to Homebrew, we need to publish to
15+
# different formulas depending on if we're case 1. or case 2, and neither goreleaser nor
16+
# Homebrew has a good way of handling this automatically. In the case of the former (a new
17+
# latest release), we must:
18+
#
19+
# 1. Copy the main formula in our Homebrew tap for the previous latest release to a
20+
# versioned formula
21+
# 2. Build and publish the new release to the main formula
22+
# 3. Update the Homebrew symlink alias for the latest version
23+
#
24+
# In the case of the latter (a patch release for an older version), we only need to:
25+
#
26+
# 1. Build and publish the new release to a versioned Homebrew formula
27+
#
28+
# This action contains 5 jobs to accommodate both cases:
29+
#
30+
# release_type [always] - checks tags, determines if we're case 1. or case 2.
31+
# goreleaser_pre [if case 1.] - copies the main formula to a versioned formula
32+
# goreleaser [always] - runs tests, builds + publishes with goreleaser
33+
# goreleaser_post [if case 1.] - updates symlink to latest version
34+
# npm [always] - publishes to npm
635
jobs:
36+
# release_type compares the most recently created tag to the highest versioned tag
37+
# available on the repo to determine if this release is for a new latest version or a
38+
# patch of an older version.
739
release_type:
840
name: Determine release type
941
runs-on: ubuntu-latest
@@ -16,20 +48,19 @@ jobs:
1648
uses: actions/checkout@v3
1749
with:
1850
fetch-depth: 0
19-
- name: Fetch most recent, latest (highest version), and second latest tags
20-
# TODO: Replace most_recent echo "most_recent_tag=$(git tag --sort=taggerdate | tail -1)" >> $GITHUB_ENV
51+
- name: Fetch most recent tag, latest (highest version) tag, and second latest tag
52+
# TODO: to fake a patch release: echo "most_recent_tag=3.43.3" >> $GITHUB_ENV
2153
run: |
22-
echo "most_recent_tag=3.43.3" >> $GITHUB_ENV
54+
echo "most_recent_tag=$(git tag --sort=taggerdate | tail -1)" >> $GITHUB_ENV
2355
echo "latest_tag=$(git tag --sort=version:refname | tail -1)" >> $GITHUB_ENV
2456
echo "second_latest_tag=$(git tag --sort=version:refname | tail -2 | sed -n 1p)" >> $GITHUB_ENV
2557
- name: Install semver
2658
run: |
2759
wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
2860
chmod +x /usr/local/bin/semver
2961
- name: Compare tags
30-
# If the most recent tag IS the latest tag, semver compare returns 0. If it's a
31-
# patch of an earlier version, semver compare will return -1. It shouldn't be
32-
# possible that the most recent tag is a newer version than the latest.
62+
# If the most recent tag is also the latest tag, semver compare returns 0. If it's
63+
# a patch of an older version, semver compare will return -1.
3364
run: |
3465
if [[ $(semver compare ${{ env.latest_tag }} ${{ env.most_recent_tag }}) == 0 ]]
3566
then
@@ -40,10 +71,9 @@ jobs:
4071
- name: Log variables
4172
run: |
4273
echo "Most recent (current) tag: ${{ env.most_recent_tag }}"
43-
echo "Latest tag: ${{ env.latest_tag }}"
74+
echo "Latest version tag: ${{ env.latest_tag }}"
4475
echo "Building current version as new latest?: ${{ env.is_latest_version }}"
4576
46-
4777
# goreleaser_pre copies the main formula in our Homebrew tap for the previous latest
4878
# release (second latest tag) to a versioned formula, so that it is preserved when
4979
# goreleaser runs and overwrites the main formula for the latest build.
@@ -83,7 +113,7 @@ jobs:
83113
run: cp Formula/src-cli.rb ${{ env.versioned_formula_file }}
84114
# Homebrew expects the name of the class in a versioned formula file to be of the
85115
# format {Formula}AT{Major}{Minor}{Patch}, but the main formula classname is just
86-
# {Formula}, so we manually patch the name: SrcCli -> SrcCliAT###
116+
# {Formula}, so we manually update the name: SrcCli -> SrcCliAT###
87117
- name: Rename formula classname
88118
run: sed -i 's/class SrcCli/class ${{ env.versioned_classname }}/' ${{ env.versioned_formula_file }}
89119
- name: Commit result
@@ -95,12 +125,14 @@ jobs:
95125
git commit -m "Copy previous release"
96126
git push --dry-run
97127
128+
# goreleaser runs tests before building, then uses goreleaser to publish to Homebrew and
129+
# Docker Hub.
98130
goreleaser:
99131
name: Run goreleaser
100132
runs-on: ubuntu-latest
101133
needs: [release_type, goreleaser_pre]
102134
# By default, this job will be skipped if either "needs" job is skipped. This tells
103-
# GitHub actions to always run it, so long as the previous jobs didn't fail.
135+
# GitHub actions to always run it, so long as the previous jobs that ran didn't fail.
104136
if: |
105137
always() &&
106138
(needs.release_type.result == 'success') &&
@@ -114,6 +146,9 @@ jobs:
114146
- name: Set variables
115147
run: echo "is_latest_version=${{ needs.release_type.outputs.is_latest_version }}" >> $GITHUB_ENV
116148
- name: Set config file
149+
# These goreleaser config files are identical except for the brews.name template.
150+
# Homebrew expects the main formula to be named one way, and versioned formulas to
151+
# be named another, but goreleaser only allows us to specify a single template.
117152
run: |
118153
if [[ ${{ env.is_latest_version }} == 1 ]]
119154
then
@@ -191,6 +226,7 @@ jobs:
191226
git commit -m "Update latest release symlink"
192227
git push --dry-run
193228
229+
# npm publishes the new version to the npm package registry
194230
# npm:
195231
# runs-on: ubuntu-latest
196232
# needs: goreleaser

README.markdown renamed to README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/
2626
chmod +x /usr/local/bin/src
2727
```
2828

29-
or
29+
or with Homebrew:
3030

3131
```bash
3232
brew install sourcegraph/src-cli/src-cli
3333
```
3434

35+
or with npm:
36+
37+
```bash
38+
npm install -g @sourcegraph/src
39+
```
40+
3541
#### Version compatible with your Sourcegraph instance
3642

3743
Replace `sourcegraph.example.com` with your Sourcegraph instance URL:
@@ -47,6 +53,12 @@ or, if you know the specific version to target, for example 3.43.2:
4753
brew install sourcegraph/src-cli/src-cli@3.43.2
4854
```
4955

56+
or with npm/npx:
57+
58+
```bash
59+
npx @sourcegraph/src@3.43.2 version
60+
```
61+
5062
> Note: Versioned formulas are available on Homebrew for Sourcegraph versions 3.43.2 and later.
5163
5264
### Installation: Linux
@@ -58,6 +70,12 @@ curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/s
5870
chmod +x /usr/local/bin/src
5971
```
6072

73+
or with npm:
74+
75+
```bash
76+
npm install -g @sourcegraph/src
77+
```
78+
6179
#### Version compatible with your Sourcegraph instance
6280

6381
Replace `sourcegraph.example.com` with your Sourcegraph instance URL:
@@ -67,6 +85,12 @@ curl -L https://sourcegraph.example.com/.api/src-cli/src_linux_amd64 -o /usr/loc
6785
chmod +x /usr/local/bin/src
6886
```
6987

88+
or, with npm/npx, if you know the specific version to target, for example 3.43.2:
89+
90+
```bash
91+
npx @sourcegraph/src@3.43.2 version
92+
```
93+
7094
### Installation: Windows
7195

7296
See [Sourcegraph CLI for Windows](WINDOWS.md).

0 commit comments

Comments
 (0)