Increment Package Versions #2
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: Increment Package Versions | |
on: | |
workflow_dispatch: # Manual trigger | |
jobs: | |
increment-version: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Allow write access to repository contents | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Increment Version | |
run: | | |
PACKAGE_FILES=("path/to/file1/package.json" "path/to/file2/package.json" "path/to/file3/package.json" "path/to/file4/package.json") | |
for file in "${PACKAGE_FILES[@]}"; do | |
echo "Updating version in $file" | |
CURRENT_VERSION=$(jq -r '.version' "$file") | |
NEW_VERSION=$(node -p "v='$CURRENT_VERSION'.split('.'); v[2]++; v.join('.')") | |
echo "Incrementing version: $CURRENT_VERSION -> $NEW_VERSION" | |
jq ".version=\"$NEW_VERSION\"" "$file" > tmp.json && mv tmp.json "$file" | |
done | |
- name: Commit and Push Changes | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add . | |
git commit -m "Incremented package.json versions" | |
git push |