Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: fix shallow clones not retrieving a valid semver
  • Loading branch information
ethanndickson committed Jun 20, 2024
commit 2d6cee9daced86c5c83f37aa2731667355d3c772
42 changes: 21 additions & 21 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down