Update calver.yml
This commit is contained in:
21
.github/workflows/calver.yml
vendored
21
.github/workflows/calver.yml
vendored
@@ -4,9 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- 'main'
|
||||||
paths:
|
|
||||||
- 'subgen.py'
|
|
||||||
- 'launcher.py'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -16,24 +13,21 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
# Fetch the full history, it's important here
|
# Fetch the full history
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Calculate version
|
- name: Calculate version
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
# Calculate the commit count for this month
|
|
||||||
YEAR=$(date +%Y)
|
YEAR=$(date +%Y)
|
||||||
MONTH=$(date +%m)
|
MONTH=$(date +%m)
|
||||||
# count commits since start of the month, limiting scope
|
|
||||||
COMMIT_COUNT=$(git rev-list --count HEAD --since="$YEAR-$MONTH-01")
|
COMMIT_COUNT=$(git rev-list --count HEAD --since="$YEAR-$MONTH-01")
|
||||||
echo "COMMIT_COUNT=$COMMIT_COUNT"
|
echo "COMMIT_COUNT=$COMMIT_COUNT"
|
||||||
echo "VERSION=${YEAR}.${MONTH}.${COMMIT_COUNT}" >> $GITHUB_ENV
|
echo "VERSION=${YEAR}.${MONTH}.${COMMIT_COUNT}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Update version file
|
- name: Update version file
|
||||||
run: |
|
run: |
|
||||||
# Update subgen.py with the calculated version
|
|
||||||
sed -i "s/subgen_version =.*/subgen_version = '${{ env.VERSION }}'/" subgen.py
|
sed -i "s/subgen_version =.*/subgen_version = '${{ env.VERSION }}'/" subgen.py
|
||||||
|
|
||||||
- name: Amend commit with version update
|
- name: Amend commit with version update
|
||||||
@@ -44,16 +38,11 @@ jobs:
|
|||||||
git config user.name "${GIT_AUTHOR_NAME}"
|
git config user.name "${GIT_AUTHOR_NAME}"
|
||||||
git config user.email "${GIT_AUTHOR_EMAIL}"
|
git config user.email "${GIT_AUTHOR_EMAIL}"
|
||||||
|
|
||||||
# Stage the modified file
|
|
||||||
git add subgen.py
|
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}>"
|
git commit --amend --reuse-message=HEAD --author="${GIT_AUTHOR_NAME} <${GIT_AUTHOR_EMAIL}>"
|
||||||
|
|
||||||
# Attempt a regular push first. If it fails because of remote changes, use --force-with-lease cautiously.
|
# Pull any remote changes
|
||||||
git push origin HEAD:main
|
git pull --rebase origin main # Use --rebase to avoid a merge commit
|
||||||
|
|
||||||
# Alternative: Use --force-with-lease if a regular push fails
|
# Push the amended commit
|
||||||
# This is much safer than --force, but still requires care
|
git push origin HEAD:main
|
||||||
# If this fails as well (e.g., very recent conflict), you'll need manual intervention.
|
|
||||||
# git push --force-with-lease origin HEAD:main
|
|
||||||
|
|||||||
Reference in New Issue
Block a user