|
| 1 | +# NB: release notes inspired by https://blogs.sap.com/2018/06/22/generating-release-notes-from-git-commit-messages-using-basic-shell-commands-gitgrep/ |
| 2 | +name: Tag Creator |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, closed] |
| 6 | +env: |
| 7 | + IS_MAJOR: >- |
| 8 | + ${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/major' ) }} |
| 9 | + IS_MINOR: >- |
| 10 | + ${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/minor' ) }} |
| 11 | + IS_PATCH: >- |
| 12 | + ${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/patch' ) }} |
| 13 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 14 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 15 | + GITHUB_HEAD_REF: ${{ github.head_ref }} |
| 16 | +jobs: |
| 17 | + bumpversion: |
| 18 | + if: >- |
| 19 | + ( |
| 20 | + contains( github.event.pull_request.labels.*.name, 'bumpversion/major' ) || |
| 21 | + contains( github.event.pull_request.labels.*.name, 'bumpversion/minor' ) || |
| 22 | + contains( github.event.pull_request.labels.*.name, 'bumpversion/patch' ) |
| 23 | + ) && ( |
| 24 | + github.event.sender.login == 'lukasheinrich' || |
| 25 | + github.event.sender.login == 'matthewfeickert' || |
| 26 | + github.event.sender.login == 'kratsg' |
| 27 | + ) |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Dump GitHub context |
| 31 | + env: |
| 32 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 33 | + run: echo "$GITHUB_CONTEXT" |
| 34 | + - name: Determine version part |
| 35 | + run: | |
| 36 | + if [ $IS_MAJOR == 'true' ] |
| 37 | + then |
| 38 | + echo "::set-env name=BV_PART::major" |
| 39 | + elif [ $IS_MINOR == 'true' ] |
| 40 | + then |
| 41 | + echo "::set-env name=BV_PART::minor" |
| 42 | + else |
| 43 | + echo "::set-env name=BV_PART::patch" |
| 44 | + fi |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@v1.2.0 |
| 47 | + - name: Set up git user |
| 48 | + run: | |
| 49 | + git config --local user.email "action@github.com" |
| 50 | + git config --local user.name "GitHub Action" |
| 51 | + - name: Checkout master |
| 52 | + run: git checkout master |
| 53 | + - name: Squash and merge PR#${{ github.event.pull_request.number }} to master |
| 54 | + if: github.event.action == 'labeled' |
| 55 | + run: | |
| 56 | + git merge --squash "origin/${GITHUB_HEAD_REF}" |
| 57 | + git commit -m "${PR_TITLE} (#${PR_NUMBER})" |
| 58 | + - name: Set up Python 3.7 |
| 59 | + uses: actions/setup-python@v1 |
| 60 | + with: |
| 61 | + python-version: 3.7 |
| 62 | + - name: Install bumpversion |
| 63 | + run: | |
| 64 | + python -m pip install --upgrade pip setuptools wheel |
| 65 | + python -m pip install bumpversion |
| 66 | + - name: Run bumpversion ${{ env['BV_PART'] }} |
| 67 | + run: | |
| 68 | + OLD_TAG=$(git describe --tags --abbrev=0) |
| 69 | + echo "::set-env name=OLD_TAG::${OLD_TAG}" |
| 70 | + bumpversion $BV_PART --message "Bump version: {current_version} → {new_version} |
| 71 | +
|
| 72 | + Triggered by #${PR_NUMBER} via GitHub Actions." |
| 73 | + NEW_TAG=$(git describe --tags --abbrev=0) |
| 74 | + echo "::set-env name=NEW_TAG::${NEW_TAG}" |
| 75 | + git tag -n99 -l $NEW_TAG |
| 76 | +
|
| 77 | + CHANGES=$(git log --pretty=format:'%s' $OLD_TAG..HEAD -i -E --grep='^([a-z]*?):') |
| 78 | + CHANGES_NEWLINE="$(echo "${CHANGES}" | sed -e 's/^/ - /')" |
| 79 | + SANITIZED_CHANGES=$(echo "${CHANGES}" | sed -e 's/^/<li>/' -e 's|$|</li>|' -e 's/(#[0-9]\+)//' ) |
| 80 | + echo "::set-env name=CHANGES::${SANITIZED_CHANGES//$'\n'/}" |
| 81 | + NUM_CHANGES=$(echo -n "$CHANGES" | grep -c '^') |
| 82 | + echo "::set-env name=NUM_CHANGES::${NUM_CHANGES}" |
| 83 | + git tag $NEW_TAG $NEW_TAG^{} -f -m "$(printf "This is a $BV_PART release from $OLD_TAG → $NEW_TAG.\n\nChanges:\n$CHANGES_NEWLINE")" |
| 84 | + git tag -n99 -l $NEW_TAG |
| 85 | + - name: Comment on issue |
| 86 | + if: >- |
| 87 | + github.event.action == 'labeled' |
| 88 | + uses: actions/github-script@0.3.0 |
| 89 | + with: |
| 90 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + script: | |
| 92 | + github.issues.createComment({...context.issue, body: "I've queued this up. When it gets merged, I'll create a ${{ env['BV_PART'] }} release from ${{ env['OLD_TAG'] }} → ${{ env['NEW_TAG'] }} which includes the following ${{ env['NUM_CHANGES'] }} change(s) [including this PR]:<br />${{ env['CHANGES'] }}<br />If you make any more changes, you probably want to re-trigger me again by removing the `bumpversion/${{ env['BV_PART'] }}` label and then adding it back again."}) |
| 93 | + - name: Push changes |
| 94 | + if: >- |
| 95 | + github.event.action == 'closed' && github.event.pull_request.merged |
| 96 | + uses: ad-m/github-push-action@v0.5.0 |
| 97 | + with: |
| 98 | + github_token: ${{ secrets.GITHUB_PAT }} |
| 99 | + - name: Comment that something failed |
| 100 | + if: failure() |
| 101 | + uses: actions/github-script@0.3.0 |
| 102 | + with: |
| 103 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + script: | |
| 105 | + github.issues.createComment({...context.issue, body: ":cry: Something went wrong. I am not able to push. Check the [Actions pipeline](https://github.com/${{ github.repository }}/actions?query=workflow%3A%22Tag+Creator%22) to see what happened. If you make any more changes, you probably want to re-trigger me again by adding the `bumpversion/${{ env['BV_PART'] }}` label again."}) |
| 106 | + github.issues.removeLabels({...context.issue, "bumpversion/${{ env['BV_PART'] }}" }) |
| 107 | +
|
| 108 | + always_job: |
| 109 | + name: Always run job |
| 110 | + runs-on: ubuntu-latest |
| 111 | + steps: |
| 112 | + - name: Always run |
| 113 | + run: echo "This job is used to prevent the workflow status from showing as failed when all other jobs are skipped. See https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/m-p/38085 for more information." |
0 commit comments