diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 0000000..874226f --- /dev/null +++ b/.github/workflows/update-version.yml @@ -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