Skip to content

Commit fbe02db

Browse files
kpal81xdCopilot
andcommitted
Release script update (#7663)
* removed dev from version * Add CommonJS support to ESLint config and improve console log formatting in release script * WIP: release script updated version * Fix release script to use current branch name and improve branch handling logic * Simplify finalization prompt in release script by removing tag existence check * Add git fetch command to ensure remote tags are available before finalizing release * Refactor condition check for branch type in release script * Add comments to clarify branch checks in release script * Normalize prompt responses in release script for consistency * Changed main branch to main * Enhance help message and usage instructions in release script * Add comment to clarify release type determination in release script * Update prompt message for finalizing release to include release type * Refactor release script to improve prompt message and ensure prerelease tagging * Refactor release script to use variables for prerelease identifiers and improve version calculation logic * Add checks for uncommitted changes and streamline version calculation in release script * Update publish workflow to use 'preview' tag instead of 'alpha' for pre-release versions * Remove npm version command from pre-release tag detection in publish workflow * Add publishing step to code.playcanvas.com in workflow * Fix engine version variable in PlayCanvas publish step * Refactor tag parsing and publishing logic in workflow * Fix tag condition in npm publish step to use regex for preview detection * Add silent flag to curl command for PlayCanvas publishing step * Fix curl command in PlayCanvas publishing step to handle errors * Remove deprecated CommonJS configuration and release script * fix: Update PlayCanvas publish endpoint to use secret variable * Update .github/workflows/publish.yaml Co-authored-by: Copilot <[email protected]> * Update release.sh Co-authored-by: Copilot <[email protected]> * Update release.sh Co-authored-by: Copilot <[email protected]> * Update release.sh Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent d1ff92d commit fbe02db

File tree

3 files changed

+126
-247
lines changed

3 files changed

+126
-247
lines changed

.github/workflows/publish.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
tags:
66
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+-preview.[0-9]+'
78

89
jobs:
910
publish-npm:
@@ -19,6 +20,12 @@ jobs:
1920
cache: 'npm'
2021
registry-url: 'https://registry.npmjs.org/'
2122

23+
- name: Parse tag name
24+
run: |
25+
TAG_NAME=${GITHUB_REF#refs/tags/}
26+
echo "TAG=${TAG_NAME}" >> $GITHUB_ENV
27+
echo "VERSION=${TAG_NAME/v/}" >> $GITHUB_ENV
28+
2229
- name: Install Dependencies
2330
run: npm install
2431

@@ -29,6 +36,20 @@ jobs:
2936
run: npm run publint
3037

3138
- name: Publish to npm
32-
run: npm publish --tag lts
39+
run: |
40+
if [[ "${{ env.TAG }}" =~ "preview" ]]; then
41+
tag=preview-lts
42+
else
43+
tag=lts
44+
fi
45+
npm publish --tag $tag
3346
env:
34-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48+
49+
- name: Publish to code.playcanvas.com
50+
run: |
51+
if ! curl -sS -X POST -H "Content-Type: application/json" \
52+
-d '{ "engineVersion": "${{ env.VERSION }}" }' ${{ secrets.PUBLISH_ENDPOINT }}; then
53+
echo "Failed to publish to code.playcanvas.com"
54+
exit 1
55+
fi

release.cjs

Lines changed: 0 additions & 245 deletions
This file was deleted.

release.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash -e
2+
3+
MAIN_BRANCH="main"
4+
5+
PRE_ID_DEV="dev"
6+
PRE_ID_PREVIEW="preview"
7+
8+
RELEASE_PREFIX="release-"
9+
RELEASE_REGEX="^$RELEASE_PREFIX[0-9]+.[0-9]+$"
10+
11+
# Help
12+
HELP=$1
13+
if [[ "$HELP" == "--help" || "$HELP" == "-h" ]]; then
14+
echo """
15+
Run this script on either '$MAIN_BRANCH' or '${RELEASE_PREFIX}X.X' branch.
16+
17+
For minor releases:
18+
On '$MAIN_BRANCH' branch, it will create a new release branch '${RELEASE_PREFIX}X.X' and bump the minor version on '$MAIN_BRANCH'.
19+
20+
For patch or prereleases:
21+
On '${RELEASE_PREFIX}X.X' branch, it asks for a type (patch or prerelease) and creates a tag.
22+
"""
23+
exit 0
24+
fi
25+
26+
# Check for any uncommitted changes (unstaged or staged)
27+
if [[ $(git status --porcelain) ]]; then
28+
echo "There are uncommitted changes. Please commit or stash them before running this script."
29+
exit 1
30+
fi
31+
32+
BRANCH=$(git branch --show-current)
33+
VERSION=$(npm pkg get version | sed 's/"//g')
34+
35+
PARTS=(${VERSION//./ })
36+
MAJOR=${PARTS[0]}
37+
MINOR=${PARTS[1]}
38+
PATCH=${PARTS[2]//-*/}
39+
BUILD=${PARTS[3]}
40+
41+
# Checked out on main branch
42+
if [[ "$BRANCH" == "$MAIN_BRANCH" ]]; then
43+
echo "Create release [BRANCH=$BRANCH, VERSION=$VERSION]"
44+
45+
RELEASE_BRANCH="$RELEASE_PREFIX$MAJOR.$MINOR"
46+
RELEASE_MESSAGE="Branch $MAJOR.$MINOR"
47+
48+
read -p "About to create minor release branch '$RELEASE_BRANCH' taken from '$BRANCH' branch. Continue? (y/N) " -r
49+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
50+
echo "Aborted."
51+
exit 1
52+
fi
53+
54+
# Create release branch from main branch
55+
git branch "$RELEASE_BRANCH" "$BRANCH"
56+
57+
# Bump minor prerelease version on main
58+
npm version preminor --preid=$PRE_ID_DEV --no-git-tag-version
59+
git commit -m "$RELEASE_MESSAGE" -- package.json package-lock.json
60+
61+
# Switch to release branch
62+
git checkout $RELEASE_BRANCH
63+
64+
# Change prerelease version to preview
65+
npm version prerelease --preid=$PRE_ID_PREVIEW --no-git-tag-version
66+
git commit -m "$RELEASE_MESSAGE" -- package.json package-lock.json
67+
exit 0
68+
fi
69+
70+
# Checked out on release branch
71+
if [[ $BRANCH =~ $RELEASE_REGEX ]]; then
72+
# Determine which release type
73+
TYPE=$1
74+
if [[ ! " patch prerelease " =~ " $TYPE " ]]; then
75+
echo "Usage: $0 <patch|prerelease>"
76+
echo "Run '--help' for more information."
77+
exit 1
78+
fi
79+
80+
echo "Finalize release [BRANCH=$BRANCH, VERSION=$VERSION, TYPE=$TYPE]"
81+
82+
# Fetch all remote tags
83+
git fetch --tags
84+
85+
# Calculate the next version
86+
npm version $TYPE --preid=$PRE_ID_PREVIEW --no-git-tag-version >> /dev/null
87+
NEXT_VERSION=$(npm pkg get version | sed 's/"//g')
88+
git reset --hard >> /dev/null
89+
90+
read -p "About to finalize and tag branch '$BRANCH' for 'v$NEXT_VERSION'. Continue? (y/N) " -r
91+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
92+
echo "Aborted."
93+
exit 1
94+
fi
95+
96+
# Bump patch version (with tag)
97+
npm version $TYPE --preid=$PRE_ID_PREVIEW
98+
exit 0
99+
fi
100+
101+
echo "Unrecognized branch '$BRANCH'."
102+
echo "Run '--help' for more information."
103+
exit 1

0 commit comments

Comments
 (0)