-
-
Notifications
You must be signed in to change notification settings - Fork 519
147 lines (126 loc) · 5.17 KB
/
changelog.yaml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Changelog
on:
push:
branches:
- develop
tags:
- 'v*'
jobs:
generate:
if: >
! contains(github.event.head_commit.message, '[ci skip]') &&
! (
startsWith(github.event.head_commit.message, 'Increment version to v') &&
startsWith(github.ref, 'refs/heads/')
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.JRNL_BOT_TOKEN }}
- name: Check branch for new commits, and env vars
run: |
echo "::group::git fetch origin --tags --force"
git fetch origin --tags --force
echo "::endgroup::"
TAG_REGEX='include-all'
echo "::debug::GITHUB_REF: $GITHUB_REF"
BRANCH="${GITHUB_REF##*/}"
if [[ $GITHUB_REF =~ ^refs/tags/ ]]; then
# This is a tag build (i.e. a release)
echo '::debug::Release build'
if [[ ! $BRANCH =~ ^v[0-9]+(\.[0-9]+){1,2}(-(alpha|beta)([0-9]+)?)?$ ]]; then
echo "::error::Invalid tag format: ${BRANCH}"
exit 1
fi
RELEASE=1
BRANCH=develop
git checkout $BRANCH
# if actual release (not pre), then changelog should exclude prereleases on update
prerelease_regex='(alpha|beta)'
if [[ ! ${GITHUB_REF##*/} =~ $prerelease_regex ]]; then
echo '::debug::Actual release (not a prerelease)'
TAG_REGEX="$prerelease_regex"
echo "FULL_RELEASE=true" >> $GITHUB_ENV
fi
fi
echo "::debug::TAG_REGEX: $TAG_REGEX"
if [[ "$(git rev-parse "origin/$BRANCH")" != $GITHUB_SHA ]]; then
# Normal build on a branch (no tag)
echo "::debug::BRANCH: $BRANCH"
echo "::debug::GITHUB_SHA: $GITHUB_SHA"
echo "::error::$BRANCH has been updated since build started. Aborting changelog."
exit 1
fi
SINCE_TAG=$(git tag --sort=-creatordate | grep -Ev "$TAG_REGEX" | awk "NR==$(( 1 + ${RELEASE:-0} ))")
echo "::debug::BRANCH: $BRANCH"
echo "::debug::TAG_REGEX: $TAG_REGEX"
echo "::debug::FILENAME: CHANGELOG.md"
echo "::debug::SINCE_TAG: $SINCE_TAG"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
echo "TAG_REGEX=$TAG_REGEX" >> $GITHUB_ENV
echo "FILENAME=CHANGELOG.md" >> $GITHUB_ENV
echo "SINCE_TAG=$SINCE_TAG" >> $GITHUB_ENV
- name: Prep changelog file (clear out old lines)
run: |
# delete the top of the changelog up to the correct tag
tagline=$(grep -n "^## \[\?${SINCE_TAG}\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
echo "tagline: ${tagline}"
if [[ -z $tagline ]]; then
echo "::error::Something is wrong. ${SINCE_TAG} isn't in the changelog."
exit 1
fi
sed -i "1,$(expr $tagline - 1)d" "$FILENAME"
# delete generated line (or it will be added multiple times)
sed -i '/This Changelog was automatically generated by/d' "$FILENAME"
# delete trailing empty lines
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$FILENAME"
- name: Generate changelog
uses: heinrichreimer/action-github-changelog-generator@v2.1.1
with:
# see: https://github.com/heinrichreimer/action-github-changelog-generator
repo: jrnl-org/jrnl
token: ${{ secrets.JRNL_BOT_TOKEN }}
base: CHANGELOG.md
addSections: '{"build":{"prefix":"**Build:**","labels":["build"]},"docs":{"prefix":"**Documentation:**","labels":["documentation"]}}'
issues: true
pullRequests: true
issuesWoLabels: false
unreleased: true
compareLink: true
includeLabels: bug,enhancement,documentation,build,deprecated
excludeLabels: stale,wontfix
excludeTagsRegex: ${{ env.TAG_REGEX }}
sinceTag: ${{ env.SINCE_TAG }}
maxIssues: 150
releaseUrl: https://pypi.org/project/jrnl/%s/
releaseBranch: develop
verbose: false
- name: Small fixes
run: |
# Change unreleased link to correct url
sed -i 's!https://pypi.org/project/jrnl/HEAD/!https://github.com/jrnl-org/jrnl/!' "$FILENAME"
- name: Diff and consistency check
run: |
git diff
if [[ $(grep -c '^# Changelog$' "$FILENAME") != 1 ]]; then
echo '::error::Something is wrong with the changelog.'
fi
SOMETHING_CHANGED=false
git diff --exit-code || SOMETHING_CHANGED=true
echo "::debug::SOMETHING_CHANGED: $SOMETHING_CHANGED"
echo "SOMETHING_CHANGED=$SOMETHING_CHANGED" >> $GITHUB_ENV
- name: Commit
if: env.SOMETHING_CHANGED
run: |
git config user.email "jrnl.bot@gmail.com"
git config user.name "Jrnl Bot"
git add "$FILENAME"
git commit -m "Update changelog [ci skip]"
git push origin $BRANCH
- name: Merge to Release branch
if: env.FULL_RELEASE
run: |
git checkout release
git merge --ff-only $BRANCH
git push origin release