Skip to content

bump pkg json

bump pkg json #7

Workflow file for this run

name: Conditional Release
on:
push:
branches:
- main
jobs:
release:
name: Release and Publish Package
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Install Dependencies
run: npm install
- name: Check for File Changes
id: file_changes
run: |
git fetch --depth=2
# Check if HEAD~1 is available, else use HEAD
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
else
CHANGED_FILES=$(git diff --name-only HEAD)
fi
echo "Changed files: $CHANGED_FILES"
# Check if relevant files have changed
if ! echo "$CHANGED_FILES" | grep -qE "^(index.ts|api.ts)$"; then
echo "No relevant file changes detected. Skipping version bump and release."
exit 0
fi
- name: Bump Version and Create Release
env:
HUSKY_SKIP_HOOKS: 1
id: bump-version
run: |
cd api
git config --local user.name "GitHub Action"
git config --local user.email "[email protected]"
# Get current version
current_version=$(npm pkg get version)
# Bump the version
npm version patch -m "Release version %s"
# Get new version
new_version=$(npm pkg get version)
echo "New version: $new_version"
# Commit and push the changes
git add package.json
git commit -m "Bump version to $new_version"
git tag -a "v$new_version" -m "Release version $new_version"
git push origin main --follow-tags
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.bump-version.outputs.new_version }}
release_name: Release ${{ steps.bump-version.outputs.new_version }}
draft: false
prerelease: false
body: |
Release of version ${{ steps.bump-version.outputs.new_version }}