diff --git a/.github/workflows/create_version.yml b/.github/workflows/create_version.yml index 3076cd3dbe..d9fd868b21 100644 --- a/.github/workflows/create_version.yml +++ b/.github/workflows/create_version.yml @@ -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: | @@ -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