Skip to content

Commit

Permalink
Update create_version.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
DARKDRAGON-LK authored Apr 9, 2024
1 parent b1dd852 commit 5075603
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions .github/workflows/create_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,50 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Determine current date
id: current_date
run: echo "::set-output name=date::$(date +'%Y%m%d')"
- name: Determine current commit number
id: current_commit
run: echo "::set-output name=commit_number::$(git rev-parse HEAD)"

- name: Read merge counter from file
id: read_counter
run: echo "::set-output name=counter::$(cat counter.txt || echo '0')"
- name: Read previous commit number from file
id: read_prev_commit
run: echo "::set-output name=prev_commit::$(cat commit_number.txt || echo '')"

- name: Determine if this is a merge commit
id: is_merge_commit
- name: Compare commit numbers
id: compare_commit
run: |
if git show --format=%P -s | grep -q " "; then
echo "::set-output name=is_merge::true"
if [ "${{ steps.current_commit.outputs.commit_number }}" != "${{ steps.read_prev_commit.outputs.prev_commit }}" ]; then
echo "commit_numbers_different=true" >> $GITHUB_ENV
else
echo "::set-output name=is_merge::false"
echo "commit_numbers_different=false" >> $GITHUB_ENV
fi
- name: Increment merge counter
if: steps.is_merge_commit.outputs.is_merge == 'true'
id: increment_counter
run: |
counter=$((${{ steps.read_counter.outputs.counter }} + 1))
echo "::set-output name=counter::$counter"
- name: Increment version if commit numbers differ
id: increment_version
if: env.commit_numbers_different == 'true'
run: echo "increment_version=true" >> $GITHUB_ENV

- name: Determine current date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: Read merge counter from file
run: echo "counter=$(cat counter.txt || echo '0')" >> $GITHUB_ENV

- name: Increment merge counter if needed
if: steps.increment_version.outputs.increment_version == 'true'
run: echo "counter=$((counter + 1))" >> $GITHUB_ENV

- name: Update version file with date and merge counter
run: echo "3.0.0.${{ steps.current_date.outputs.date }}.${{ steps.increment_counter.outputs.counter }}" > VERSION.txt
run: echo "3.0.0.${{ env.date }}.${{ env.counter }}" > VERSION.txt

- name: Update README.md
run: |
sed -i "s/Current Version:.*/Current Version: 3.0.0.${{ steps.current_date.outputs.date }}.${{ steps.increment_counter.outputs.counter }} (This line will be automatically updated to reflect the latest version)/" README.md
sed -i "s/Current Version:.*/Current Version: 3.0.0.${{ env.date }}.${{ env.counter }} (This line will be automatically updated to reflect the latest version)/" README.md
- name: Set up Git identity
run: |
Expand All @@ -57,5 +65,5 @@ jobs:
- name: Commit version and README update
run: |
git add VERSION.txt README.md
git commit -m "Update version to 3.0.0.${{ steps.current_date.outputs.date }}.${{ steps.increment_counter.outputs.counter }}"
git commit -m "Update version to 3.0.0.${{ env.date }}.${{ env.counter }}"
git push

0 comments on commit 5075603

Please sign in to comment.