11name : Self-host Docker Image
22on :
3-
43 workflow_dispatch :
54 inputs :
65 branch :
76 description : " Git branch to build"
87 required : true
9- default : release-v2
10- type : string
11- image_version :
12- description : " Docker image version (e.g. 1.2.3)"
13- required : true
8+ default : build/selfhost-image
149 type : string
1510
1611permissions :
2217 environment : self-host
2318
2419 env :
25- DOCKER_IMAGE_VERSION : ${{ inputs.image_version }}
2620 BUILD_BRANCH : ${{ inputs.branch }}
2721 DOCKER_IMAGE_NAME : sparrowapi/sparrow-api
2822
3226 with :
3327 ref : ${{ env.BUILD_BRANCH }}
3428 fetch-depth : 0
29+
30+ - name : Read version from package.json
31+ id : version
32+ run : |
33+ if ! command -v jq >/dev/null 2>&1; then
34+ echo "jq not found"; exit 1
35+ fi
36+ V=$(jq -r '.version' package.json)
37+ if [ -z "$V" ] || [ "$V" = "null" ]; then
38+ echo "Version not found in package.json"; exit 1
39+ fi
40+ if ! [[ "$V" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
41+ echo "Version $V is not valid semver (expected X.Y.Z)"; exit 1
42+ fi
43+ echo "full=$V" >> "$GITHUB_OUTPUT"
44+
45+
3546 - name : Set up QEMU
3647 uses : docker/setup-qemu-action@v3
3748
4758 - name : Build and push (multi-arch)
4859 run : |
4960 set -euo pipefail
61+ VERSION='${{ steps.version.outputs.full }}'
62+ echo "Building image tag: $VERSION"
5063 docker buildx build \
5164 --platform linux/amd64,linux/arm64 \
5265 --build-arg GITHUB_TOKEN=${{ secrets.SPARROW_GITHUB_TOKEN }} \
53- -t $DOCKER_IMAGE_NAME:${DOCKER_IMAGE_VERSION} \
54- -t $DOCKER_IMAGE_NAME:latest \
66+ -t $DOCKER_IMAGE_NAME:$VERSION \
5567 --push .
0 commit comments