Skip to content

Commit 993ee0a

Browse files
authored
Use GITHUB_REF_NAME to determine current tag for release workflow (#879)
1 parent ee916cd commit 993ee0a

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

.github/workflows/goreleaser.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ on:
3535
# goreleaser_post [if case 1.] - updates symlink to latest version
3636
# npm [always] - publishes to npm
3737
jobs:
38-
# release_type compares the most recently created tag to the highest versioned tag
39-
# available on the repo to determine if this release is for a new latest version or a
40-
# patch of an older version.
38+
# release_type compares the current tag to the highest versioned tag available on the
39+
# repo to determine if this release is for a new latest version or a patch of an older
40+
# version.
4141
release_type:
4242
name: Determine release type
4343
runs-on: ubuntu-latest
@@ -50,33 +50,42 @@ jobs:
5050
uses: actions/checkout@v3
5151
with:
5252
fetch-depth: 0
53-
- name: Fetch most recent tag, latest (highest version) tag, and second latest tag
53+
- name: Set current tag, latest (highest version) tag, and second latest tag
5454
# For latest and second latest tags, we can't use git tag --sort=version:refname
5555
# because git doesn't have a concept of pre-release versions and thus mis-sorts
5656
# versions like 4.0.0-rc.0 *after* 4.0.0.
5757
run: |
58-
echo "most_recent_tag=$(git tag --sort=taggerdate | tail -1)" >> $GITHUB_ENV
58+
echo "current_tag=${GITHUB_REF_NAME}" >> $GITHUB_ENV
5959
echo "latest_tag=$(git tag | tr - \~ | sort --version-sort | tr \~ - | tail -1)" >> $GITHUB_ENV
6060
echo "second_latest_tag=$(git tag | tr - \~ | sort --version-sort | tr \~ - | tail -2 | sed -n 1p)" >> $GITHUB_ENV
6161
- name: Install semver
6262
run: |
6363
wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
6464
chmod +x /usr/local/bin/semver
6565
- name: Compare tags
66-
# If the most recent tag is also the latest tag, semver compare returns 0. If it's
67-
# a patch of an older version, semver compare will return -1.
66+
# If the current tag is also the latest (highest-versioned) tag, semver compare
67+
# returns 0. If the current tag is older (i.e. it's a patch for an older version),
68+
# semver compare will return -1. By definition, it should be impossible for the
69+
# current tag to be newer than the latest tag unless somehow the current tag is
70+
# not a real tag, but if for some reason this happens, it will be treated the same
71+
# as if it were the latest.
6872
run: |
69-
if [[ $(semver compare ${{ env.latest_tag }} ${{ env.most_recent_tag }}) == 0 ]]
73+
if [ "$(semver compare ${{ env.current_tag }} ${{ env.latest_tag }})" -ge 0 ]
7074
then
7175
echo "is_latest_version=1" >> $GITHUB_ENV
7276
else
7377
echo "is_latest_version=0" >> $GITHUB_ENV
7478
fi
7579
- name: Log variables
7680
run: |
77-
echo "Most recent (current) tag: ${{ env.most_recent_tag }}"
78-
echo "Latest version tag: ${{ env.latest_tag }}"
79-
echo "Building current version as new latest?: ${{ env.is_latest_version }}"
81+
echo "Version for this release: ${{ env.current_tag }}"
82+
echo "Latest version: ${{ env.latest_tag }}"
83+
if [[ ${{ env.is_latest_version }} == 1 ]]
84+
then
85+
echo "Releasing new latest version."
86+
else
87+
echo "Releasing patch of older version."
88+
fi
8089
8190
# goreleaser_pre copies the main formula in our Homebrew tap for the previous latest
8291
# release (second latest tag) to a versioned formula, so that it is preserved when
@@ -103,7 +112,7 @@ jobs:
103112
echo "versioned_classname=SrcCliAT$(echo ${{ env.second_latest_tag }} | sed 's/\.//g')" >> $GITHUB_ENV
104113
- name: Log variables
105114
run: |
106-
echo "Second latest tag: ${{ env.second_latest_tag }}"
115+
echo "Second latest tag (previous latest release): ${{ env.second_latest_tag }}"
107116
echo "Versioned formula file: ${{ env.versioned_formula_file }}"
108117
echo "Versioned classname: ${{ env.versioned_classname }}"
109118
- name: Checkout Homebrew tap

0 commit comments

Comments
 (0)