|
| 1 | +name: Display the version hint |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [synchronize, opened, reopened, ready_for_review] |
| 5 | + branches: [master] |
| 6 | + |
| 7 | +jobs: |
| 8 | + preview-version-hint: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + name: Checkout the repository |
| 13 | + with: |
| 14 | + fetch-depth: 0 |
| 15 | + ref: ${{ github.event.pull_request.head.sha }} |
| 16 | + token: ${{ secrets.PAT }} |
| 17 | + |
| 18 | + - name: Setup Python and Git |
| 19 | + uses: ./.github/actions/setup-python-and-git |
| 20 | + with: |
| 21 | + python-version: '3.11' |
| 22 | + |
| 23 | + - name: Install requirements |
| 24 | + run: | |
| 25 | + python -m pip install generate-changelog bump-my-version |
| 26 | +
|
| 27 | + - name: Get the release hint |
| 28 | + id: generate-changelog |
| 29 | + run: | |
| 30 | + RELEASE_KIND=$(generate-changelog --output release-hint --branch-override ${{ github.base_ref }} --skip-output-pipeline) |
| 31 | + echo "::notice::Suggested release type upon merge to ${{ github.base_ref }}: ${RELEASE_KIND}" |
| 32 | + echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV |
| 33 | + echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT |
| 34 | +
|
| 35 | + - name: Get Pull Request Number |
| 36 | + id: pr |
| 37 | + run: | |
| 38 | + PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}") |
| 39 | + echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT |
| 40 | + echo "::notice::PR_NUMBER is ${PR_NUMBER}" |
| 41 | + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 44 | + |
| 45 | + - name: Bump version dry run |
| 46 | + if: ${{ env.RELEASE_KIND != 'no-release' }} |
| 47 | + shell: bash |
| 48 | + run: | |
| 49 | + # This will display a full log of what would happen if we were to bump the version. |
| 50 | + bump-my-version bump --dry-run --verbose "$RELEASE_KIND" |
| 51 | +
|
| 52 | + # This retrieves the current and new version numbers as a JSON-formatted string. |
| 53 | + VERSION_INFO=$(bump-my-version show --format json --increment "$RELEASE_KIND" current_version new_version) |
| 54 | + echo "CURRENT_VERSION=$(echo $VERSION_INFO | jq -r .current_version)" >> $GITHUB_ENV |
| 55 | + echo "NEW_VERSION=$(echo $VERSION_INFO | jq -r .new_version)" >> $GITHUB_ENV |
| 56 | +
|
| 57 | + - name: Set no-release information |
| 58 | + if: ${{ env.RELEASE_KIND == 'no-release' }} |
| 59 | + run: | |
| 60 | + echo "CURRENT_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV |
| 61 | + echo "NEW_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Display the version hint |
| 64 | + uses: s-gehring/singleton-comment@v1 |
| 65 | + with: |
| 66 | + comment-body: | |
| 67 | + **Version hint:** ${{ env.RELEASE_KIND }} |
| 68 | + **Current version:** ${{ env.CURRENT_VERSION }} |
| 69 | + **New version (when merged):** ${{ env.NEW_VERSION }} |
0 commit comments