-
Notifications
You must be signed in to change notification settings - Fork 85
131 lines (128 loc) · 5.85 KB
/
tag.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# NB: release notes inspired by https://blogs.sap.com/2018/06/22/generating-release-notes-from-git-commit-messages-using-basic-shell-commands-gitgrep/
name: Tag Creator
on:
pull_request:
types: [labeled, closed]
env:
IS_MAJOR: >-
${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/major' ) }}
IS_MINOR: >-
${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/minor' ) }}
IS_PATCH: >-
${{ contains( github.event.pull_request.labels.*.name, 'bumpversion/patch' ) }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
jobs:
bumpversion:
if: >-
(
contains( github.event.pull_request.labels.*.name, 'bumpversion/major' ) ||
contains( github.event.pull_request.labels.*.name, 'bumpversion/minor' ) ||
contains( github.event.pull_request.labels.*.name, 'bumpversion/patch' )
) && (
github.event.sender.login == 'lukasheinrich' ||
github.event.sender.login == 'matthewfeickert' ||
github.event.sender.login == 'kratsg'
)
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Determine version part
run: |
if [ $IS_MAJOR == 'true' ]
then
echo "::set-env name=BV_PART::major"
elif [ $IS_MINOR == 'true' ]
then
echo "::set-env name=BV_PART::minor"
else
echo "::set-env name=BV_PART::patch"
fi
- name: Checkout repository
uses: actions/[email protected]
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0
- name: Set up git user
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Checkout master
run: git checkout master
- name: Squash and merge PR#${{ github.event.pull_request.number }} to master
if: github.event.action == 'labeled'
run: |
git merge --squash "origin/${GITHUB_HEAD_REF}"
git commit -m "${PR_TITLE} (#${PR_NUMBER})"
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install bump2version
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install "bump2version~=1.0"
- name: Run bump2version ${{ env['BV_PART'] }}
run: |
OLD_TAG=$(git describe --tags --abbrev=0)
echo "::set-env name=OLD_TAG::${OLD_TAG}"
bump2version $BV_PART --message "Bump version: {current_version} → {new_version}
Triggered by #${PR_NUMBER} via GitHub Actions."
NEW_TAG=$(git describe --tags --abbrev=0)
echo "::set-env name=NEW_TAG::${NEW_TAG}"
git tag -n99 -l $NEW_TAG
CHANGES=$(git log --pretty=format:'%s' $OLD_TAG..HEAD -i -E --grep='^([a-z]*?):')
CHANGES_NEWLINE="$(echo "${CHANGES}" | sed -e 's/^/ - /')"
SANITIZED_CHANGES=$(echo "${CHANGES}" | sed -e 's/^/<li>/' -e 's|$|</li>|' -e 's/(#[0-9]\+)//' -e 's/"/'"'"'/g')
echo "::set-env name=CHANGES::${SANITIZED_CHANGES//$'\n'/}"
NUM_CHANGES=$(echo -n "$CHANGES" | grep -c '^')
echo "::set-env name=NUM_CHANGES::${NUM_CHANGES}"
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")"
git tag -n99 -l $NEW_TAG
- name: Comment on issue
if: >-
github.event.action == 'labeled'
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
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."
})
- name: Push changes
if: >-
github.event.action == 'closed' && github.event.pull_request.merged
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_PAT }}
- name: Comment that something failed
if: failure()
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
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."
})
github.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: "bumpversion/${{ env['BV_PART'] }}"
})
always_job:
name: Always run job
runs-on: ubuntu-latest
steps:
- name: Always run
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."