2121 steps :
2222 - name : Checkout code
2323 uses : actions/checkout@v4
24+ with :
25+ fetch-depth : 0
26+
27+ - name : Set up Python
28+ uses : actions/setup-python@v5
29+ with :
30+ python-version : " 3.11"
2431
2532 - name : Login to GitHub Container Registry
2633 uses : docker/login-action@v3
@@ -34,27 +41,40 @@ jobs:
3441 with :
3542 driver : docker
3643
37- - name : Determine compose-runner version
38- id : get_version
44+ - name : Build wheel from VCS version
45+ run : |
46+ python -m pip install --upgrade pip build
47+ rm -rf dist
48+ python -m build --wheel
49+ ls -l dist
50+
51+ - name : Determine compose-runner version and Docker tags
52+ id : version
3953 run : |
40- if [[ "${GITHUB_REF_TYPE}" == "branch" ]]; then
41- VERSION="${GITHUB_SHA::12}"
42- elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
43- VERSION="${GITHUB_REF_NAME}"
44- elif [[ "${GITHUB_REF_TYPE}" == "release" ]]; then
45- VERSION="${GITHUB_REF_NAME}"
46- else
47- VERSION="${GITHUB_SHA::12}"
54+ VERSION=$(python - <<'PY'
55+ from pathlib import Path
56+
57+ wheel = next(Path("dist").glob("*.whl")).name
58+ print(wheel.split("-")[1].replace("_", "-"))
59+ PY
60+ )
61+ DOCKER_TAG="${VERSION//+/-}"
62+
63+ if [[ "${GITHUB_REF_TYPE}" == "tag" && "${GITHUB_REF_NAME}" != "${VERSION}" ]]; then
64+ echo "Wheel version ${VERSION} does not match git tag ${GITHUB_REF_NAME}"
65+ exit 1
4866 fi
67+
4968 echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
69+ echo "docker_tag=${DOCKER_TAG}" >> "$GITHUB_OUTPUT"
5070
5171 - name : Build and push Docker image
5272 uses : docker/build-push-action@v7
5373 with :
5474 context : .
5575 push : true
5676 build-args : |
57- COMPOSE_RUNNER_VERSION=${{ steps.get_version .outputs.version }}
77+ COMPOSE_RUNNER_VERSION=${{ steps.version .outputs.version }}
5878 tags : |
59- ghcr.io/neurostuff/nsc-runner:${{ steps.get_version .outputs.version }}
60- ghcr.io/neurostuff/nsc-runner:${{ github.ref_name == 'main' && 'latest' || steps.get_version .outputs.version }}
79+ ghcr.io/neurostuff/nsc-runner:${{ steps.version .outputs.docker_tag }}
80+ ghcr.io/neurostuff/nsc-runner:${{ github.ref_name == 'main' && 'latest' || steps.version .outputs.docker_tag }}
0 commit comments