From 197cfc3efd61af6809c3f5eebeb98382a2c7e842 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Tue, 9 Jul 2024 17:33:01 +0200 Subject: [PATCH] [haxe] Publish script. Pipeline reacts only to version commits. --- spine-haxe/build.sh | 40 ++++++++++++++++++++++++---------------- spine-haxe/haxelib.json | 2 +- spine-haxe/publish.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 17 deletions(-) create mode 100755 spine-haxe/publish.sh diff --git a/spine-haxe/build.sh b/spine-haxe/build.sh index 31dd485ad..20b2d075e 100755 --- a/spine-haxe/build.sh +++ b/spine-haxe/build.sh @@ -1,24 +1,32 @@ #!/bin/sh set -e -if [ -z "$GITHUB_REF" ]; -then - BRANCH=$(git symbolic-ref --short -q HEAD) +if [ -z "$GITHUB_REF" ]; then + BRANCH=$(git symbolic-ref --short -q HEAD) else - BRANCH=${GITHUB_REF#refs/heads/} + BRANCH=${GITHUB_REF#refs/heads/} fi -echo "Building spine-haxe $BRANCH artifacts" +# Get the latest commit message +COMMIT_MSG=$(git log -1 --pretty=%B) -if ! [ -z "$HAXE_UPDATE_URL" ] && ! [ -z "$BRANCH" ]; -then - echo "Deploying spine-haxe $BRANCH artifacts" - zip -r spine-haxe.zip \ - haxelib.json \ - LICENSE \ - README.md \ - spine-haxe - curl -f -F "file=@spine-haxe.zip" "$HAXE_UPDATE_URL$BRANCH" +# Public only if the commit message is in the correct format +if echo "$COMMIT_MSG" | grep -qE '^\[haxe\] Release [0-9]+\.[0-9]+\.[0-9]+$'; then + VERSION=$(echo "$COMMIT_MSG" | sed -E 's/^\[haxe\] Release ([0-9]+\.[0-9]+\.[0-9]+)$/\1/') + echo "Building spine-haxe $BRANCH artifacts (version $VERSION)" + + if [ ! -z "$HAXE_UPDATE_URL" ] && [ ! -z "$BRANCH" ]; then + echo "Deploying spine-haxe $BRANCH artifacts (version $VERSION)" + zip -r "spine-haxe-$VERSION.zip" \ + haxelib.json \ + LICENSE \ + README.md \ + spine-haxe + curl -f -F "file=@spine-haxe-$VERSION.zip" "$HAXE_UPDATE_URL$BRANCH" + else + echo "Not deploying artifacts. HAXE_UPDATE_URL and/or BRANCH not set." + fi else - echo "Not deploying artifacts. HAXE_UPDATE_URL and/or BRANCH not set." -fi + echo "The commit is not a release - do not publish." + echo "To release the commit has to be in the for: \"[haxe] Release x.y.z\"" +fi \ No newline at end of file diff --git a/spine-haxe/haxelib.json b/spine-haxe/haxelib.json index 3834f70ca..b95426a61 100644 --- a/spine-haxe/haxelib.json +++ b/spine-haxe/haxelib.json @@ -18,7 +18,7 @@ ], "description": "The official Spine Runtime for Haxe", "version": "4.2.0", - "releasenote": "Initial release", + "releasenote": "Update to 4.2.0", "contributors": [ "esotericsoftware" ], diff --git a/spine-haxe/publish.sh b/spine-haxe/publish.sh new file mode 100755 index 000000000..441bb7e0b --- /dev/null +++ b/spine-haxe/publish.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +currentVersion=$(grep -o '"version": "[^"]*' haxelib.json | grep -o '[^"]*$') + +major=$(echo "$currentVersion" | cut -d. -f1) +minor=$(echo "$currentVersion" | cut -d. -f2) +patch=$(echo "$currentVersion" | cut -d. -f3) +newPatch=$((patch + 1)) +newVersion="$major.$minor.$newPatch" + +echo "current version: $currentVersion" +echo "new version: $newVersion" + +sed -i '' "s/$currentVersion/$newVersion/" haxelib.json + +echo "Write Y if you want to commit and push the new version $newVersion." +echo "This will trigger a pipeline that will publish the new version on esoteric software server." +echo "Do you want to proceed [y/n]?" + +read answer +if [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then + git add haxelib.json + git commit -m "[haxe] Release $newVersion" + git push origin haxe-ci + echo "Changes committed and pushed." +else + echo "Commit and push cancelled, but haxelib.json version updated." +fi \ No newline at end of file