Skip to content

Commit c8257a3

Browse files
pbrezinaalexey-tikhonov
authored andcommitted
ci: automatically generate release notes
The release workflow is extended to automatically generate release notes and open a draft pull request against sssd.io. Reviewed-by: Alejandro López <allopez@redhat.com> Reviewed-by: Justin Stephenson <jstephen@redhat.com>
1 parent 033a81b commit c8257a3

4 files changed

Lines changed: 136 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ on:
33
workflow_dispatch:
44
inputs:
55
branch:
6-
description: 'Target branch for release'
6+
description: 'Target branch to release from'
77
required: true
88
default: 'master'
99
type: string
1010
version:
1111
description: 'Release version'
1212
required: true
1313
type: string
14+
15+
previous_version:
16+
description: 'Previous version, starting point for release notes generator'
17+
required: true
18+
type: string
1419
jobs:
1520
release:
1621
runs-on: ubuntu-latest
@@ -40,10 +45,21 @@ jobs:
4045
with:
4146
working-directory: sssd
4247

48+
- name: Install release notes dependencies
49+
shell: bash
50+
run: dnf install -y pandoc python3-pypandoc
51+
4352
- name: Execute release script
4453
working-directory: sssd
4554
shell: bash
4655
env:
4756
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
4857
run: |
49-
./scripts/release.sh "${{ inputs.branch }}" "${{ inputs.version }}"
58+
./scripts/release.sh "${{ inputs.branch }}" "${{ inputs.version }}" "${{ inputs.previous_version }}"
59+
60+
- name: Execute release notes script
61+
working-directory: sssd
62+
shell: bash
63+
run: |
64+
# Release notes file is generated from the release script
65+
./scripts/generate-full-release-notes.sh "${{ inputs.version }}" "/tmp/sssd-${{ inputs.version }}.rst" sssd-bot "${{ secrets.BOT_TOKEN }}"

