Skip to content

Commit 4467cab

Browse files
committed
feat: add versioning logic to GitHub Actions workflow and update package.json version
1 parent 2d5c9ee commit 4467cab

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,51 @@ jobs:
6363
pnpm run build:stable
6464
fi
6565
66+
- name: Get current version
67+
id: current_version
68+
run: |
69+
CURRENT_VERSION=$(node -p "require('./package.json').version")
70+
echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
71+
72+
- name: Calculate new version
73+
id: new_version
74+
run: |
75+
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
76+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
77+
# Split version into parts
78+
IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION"
79+
PATCH=$((version_parts[2] + 1))
80+
NEW_VERSION="${version_parts[0]}.${version_parts[1]}.${PATCH}"
81+
82+
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
83+
NEW_VERSION="${NEW_VERSION}-alpha"
84+
fi
85+
else
86+
NEW_VERSION="$CURRENT_VERSION"
87+
fi
88+
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
89+
90+
- name: Update package.json
91+
if: github.event_name == 'workflow_dispatch'
92+
run: |
93+
NEW_VERSION="${{ steps.new_version.outputs.version }}"
94+
# Use node to update package.json to preserve formatting
95+
node -e "
96+
const fs = require('fs');
97+
const package = JSON.parse(fs.readFileSync('package.json'));
98+
package.version = '$NEW_VERSION';
99+
fs.writeFileSync('package.json', JSON.stringify(package, null, 2) + '\n');
100+
"
101+
102+
- name: Commit version update
103+
if: github.event_name == 'workflow_dispatch'
104+
run: |
105+
git config user.name 'github-actions[bot]'
106+
git config user.email 'github-actions[bot]@users.noreply.github.com'
107+
git add package.json
108+
git commit -m "chore: update package.json version to ${{ steps.new_version.outputs.version }}"
109+
git push
110+
66111
- name: Get Package Version
67112
id: package_version
68113
run: |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aithranetwork/plugin-aithra-toolkit",
3-
"version": "0.0.5",
3+
"version": "0.0.5-alpha",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

0 commit comments

Comments
 (0)