@@ -3,11 +3,20 @@ name: Publish Docker image
33on :
44 push :
55 branches :
6- - main
76 - " v*"
87 tags :
98 - " v*"
109 workflow_dispatch :
10+ inputs :
11+ tag_name :
12+ description : " Docker release tag name to use, for example v0.3.0"
13+ required : false
14+ type : string
15+ publish_release_tags :
16+ description : " Publish stable release Docker tags for tag_name"
17+ required : false
18+ default : false
19+ type : boolean
1120
1221concurrency :
1322 group : ${{ github.workflow }}-${{ github.ref }}
4453 release="false"
4554 short_sha="${GITHUB_SHA::12}"
4655 exact_tag="$(git tag --points-at "${GITHUB_SHA}" --list 'v*' | sort -V | tail -n 1 || true)"
56+ input_tag_name="${INPUT_TAG_NAME:-}"
57+ input_publish_release_tags="${INPUT_PUBLISH_RELEASE_TAGS:-false}"
4758 ref_name_safe="$(printf '%s' "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E 's#[^a-z0-9_.-]+#-#g; s#^[.-]+##; s#[.-]+$##')"
4859 if [[ -z "${ref_name_safe}" ]]; then
4960 ref_name_safe="${short_sha}"
@@ -62,11 +73,29 @@ jobs:
6273 version="${exact_tag}"
6374 publish="true"
6475 release="true"
65- elif [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == refs/heads/v* ]]; then
76+ elif [[ "${GITHUB_REF}" == refs/heads/v* ]]; then
6677 version="${ref_name_safe}-${short_sha}"
6778 publish="true"
6879 elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
69- version="${ref_name_safe}-${short_sha}"
80+ if [[ -n "${input_tag_name}" ]]; then
81+ if [[ "${input_tag_name}" != v* ]]; then
82+ echo "Manual release Docker publishing requires a v* tag_name input." >&2
83+ exit 1
84+ fi
85+ version="${input_tag_name}"
86+ release="${input_publish_release_tags}"
87+ if [[ "${release}" == "true" ]]; then
88+ git fetch origin +refs/heads/main:refs/remotes/origin/main --no-tags
89+ git fetch origin +refs/tags/"${input_tag_name}":refs/tags/"${input_tag_name}"
90+ tag_commit="$(git rev-list -n 1 "${input_tag_name}")"
91+ if ! git merge-base --is-ancestor "${tag_commit}" refs/remotes/origin/main; then
92+ echo "Tag ${input_tag_name} is not on origin/main; refusing to publish release Docker tags." >&2
93+ exit 1
94+ fi
95+ fi
96+ else
97+ version="${ref_name_safe}-${short_sha}"
98+ fi
7099 publish="true"
71100 else
72101 version="${ref_name_safe}-${short_sha}"
86115 echo "Using version: ${version}"
87116 echo "Publish Docker images: ${publish}"
88117 echo "Release Docker tags: ${release}"
118+ env :
119+ INPUT_TAG_NAME : ${{ inputs.tag_name || '' }}
120+ INPUT_PUBLISH_RELEASE_TAGS : ${{ inputs.publish_release_tags }}
89121
90122 build :
91123 name : Build server${{ matrix.config.display_suffix }}
0 commit comments