Skip to content

Commit 2a23210

Browse files
nakasyouchatgpt-codex-connector[bot]CopilotCopilot
authored
ci: use bump type input in publish workflow (#60)
* ci: use bump type input in publish workflow Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com> * Update .github/workflows/publish.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Derive package version from git tags instead of package.json (#62) * Initial plan * fix: derive version from latest tag instead of package.json Co-authored-by: nakasyou <79000684+nakasyou@users.noreply.github.com> * refactor: use git native sorting and add file check Co-authored-by: nakasyou <79000684+nakasyou@users.noreply.github.com> * fix: add validation for empty version and prerelease note Co-authored-by: nakasyou <79000684+nakasyou@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nakasyou <79000684+nakasyou@users.noreply.github.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com> --------- Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent a6c5c58 commit 2a23210

1 file changed

Lines changed: 62 additions & 8 deletions

File tree

.github/workflows/publish.yml

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ on:
1111
- hikkaku
1212
- create-hikkaku
1313
- vite-plugin-turbowarp-packager
14-
version:
15-
description: 'Version (e.g. 1.2.3 or v1.2.3)'
14+
release_type:
15+
description: 'Version bump type'
1616
required: true
17-
type: string
17+
type: choice
18+
options:
19+
- patch
20+
- minor
21+
- major
1822

1923
permissions:
2024
id-token: write
@@ -32,7 +36,7 @@ jobs:
3236
env:
3337
GH_TOKEN: ${{ github.token }}
3438
PACKAGE_NAME: ${{ inputs.package }}
35-
INPUT_VERSION: ${{ inputs.version }}
39+
INPUT_RELEASE_TYPE: ${{ inputs.release_type }}
3640

3741
steps:
3842
- name: Checkout
@@ -56,19 +60,69 @@ jobs:
5660
shell: bash
5761
run: |
5862
package="$PACKAGE_NAME"
59-
version="${INPUT_VERSION#v}"
63+
release_type="$INPUT_RELEASE_TYPE"
6064
6165
if ! [[ "$package" =~ ^(hikkaku|create-hikkaku|vite-plugin-turbowarp-packager)$ ]]; then
6266
echo "Unsupported package: $package"
6367
exit 1
6468
fi
6569
66-
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
67-
echo "Invalid version: $INPUT_VERSION"
68-
echo "Supported examples: 1.2.3, v1.2.3, 1.2.3-beta.1"
70+
if ! [[ "$release_type" =~ ^(major|minor|patch)$ ]]; then
71+
echo "Invalid release_type: $release_type"
72+
echo "Supported values: major, minor, patch"
6973
exit 1
7074
fi
7175
76+
# Derive current version from latest tag for this package
77+
# If no tags exist, fall back to package.json version
78+
# Note: Uses git's version sorting which correctly handles semver including prereleases
79+
latest_tag=$(git tag -l "$package@*" --sort=-version:refname | head -n1)
80+
81+
if [ -n "$latest_tag" ]; then
82+
# Extract version from tag (format: package@version)
83+
current_version="${latest_tag#$package@}"
84+
echo "Found latest tag: $latest_tag (version: $current_version)"
85+
else
86+
# No tags exist, use package.json version as starting point
87+
package_json_path="packages/$package/package.json"
88+
if [ ! -r "$package_json_path" ]; then
89+
echo "package.json not found or not readable: $package_json_path"
90+
exit 1
91+
fi
92+
current_version="$(node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));process.stdout.write(typeof pkg.version==='string'?pkg.version.trim():'')" "$package_json_path")"
93+
if [ -z "$current_version" ]; then
94+
echo "package.json does not contain a valid version field: $package_json_path"
95+
exit 1
96+
fi
97+
echo "No existing tags found, using package.json version: $current_version"
98+
fi
99+
100+
if ! [[ "$current_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)([.-][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
101+
echo "Invalid current package version: $current_version"
102+
exit 1
103+
fi
104+
105+
major="${BASH_REMATCH[1]}"
106+
minor="${BASH_REMATCH[2]}"
107+
patch="${BASH_REMATCH[3]}"
108+
109+
case "$release_type" in
110+
major)
111+
major=$((major + 1))
112+
minor=0
113+
patch=0
114+
;;
115+
minor)
116+
minor=$((minor + 1))
117+
patch=0
118+
;;
119+
patch)
120+
patch=$((patch + 1))
121+
;;
122+
esac
123+
124+
version="$major.$minor.$patch"
125+
72126
tag="$package@$version"
73127
74128
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then

0 commit comments

Comments
 (0)