From 2d6cee9daced86c5c83f37aa2731667355d3c772 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 20 Jun 2024 11:34:32 +0000 Subject: [PATCH 1/2] fix: fix shallow clones not retrieving a valid semver --- scripts/version.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index 4a87853d2c99d..e811018dcf3b7 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -26,29 +26,29 @@ if [[ -n "${CODER_FORCE_VERSION:-}" ]]; then exit 0 fi -# To make contributing easier, if the upstream isn't coder/coder and there are -# no tags we will fall back to 0.1.0 with devel suffix. -remote_url=$(git remote get-url origin) + +# To make contributing easier, if there are no tags, we'll use a default +# version. tag_list=$(git tag) -if ! [[ ${remote_url} =~ [@/]github.com ]] && ! [[ ${remote_url} =~ [:/]coder/coder(\.git)?$ ]] && [[ -z ${tag_list} ]]; then - log - log "INFO(version.sh): It appears you've checked out a fork of Coder." - log "INFO(version.sh): By default GitHub does not include tags when forking." - log "INFO(version.sh): We will use the default version 2.0.0 for this build." - log "INFO(version.sh): To pull tags from upstream, use the following commands:" - log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git" - log "INFO(version.sh): - git fetch upstream" - log - last_tag="v2.0.0" +if [[ -z ${tag_list} ]]; then + log + log "INFO(version.sh): It appears you've checked out a fork or shallow clone of Coder." + log "INFO(version.sh): By default GitHub does not include tags when forking." + log "INFO(version.sh): We will use the default version 2.0.0 for this build." + log "INFO(version.sh): To pull tags from upstream, use the following commands:" + log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git" + log "INFO(version.sh): - git fetch upstream" + log + last_tag="v2.0.0" else - current_commit=$(git rev-parse HEAD) - # Try to find the last tag that contains the current commit - last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1) - # If there is no tag that contains the current commit, - # get the latest tag sorted by semver. - if [[ -z "${last_tag}" ]]; then - last_tag=$(git tag --sort=version:refname | tail -n 1) - fi + current_commit=$(git rev-parse HEAD) + # Try to find the last tag that contains the current commit + last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1) + # If there is no tag that contains the current commit, + # get the latest tag sorted by semver. + if [[ -z "${last_tag}" ]]; then + last_tag=$(git tag --sort=version:refname | tail -n 1) + fi fi version="${last_tag}" From 8ecea9347e08199372e2415f9bd34ec4959e4b14 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 20 Jun 2024 13:04:07 +0000 Subject: [PATCH 2/2] shfmt --- scripts/version.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index e811018dcf3b7..3e813036fbbeb 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -26,29 +26,28 @@ if [[ -n "${CODER_FORCE_VERSION:-}" ]]; then exit 0 fi - # To make contributing easier, if there are no tags, we'll use a default # version. tag_list=$(git tag) if [[ -z ${tag_list} ]]; then - log - log "INFO(version.sh): It appears you've checked out a fork or shallow clone of Coder." - log "INFO(version.sh): By default GitHub does not include tags when forking." - log "INFO(version.sh): We will use the default version 2.0.0 for this build." - log "INFO(version.sh): To pull tags from upstream, use the following commands:" - log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git" - log "INFO(version.sh): - git fetch upstream" - log - last_tag="v2.0.0" + log + log "INFO(version.sh): It appears you've checked out a fork or shallow clone of Coder." + log "INFO(version.sh): By default GitHub does not include tags when forking." + log "INFO(version.sh): We will use the default version 2.0.0 for this build." + log "INFO(version.sh): To pull tags from upstream, use the following commands:" + log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git" + log "INFO(version.sh): - git fetch upstream" + log + last_tag="v2.0.0" else - current_commit=$(git rev-parse HEAD) - # Try to find the last tag that contains the current commit - last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1) - # If there is no tag that contains the current commit, - # get the latest tag sorted by semver. - if [[ -z "${last_tag}" ]]; then - last_tag=$(git tag --sort=version:refname | tail -n 1) - fi + current_commit=$(git rev-parse HEAD) + # Try to find the last tag that contains the current commit + last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1) + # If there is no tag that contains the current commit, + # get the latest tag sorted by semver. + if [[ -z "${last_tag}" ]]; then + last_tag=$(git tag --sort=version:refname | tail -n 1) + fi fi version="${last_tag}"