From 8c8163ef62cf9c4677c8e800f36270af27930f42 Mon Sep 17 00:00:00 2001 From: Santiago Bernhardt Date: Sat, 7 Jan 2023 07:00:45 +1300 Subject: [PATCH] Hotfix - Validate default_branch only when history type full (#244) * validate default_branch when history type full * This var is branch_history * there is no head in the container hence we change the strategy for filtering * Add readme warning when combining history full without specifying the default branch an is not main or master --- README.md | 2 +- entrypoint.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d264b7ab..60df6021 100755 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret - **GITHUB_TOKEN** **_(required)_** - Required for permission to tag the repo. - **DEFAULT_BUMP** _(optional)_ - Which type of bump to use when none explicitly provided (default: `minor`). -- **DEFAULT_BRANCH** _(optional)_ - Overwrite the default branch its read from Github Runner env var but can be overwritten (default: `$GITHUB_BASE_REF`). +- **DEFAULT_BRANCH** _(optional)_ - Overwrite the default branch its read from Github Runner env var but can be overwritten (default: `$GITHUB_BASE_REF`). Strongly recommended to set this var if using anything else than master or main as default branch otherwise in combination with history full will error. - **WITH_V** _(optional)_ - Tag version with `v` character. - **RELEASE_BRANCHES** _(optional)_ - Comma separated list of branches (bash reg exp accepted) that will generate the release tags. Other branches and pull-requests generate versions postfixed with the commit hash and do not generate any tag. Examples: `master` or `.*` or `release.*,hotfix.*,master` ... - **CUSTOM_TAG** _(optional)_ - Set a custom tag, useful when generating tag based on f.ex FROM image in a docker image. **Setting this tag will invalidate any other settings set!** diff --git a/entrypoint.sh b/entrypoint.sh index c651f777..95b93b58 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -126,10 +126,10 @@ then fi # sanitize that the default_branch is set (via env var when running on PRs) else find it natively -if [ -z "${default_branch}" ] +if [ -z "${default_branch}" ] && [ "$branch_history" == "full" ] then echo "The DEFAULT_BRANCH should be autodetected when tag-action runs on on PRs else must be defined, See: https://github.com/anothrNick/github-tag-action/pull/230, since is not defined we find it natively" - default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') + default_branch=$(git branch -rl '*/master' '*/main' | cut -d / -f2) echo "default_branch=${default_branch}" # re check this if [ -z "${default_branch}" ]