Skip to content

fix: fix shallow clones not retrieving a valid semver #13609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2024
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
Prev Previous commit
shfmt
  • Loading branch information
ethanndickson committed Jun 20, 2024
commit 8ecea9347e08199372e2415f9bd34ec4959e4b14
35 changes: 17 additions & 18 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Loading