Skip to content

Commit f60a97e

Browse files
committed
ci: publish docker images only on release tags
1 parent 145fb4b commit f60a97e

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

.github/workflows/docker.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
run: docker rm -f chatcrystal-smoke || true
9696

9797
publish:
98-
if: github.event_name != 'pull_request'
98+
if: startsWith(github.ref, 'refs/tags/v')
9999
needs: validate
100100
runs-on: ubuntu-latest
101101
permissions:
@@ -113,19 +113,13 @@ jobs:
113113
- name: Verify publish ref
114114
run: |
115115
git fetch --no-tags origin main
116-
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
117-
remote_sha="$(git rev-parse origin/main)"
118-
if [ "${GITHUB_SHA}" != "${remote_sha}" ]; then
119-
echo "::error::Refusing to publish because ${GITHUB_SHA} is not the current origin/main (${remote_sha})."
120-
exit 1
121-
fi
122-
elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
116+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
123117
if ! git merge-base --is-ancestor "${GITHUB_SHA}" origin/main; then
124118
echo "::error::Refusing to publish tag ${GITHUB_REF_NAME} because ${GITHUB_SHA} is not reachable from origin/main."
125119
exit 1
126120
fi
127121
else
128-
echo "::error::Docker image publishing is limited to main and v* tags."
122+
echo "::error::Docker image publishing is limited to v* tags."
129123
exit 1
130124
fi
131125
@@ -148,7 +142,7 @@ jobs:
148142
with:
149143
images: ${{ env.IMAGE_NAME }}
150144
tags: |
151-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
145+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
152146
type=sha,prefix=sha-
153147
type=ref,event=tag
154148
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
@@ -170,6 +164,4 @@ jobs:
170164
echo "::error::GHCR image is not publicly pullable. Open the package settings for ghcr.io/zengliangyi/chatcrystal, change visibility to Public, then rerun this workflow."
171165
exit 1
172166
fi
173-
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
174-
docker pull "${IMAGE_NAME}:latest"
175-
fi
167+
docker pull "${IMAGE_NAME}:latest"

0 commit comments

Comments
 (0)