Skip to content

Commit

Permalink
feat: add versioning logic to GitHub Actions workflow and update pack…
Browse files Browse the repository at this point in the history
…age.json version
  • Loading branch information
bucurdavid committed Feb 14, 2025
1 parent 2d5c9ee commit 4467cab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,51 @@ jobs:
pnpm run build:stable
fi
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Split version into parts
IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION"
PATCH=$((version_parts[2] + 1))
NEW_VERSION="${version_parts[0]}.${version_parts[1]}.${PATCH}"
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
NEW_VERSION="${NEW_VERSION}-alpha"
fi
else
NEW_VERSION="$CURRENT_VERSION"
fi
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Update package.json
if: github.event_name == 'workflow_dispatch'
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
# Use node to update package.json to preserve formatting
node -e "
const fs = require('fs');
const package = JSON.parse(fs.readFileSync('package.json'));
package.version = '$NEW_VERSION';
fs.writeFileSync('package.json', JSON.stringify(package, null, 2) + '\n');
"
- name: Commit version update
if: github.event_name == 'workflow_dispatch'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add package.json
git commit -m "chore: update package.json version to ${{ steps.new_version.outputs.version }}"
git push
- name: Get Package Version
id: package_version
run: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aithranetwork/plugin-aithra-toolkit",
"version": "0.0.5",
"version": "0.0.5-alpha",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down

0 comments on commit 4467cab

Please sign in to comment.