Created
February 27, 2024 11:07
-
-
Save deepak-terse/044b77bff983ea8ba485718cc1030169 to your computer and use it in GitHub Desktop.
Auto increments package version on every branch merge to main branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Increment Version | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
increment_version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
run: npm ci | |
- name: Check commit message | |
id: commit | |
run: | | |
echo "::set-output name=message::${{ github.event.head_commit.message }}" | |
git config --local user.email "${{ github.event.head_commit.author.email }}" | |
git config --local user.name "${{ github.event.head_commit.author.name }}" | |
- name: Determine version increment | |
id: version_increment | |
run: | | |
commit_message="${{ steps.commit.outputs.message }}" | |
if [[ $commit_message == *"minor"* ]]; then | |
echo "::set-output name=increment::minor" | |
elif [[ $commit_message == *"major"* ]]; then | |
echo "::set-output name=increment::major" | |
elif [[ $commit_message == *"hotfix"* ]]; then | |
echo "::set-output name=increment::patch" | |
else | |
echo "::set-output name=increment::none" | |
fi | |
- name: Increment package.json version | |
run: | | |
increment="${{ steps.version_increment.outputs.increment }}" | |
if [[ $increment != "none" ]]; then | |
echo "Incrementing package.json version..." | |
npm version $increment | |
echo "Incremented package.json version using $increment" | |
else | |
echo "No version increment detected. Skipping..." | |
fi | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add package.json | |
git commit -m "${{ steps.commit.outputs.message }}" | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment