-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
96 lines (88 loc) · 3.58 KB
/
action.yml
File metadata and controls
96 lines (88 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: 'Tessl Smart Publish'
description: 'Publish a tessl tile, auto-bumping patch from the registry'
inputs:
token:
description: 'Tessl API token'
required: true
path:
description: 'Path to the tile directory (default: repo root)'
required: false
default: '.'
outputs:
version:
description: 'The version that was published'
value: ${{ steps.publish.outputs.version }}
runs:
using: 'composite'
steps:
- name: Setup Tessl CLI
uses: tesslio/setup-tessl@v2
with:
token: ${{ inputs.token }}
- name: Smart publish
id: publish
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
TILE_PATH="${{ inputs.path }}"
TILE_JSON="$TILE_PATH/tile.json"
TILE_NAME=$(jq -r .name "$TILE_JSON")
LOCAL=$(jq -r .version "$TILE_JSON")
# Query registry for the latest published version.
# Only treat the expected "not found" case as first publish; surface all
# other failures so auth/network/CLI issues do not get silently masked.
if INFO_OUTPUT=$(tessl tile info "$TILE_NAME" 2>&1); then
LATEST=$(printf '%s\n' "$INFO_OUTPUT" | grep 'Latest Version' | awk '{print $NF}')
if [ -z "$LATEST" ]; then
echo "::error::Unable to determine latest published version for $TILE_NAME from 'tessl tile info' output."
exit 1
fi
else
if printf '%s\n' "$INFO_OUTPUT" | grep -qi '404'; then
LATEST=""
else
echo "::error::Failed to query Tessl registry for $TILE_NAME: $INFO_OUTPUT"
exit 1
fi
fi
if [ -z "$LATEST" ]; then
# First publish — use version from tile.json as-is
VERSION="$LOCAL"
echo "First publish — using tile.json version $VERSION"
else
# Compare: if tile.json is ahead of registry, respect the manual bump
# Version comparison: split into components
local_parts=(${LOCAL//./ })
latest_parts=(${LATEST//./ })
LOCAL_NUM=$(( ${local_parts[0]} * 1000000 + ${local_parts[1]} * 1000 + ${local_parts[2]} ))
LATEST_NUM=$(( ${latest_parts[0]} * 1000000 + ${latest_parts[1]} * 1000 + ${latest_parts[2]} ))
if [ "$LOCAL_NUM" -gt "$LATEST_NUM" ]; then
VERSION="$LOCAL"
echo "tile.json ($LOCAL) is ahead of registry ($LATEST) — publishing as-is"
else
MAJOR=$(echo "$LATEST" | cut -d. -f1)
MINOR=$(echo "$LATEST" | cut -d. -f2)
PATCH=$(echo "$LATEST" | cut -d. -f3)
VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
echo "Auto-bumping from registry $LATEST to $VERSION"
fi
fi
jq --arg v "$VERSION" '.version = $v' "$TILE_JSON" > "$TILE_JSON.tmp" && mv "$TILE_JSON.tmp" "$TILE_JSON"
tessl tile publish "$TILE_PATH"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Commit the version back to the repo if it changed
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$TILE_JSON"
git diff --cached --quiet || {
git commit -m "Bump $TILE_NAME to $VERSION [skip ci]"
git push 2>/dev/null || {
BRANCH="tessl-bump-$VERSION"
git checkout -b "$BRANCH"
git push -u origin "$BRANCH"
gh pr create \
--title "Bump $TILE_NAME to $VERSION [skip ci]" \
--body "Auto-created by patch-version-publish — direct push blocked by branch protection."
}
}