@@ -3,7 +3,39 @@ name: GoReleaser
33on :
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
635jobs :
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
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.
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
0 commit comments