Skip to content

Commit

Permalink
OPCT-239: create basic changelog builder based in commits (#74)
Browse files Browse the repository at this point in the history
Generate changelog by commits when mkdocs is building the docs.

The reason for this change is to improve the report for each release,
currently, there is a GitHub action that generates a delta when a new
release is created but the delta is always based on the last GitHub
release, not the last Major version, most interested by us as the
project uses SemVer standards.
  • Loading branch information
mtulio committed Sep 21, 2023
1 parent 2c7e3b7 commit 94c1575
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/static-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y python3-pip graphviz
pip3 install -r hack/docs-requirements.txt
mkdocs build --site-dir ./site
make build-docs
- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ vet:
.PHONY: clean
clean:
rm -rvf ./build/ ./openshift-provider-cert-* ./opct-*

# For dependencies, see:
# .github/workflows/static-website.yml
# hack/docs-requirements.txt

.PHONY: build-changelog
build-changelog:
./hack/generate-changelog.sh

.PHONY: build-docs
build-docs: build-changelog
mkdocs build --site-dir ./site
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gitkeep
90 changes: 90 additions & 0 deletions hack/generate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

#
# This script generates changelog fragments for each release,
# ordered it by newest release and publish it in the docs
# page /CHANGELOG.
# TODO: generate changelog for plugins repo.
#

set -o errexit
set -o nounset
set -o pipefail

releases=("v0.1.0" "v0.2.0" "v0.3.0" "v0.4.0")

chagelog_file="$(dirname $0)"/../docs/CHANGELOG.md
chagelog_dir="$(dirname $0)"/../docs/changelogs
chagelog_dir="/tmp/opct-changelogs"
mkdir -p $chagelog_dir

cat > "$chagelog_file" << EOF
# CHANGELOG
EOF

first_commit=$(git rev-list --max-parents=0 HEAD)
init_release=$first_commit
for rel in ${releases[*]}; do
ch_file=$chagelog_dir/$rel.md
echo -e "\n# [$rel](https://github.com/redhat-openshift-ecosystem/provider-certification-tool/releases/tag/$rel)" > "$ch_file"
echo -e "OPCT:\n" >> "$ch_file"
git log --pretty=oneline --abbrev-commit --no-decorate --no-color $init_release..tags/$rel | \
while read line
do
commit="$(echo $line | awk '{print$1}')"
commit_url="[$commit](https://github.com/redhat-openshift-ecosystem/provider-certification-tool/commit/$commit)"
line="${line#"$commit"}"
jira_card=$(echo $line | grep -Po '(OPCT-\d+)' || true)
if [ -n "${jira_card-}" ] ; then
line=$(echo $line | sed "s/$jira_card/\[$jira_card\]\(https\:\/\/issues.redhat.com\/browse\/$jira_card\)/")
fi
pr_id=$(echo $line | grep -Po '#\d+' || true)
if [ -n "${pr_id-}" ] ; then
line=$(echo $line | sed "s/$pr_id/\[$pr_id\]\(https\:\/\/github.com\/redhat-openshift-ecosystem\/provider-certification-tool\/pull\/${pr_id#\#}\)/")
fi
echo -e "- $commit_url - ${line}" >> "$ch_file"
done
init_release=$rel
echo -e "\n\n" >> "$ch_file"
done

# devel (since last release - need to run from 'main' branch)
ch_file=$chagelog_dir/devel.md
echo -e "\n# Development\n" > "$ch_file"
echo -e "OPCT:\n" >> "$ch_file"
git log --pretty=oneline --abbrev-commit --no-decorate --no-color $init_release..HEAD | \
while read line
do
commit="$(echo $line | awk '{print$1}')"
commit_url="[$commit](https://github.com/redhat-openshift-ecosystem/provider-certification-tool/commit/$commit)"
line="${line#"$commit"}"
jira_card=$(echo $line | grep -Po '(OPCT-\d+)' || true)
if [ -n "${jira_card-}" ] ; then
line=$(echo $line | sed "s/$jira_card/\[$jira_card\]\(https\:\/\/issues.redhat.com\/browse\/$jira_card\)/")
fi
pr_id=$(echo $line | grep -Po '#\d+' || true)
if [ -n "${pr_id-}" ] ; then
line=$(echo $line | sed "s/$pr_id/\[$pr_id\]\(https\:\/\/github.com\/redhat-openshift-ecosystem\/provider-certification-tool\/pull\/${pr_id#\#}\)/")
fi
echo -e "- $commit_url - ${line}" >> "$ch_file"
done

cat > "$chagelog_file" << EOF
# CHANGELOG
EOF

cat $chagelog_dir/devel.md >> "$chagelog_file"
for rev_releases in $(ls -r $chagelog_dir --ignore=devel.md); do
echo -e "\n" >> "$chagelog_file"
cat $chagelog_dir/$rev_releases >> "$chagelog_file"
done

echo -e "\n\n > This page is generated automatically by CI/hack-generate-changelog.sh\n\n" >> "$chagelog_file"


# TODO: create plugin changelog
#plugin_releases=("v0.1.1" "v0.2.2" "v0.3.0" "v0.4.0")
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ nav:
- diagrams/index.md
- diagrams/opct-sequence.md
- "Reference Architecture": diagrams/ocp-architecture-reference.md
- CHANGELOG: CHANGELOG.md

0 comments on commit 94c1575

Please sign in to comment.