scripts/generate-full-release-notes.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ while [[ $# -gt 0 ]]; do
4444
esac
4545
done
4646

47-
notes=`$scriptdir/release-notes.py --from $FROM --to $TO --version $VERSION --format $FORMAT`
47+
notes=`$scriptdir/generate-release-notes.py --from $FROM --to $TO --version $VERSION --format $FORMAT`
4848
fixed_issues=`$scriptdir/fixed-issues.sh --from $FROM --to $TO --format $FORMAT`
4949
gitlog=`git shortlog --pretty=format:"%h %s" -w0,4 $FROM..$TO`
5050

@@ -60,7 +60,7 @@ echo "------------------"
6060
echo ""
6161
echo ".. code-block:: release-notes-shortlog"
6262
echo ""
63-
echo " $ git shortlog --pretty=format:"%h %s" -w0,4 $FROM..$TO"
63+
echo " $ git shortlog --pretty=format:\"%h %s\" -w0,4 $FROM..$TO"
6464
echo ""
6565
echo "$gitlog" | sed 's/^/ /'
6666
echo ""

scripts/release-notes.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Open pull request with release notes against sssd.io
4+
5+
set -e -o pipefail
6+
7+
# Usage
8+
if [ "$#" -ne 4 ]; then
9+
echo "Usage: $0 <version> <path-to-rn> <fork-user> <fork-token>" >&2
10+
exit 1
11+
fi
12+
13+
# Create working directory
14+
scriptdir=`realpath \`dirname "$0"\``
15+
wd=`mktemp -d`
16+
trap 'rm -rf "$wd"' EXIT
17+
18+
# Initial setup
19+
VERSION=$1
20+
PATH_TO_RN=$2
21+
FORK_USER=$3
22+
FORK_TOKEN=$4
23+
24+
GITHUB_REPOSITORY="SSSD/sssd.io"
25+
OWNER=`echo "$GITHUB_REPOSITORY" | cut -d / -f 1`
26+
REPOSITORY=`echo "$GITHUB_REPOSITORY" | cut -d / -f 2`
27+
TARGET="master"
28+
RN_BRANCH_NAME="$OWNER-$REPOSITORY-relnotes-$VERSION"
29+
30+
echo "GitHub Repository: $OWNER/$REPOSITORY"
31+
echo "Target Branch: $TARGET"
32+
echo "Release Notes Branch: $RN_BRANCH_NAME"
33+
echo ""
34+
echo "Action Directory: $scriptdir"
35+
echo "Working Directory: $wd"
36+
echo ""
37+
38+
pushd "$wd"
39+
set -x
40+
41+
# Login with token to GitHub CLI, GH_TOKEN variable is used in GitHub Actions
42+
set +x
43+
if [ -z "$GH_TOKEN" ]; then
44+
echo $FORK_TOKEN > .token
45+
gh auth login --with-token < .token
46+
rm -f .token
47+
fi
48+
set -x
49+
50+
# Clone repository and fetch the pull request
51+
git clone "https://github.com/$OWNER/$REPOSITORY.git" .
52+
git remote add "$FORK_USER" "https://$FORK_USER:$FORK_TOKEN@github.com/$FORK_USER/$REPOSITORY.git"
53+
git checkout "$TARGET"
54+
gh repo set-default "$GITHUB_REPOSITORY"
55+
56+
# Create new branch that we will work on
57+
git checkout -b "$RN_BRANCH_NAME" "$TARGET"
58+
59+
# Copy release notes and update releases.rst
60+
# Insert new release before the first occurrence of ".. release::"
61+
cp -f "$PATH_TO_RN" "./src/release-notes/sssd-$VERSION.rst"
62+
TODAY=$(date +%Y-%m-%d)
63+
RELEASES_FILE="./src/releases.rst"
64+
NEW_RELEASE=$(cat <<EOF
65+
.. release:: sssd-$VERSION
66+
:date: $TODAY
67+
:download: https://github.com/SSSD/sssd/releases/tag/$VERSION
68+
EOF
69+
)
70+
71+
awk -i inplace -v new="$NEW_RELEASE" \
72+
'/^[[:space:]]*\.\. release::/ && !done {print new "\n"; done=1} {print}' \
73+
"$RELEASES_FILE"
74+
75+
# Commit changes
76+
git add --all
77+
git commit -S -a -m "Release sssd-$VERSION"
78+
79+
# Push backport to remote
80+
git push --set-upstream "$FORK_USER" "$RN_BRANCH_NAME" --force
81+
82+
# Prepare pull request message
83+
BODY_FILE="/tmp/relnotes-message"
84+
cat > "$BODY_FILE" <<EOF
85+
These are automatically generated release notes for sssd-$VERSION.
86+
87+
Please review and edit the notes before merging.
88+
89+
**You can push changes to this pull request**
90+
91+
\`\`\`
92+
git remote add $FORK_USER git@github.com:$FORK_USER/$REPOSITORY.git
93+
git fetch $FORK_USER refs/heads/$RN_BRANCH_NAME
94+
git checkout $RN_BRANCH_NAME
95+
git push $FORK_USER $RN_BRANCH_NAME --force
96+
\`\`\`
97+
EOF
98+
99+
gh pr create \
100+
--draft \
101+
--base "$TARGET" \
102+
--body-file "$BODY_FILE" \
103+
--head "$FORK_USER:$RN_BRANCH_NAME" \
104+
--title "Release sssd-$VERSION"

scripts/release.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function GROUP_END() {
1212
}
1313

1414
# Usage
15-
if [ "$#" -ne 2 ] && [ "$#" -ne 4 ]; then
16-
echo "Usage: $0 <branch> <version> [<github-repo> <git-remote>]" >&2
15+
if [ "$#" -ne 3 ] && [ "$#" -ne 5 ]; then
16+
echo "Usage: $0 <branch> <version> <prev-version> [<github-repo> <git-remote>]" >&2
1717
exit 1
1818
fi
1919

@@ -22,15 +22,17 @@ scriptdir=`realpath \`dirname "$0"\``
2222
rootdir=`realpath "$scriptdir/.."`
2323
branch=$1
2424
version=$2
25-
github_repo="${3:-SSSD/sssd}"
26-
git_remote="${4:-origin}"
25+
prev_version=$3
26+
github_repo="${4:-SSSD/sssd}"
27+
git_remote="${5:-origin}"
2728

2829
echo "SSSD sources location: $rootdir"
2930
echo "Repository: $github_repo"
3031
echo "Remote: $git_remote"
3132
echo "Temporary directory: $tmpdir"
3233
echo "Target branch: $branch"
3334
echo "Released version: $version"
35+
echo "Previous version: $prev_version"
3436

3537
# Work in a temporary copy of the repository
3638
pushd $tmpdir
@@ -108,10 +110,16 @@ GROUP_START "Create GitHub release"
108110
gh release create "$version" \
109111
--repo "$github_repo" \
110112
--title "sssd-$version" \
113+
--notes "[**See full release notes here.**](https://sssd.io/release-notes/sssd-$version.html)" \
111114
--generate-notes \
112115
--verify-tag \
113116
--draft \
114117
"sssd-${version}.tar.gz" \
115118
"sssd-${version}.tar.gz.asc" \
116119
"sssd-${version}.tar.gz.sha256sum"
117120
GROUP_END
121+
122+
GROUP_START "Generate release notes"
123+
./scripts/full-release-notes.sh --from "$prev_version" --to HEAD --version "$version" > "/tmp/sssd-$version.rst"
124+
echo "Release notes stored at /tmp/sssd-$version.rst"
125+
GROUP_END

0 commit comments

Comments
 (0)