-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
90 lines (90 loc) · 3.8 KB
/
action.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
name: Create release notes from changelog
description: Extracts release notes from CHANGELOG.md, combines them with a static header RELEASE_HEAD.md and writes them to RELEASE.md.
branding:
icon: file-text
color: purple
inputs:
version:
description: 'Version number to search for in CHANGELOG.md (default: use tag without leading v)'
required: false
default: <tag version>
begin-pattern:
description: Sed pattern to find heading with correct version in CHANGELOG.md
required: false
default: '/^## \\[${RELEASE_VERSION}\\]/'
end-pattern:
description: Sed pattern to find next heading in CHANGELOG.md that does not belong to this version anymore
required: false
default: '/^## /'
link-pattern:
description: Grep pattern to find footnote-style compare link for this version (optional)
required: false
default: '^\\[${RELEASE_VERSION}\\]:'
chop:
description: 'Number of lines to chop from end of matching part of CHANGELOG.md'
required: false
default: '2'
working-directory:
description: 'Path to folder where CHANGELOG.md and RELEASE_HEAD.md can be found and where RELEASE.md should be placed'
required: false
default: '.'
runs:
using: "composite"
steps:
- name: Set RELEASE_VERSION
shell: bash
run: >
if [ "${{ inputs.version }}" = "<tag version>" ]; then
RELEASE_VERSION_TEMP=${GITHUB_REF#refs/*/};
echo "RELEASE_VERSION=${RELEASE_VERSION_TEMP#v}" >> $GITHUB_ENV;
else
echo "RELEASE_VERSION=${{ inputs.version }}" >> $GITHUB_ENV;
fi
- name: Print RELEASE_VERSION variable to be used in sed/grep patterns
shell: bash
run: echo "\$RELEASE_VERSION = $RELEASE_VERSION"
- name: Extract first paragraph from README.md if RELEASE_HEAD.md does not exist
shell: bash
working-directory: ${{ inputs.working-directory }}
# explanation of sed command
# 1. "/^# / p" prints line(s) with first-level heading
# 2. "2,/^$/ p" prints lines from second line to next empty line
run: |
if [ ! -f RELEASE_HEAD.md ]; then
if grep -q "^# " README.md; then
sed -ne "/^# / p; 2,/^$/ p" README.md > RELEASE_HEAD.md
else
sed -ne "1,/^$/ p" README.md > RELEASE_HEAD.md
fi
echo -e "Changes in this version:\n" >> RELEASE_HEAD.md
fi
- name: Start RELEASE.md with copy of RELEASE_HEAD.md
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
cp RELEASE_HEAD.md RELEASE.md
printf "\n" >> RELEASE.md
echo "Created release notes at `realpath RELEASE.md`"
- name: Extract changelog for release version
shell: bash
working-directory: ${{ inputs.working-directory }}
# explanation of sed command:
# 1. select lines between begin-pattern and end-pattern
# 2. invert this selection
# 3. delete it
# => only selection is remaining in stream
run: |
echo "Pattern used for sed: ${{ inputs.begin-pattern }},${{ inputs.end-pattern }} ! d"
sed -e "${{ inputs.begin-pattern }},${{ inputs.end-pattern }} ! d" CHANGELOG.md | head -n -${{ inputs.chop }} >> RELEASE.md
printf "\n" >> RELEASE.md
- name: Extract compare link for release version if it exists
shell: bash
working-directory: ${{ inputs.working-directory }}
# only run grep if the link-pattern can actually be found
run: |
if grep -q "${{ inputs.link-pattern }}" CHANGELOG.md; then
grep "${{ inputs.link-pattern }}" CHANGELOG.md >> RELEASE.md
else
echo "Warning: The Link-pattern '${{ inputs.link-pattern }}' could not be found in `realpath CHANGELOG.md`."
echo "Perhaps you forgot to add a line of the form '[$RELEASE_VERSION]: url' to the end of your changelog."
fi