-
Notifications
You must be signed in to change notification settings - Fork 14
92 lines (79 loc) · 3.38 KB
/
release.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
name: Release Drafter and Publisher
on:
pull_request:
types:
- closed
concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
new_release:
if: github.ref == 'refs/heads/master' && github.event.pull_request.merged == true
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get branch name
id: getbranch
run: echo ::set-output name=BRANCH::${GITHUB_HEAD_REF}
# ${{ github.ref }} was not giving v* as tag name, but refs/tags/v* instead, so It had to be abbreviated
- name: Get latest abbreviated tag
id: gettag
run: echo ::set-output name=TAG::$(git describe --tags $(git rev-list --tags --max-count=1)) # get the latest tag across all branches and put it in the output TAG
- name: Calculate next version
id: nextversion
run: |
BRANCH_NAME="${{ steps.getbranch.outputs.BRANCH }}"
CURRENT_VERSION="${{ steps.gettag.outputs.TAG }}"
CURRENT_VERSION="${CURRENT_VERSION#v}" # Remove the 'v' from the start of the version
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
if [[ $BRANCH_NAME =~ ^major/ ]]; then
VERSION_PARTS[0]=$((VERSION_PARTS[0] + 1))
VERSION_PARTS[1]=0
VERSION_PARTS[2]=0
elif [[ $BRANCH_NAME =~ ^minor/ ]]; then
VERSION_PARTS[1]=$((VERSION_PARTS[1] + 1))
VERSION_PARTS[2]=0
else
VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1))
fi
NEXT_VERSION="v${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
echo ::set-output name=NEXT_VERSION::"$NEXT_VERSION"
- name: Update CHANGELOG.md
run: |
EXISTING_CHANGELOG=$(cat CHANGELOG.md)
echo " " > CHANGELOG.md
echo "## ${{ steps.nextversion.outputs.NEXT_VERSION }}" >> CHANGELOG.md
echo "- ${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }}) @${{ github.event.pull_request.user.login }}" >> CHANGELOG.md
echo " " >> CHANGELOG.md
echo -e "$EXISTING_CHANGELOG" >> CHANGELOG.md
- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md for PR #${{ github.event.pull_request.number }}"
- name: Push changes
run: git push origin HEAD:master
- name: Create and publish new tag
run: |
git tag ${{ steps.nextversion.outputs.NEXT_VERSION }}
git push origin ${{ steps.nextversion.outputs.NEXT_VERSION }}
- uses: release-drafter/release-drafter@v5
with:
commitish: master
name: "stellar-etl ${{ steps.nextversion.outputs.NEXT_VERSION }}"
tag: ${{ steps.nextversion.outputs.NEXT_VERSION }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}