Skip to content

Commit f3b73e4

Browse files
committed
fix: enhance error handling for package.json version extraction and improve tag filtering in publish-alpha.yml
1 parent b9492eb commit f3b73e4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

.github/workflows/publish-alpha.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,27 @@ jobs:
3838
env:
3939
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
run: |
41-
BASE_VERSION=$(node -p "require('./package.json').version")
41+
# Ensure package.json exists and extract BASE_VERSION
42+
if [[ ! -f package.json ]]; then
43+
echo "Error: package.json not found in the repository"
44+
exit 1
45+
fi
46+
BASE_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "")
47+
if [[ -z "$BASE_VERSION" ]]; then
48+
echo "Error: Failed to extract version from package.json"
49+
exit 1
50+
fi
4251
BASE_VERSION=$(echo "$BASE_VERSION" | sed 's/-.*//')
4352
IMAGE_NAME=ghcr.io/${{ github.repository }}/podverse-api
53+
echo "Base version: $BASE_VERSION"
54+
echo "Image name: $IMAGE_NAME"
4455
4556
# Use gh CLI to list tags for the container image
4657
TAGS_JSON=$(gh api -H "Accept: application/vnd.github+json" \
4758
"/repos/${{ github.repository }}/packages/container/podverse-api/versions" \
48-
--jq '[.[] | .metadata.container.tags[]] | unique')
59+
--jq '[.[] | .metadata.container.tags[]] | unique' 2>/dev/null || echo "[]")
4960
echo "Raw tags JSON: $TAGS_JSON"
50-
TAGS=$(echo "$TAGS_JSON" | jq -r '.[]' | grep "alpha" || true)
61+
TAGS=$(echo "$TAGS_JSON" | jq -r '.[] | select(test("alpha"))' || true)
5162
echo "Filtered alpha tags: $TAGS"
5263
5364
# Try to get the current alpha version (e.g., 5.1.1-alpha.3)
@@ -63,6 +74,7 @@ jobs:
6374
6475
if [[ -z "$CURRENT_ALPHA_NUM" ]]; then
6576
NEXT_VERSION="$BASE_VERSION-alpha.0"
77+
echo "No valid alpha number found. Setting to: $NEXT_VERSION"
6678
elif [[ "$CURRENT_BASE" == "$BASE_VERSION" ]]; then
6779
NEXT_INDEX=$((CURRENT_ALPHA_NUM + 1))
6880
NEXT_VERSION="$BASE_VERSION-alpha.$NEXT_INDEX"

0 commit comments

Comments
 (0)