Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Update Package Version

on:
push:
branches:
- main
- master

permissions:
contents: write

jobs:
update-version:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Sync version to problem count
run: |
COUNT=$(find Problems -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')
NEW_VERSION="CP-${COUNT}"
CURRENT_VERSION=$(jq -r '.version' package.json)

echo "Current version: ${CURRENT_VERSION}"
echo "New version: ${NEW_VERSION}"

if [ "$CURRENT_VERSION" = "$NEW_VERSION" ]; then
echo "Version already up to date."
exit 0
fi

jq --arg v "$NEW_VERSION" '.version=$v' package.json > package.json.tmp
mv package.json.tmp package.json

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: sync version to problem count [skip ci]"
git push