Skip to content

Commit 423347a

Browse files
ci: introduce self-host docker publish workflow (auto tag from package.json) []
1 parent 68d1aaf commit 423347a

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

.github/workflows/sparrow-api-selfhost-publish.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
name: Self-host Docker Image
22
on:
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

1611
permissions:
@@ -22,7 +17,6 @@ jobs:
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

@@ -32,6 +26,23 @@ jobs:
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

@@ -47,9 +58,10 @@ jobs:
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 .

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "project-sparrow-api",
3-
"version": "0.0.1",
3+
"version": "2.29.0",
44
"description": "Backend APIs for Project Sparrow.",
55
"author": "techdome",
66
"license": "",

0 commit comments

Comments
 (0)