name: Update_CalVer on: push: branches: - 'main' paths: - 'subgen.py' - 'launcher.py' workflow_dispatch: jobs: docker: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 with: # Fetch only the latest commit initially fetch-depth: 1 ref: main - name: Fetch commits for this month run: | # Fetch commits starting from the first day of the current month YEAR=$(date +%Y) MONTH=$(date +%m) git fetch --shallow-since="$YEAR-$MONTH-01" - name: Calculate version id: version run: | # Calculate the commit count for this month YEAR=$(date +%Y) MONTH=$(date +%m) COMMIT_COUNT=$(git rev-list --count HEAD --since="$YEAR-$MONTH-01") echo "COMMIT_COUNT=$COMMIT_COUNT" echo "VERSION=${YEAR}.${MONTH}.${COMMIT_COUNT}" >> $GITHUB_ENV - name: Update version file run: | # Update subgen.py with the calculated version sed -i "s/subgen_version =.*/subgen_version = '${{ env.VERSION }}'/" subgen.py - name: Amend commit with version update env: GIT_AUTHOR_NAME: "McCloudS" GIT_AUTHOR_EMAIL: "scott@mccloud.dev" run: | git config user.name "${GIT_AUTHOR_NAME}" git config user.email "${GIT_AUTHOR_EMAIL}" # Stage the modified file git add subgen.py # Amend the most recent commit, reusing the previous commit message git commit --amend --reuse-message=HEAD --author="${GIT_AUTHOR_NAME} <${GIT_AUTHOR_EMAIL}>" # Push the amended commit git push --force