Skip to content

Commit

Permalink
build: generate nightly changelog from commit history (#22377)
Browse files Browse the repository at this point in the history
* build: generated nightly changelog from commit history

* build: update goreleaser version
  • Loading branch information
codyshepherd committed Sep 7, 2021
1 parent 7ad612b commit 824e76c
Show file tree
Hide file tree
Showing 8 changed files with 3,088 additions and 1,478 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ workflows:
only:
- master
jobs:
- changelog
- godeps
- gotest:
requires:
Expand All @@ -137,6 +138,7 @@ workflows:
- godeps
- deploy_nightly:
requires:
- changelog
- gotest
- golint
- tlstest
Expand Down Expand Up @@ -809,3 +811,35 @@ jobs:
docker load < docker-image.tar
docker tag quay.io/influxdb/oss-acceptance:${CIRCLE_SHA1} quay.io/influxdb/oss-acceptance:latest
docker push quay.io/influxdb/oss-acceptance:latest
changelog:
machine:
image: ubuntu-2004:202010-01
steps:
- checkout
- install_core_deps
- run:
name: Run script
command: |
set -x
git clone --depth=1 --branch v0.2.5 https://github.com/orhun/git-cliff
cd git-cliff
cargo install git-cliff
cd ..
TIMESTAMP="$(date -u '+%Y%m%d')"
COMMIT_FILE_PATH="scripts/ci/changelog-commit.txt"
LAST_COMMIT=$(cat $COMMIT_FILE_PATH)
NEWEST_COMMIT=${CIRCLE_SHA1}
./scripts/ci/update-changelog.sh \
--commit-range "$LAST_COMMIT..$NEWEST_COMMIT" \
--prepend CHANGELOG.md \
-- \
--tag $TIMESTAMP
echo ${CIRCLE_SHA1} > $COMMIT_FILE_PATH
git add CHANGELOG.md $COMMIT_FILE_PATH
git config user.email "team-edge@influxdata.com"
git config user.name "Edge Team CircleCI Automation"
git commit -m "changelog: update $TIMESTAMP [skip ci]"
git push origin $CIRCLE_BRANCH
- store_artifacts:
path: CHANGELOG.md
11 changes: 11 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ blobs:
bucket: "dl.influxdata.com"
region: "us-east-1"
folder: "platform/nightlies/"
extra_files:
- glob: ./CHANGELOG.md
# Duplicating the contents to another folder in the bucket ensures
# scheme parity with release branches; eventually the artifacts should
# __only__ appear in the branch-specific folder
- provider: "s3"
bucket: "dl.influxdata.com"
region: "us-east-1"
folder: "platform/nightlies/master/"
extra_files:
- glob: ./CHANGELOG.md

checksum:
name_template: "influxdb2-nightly.sha256"
Expand Down
1,478 changes: 0 additions & 1,478 deletions CHANGELOG.md

Large diffs are not rendered by default.

1,451 changes: 1,451 additions & 0 deletions CHANGELOG.md.orig

Large diffs are not rendered by default.

1,478 changes: 1,478 additions & 0 deletions CHANGELOG_OLD.md

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[changelog]
body = """
{%- if version %}
## {{ version }} [{{ timestamp | date(format="%Y-%m-%d") }}]
{%- else %}
## [unreleased]
{%- endif %}
----------------------
{% set grouped_commits = commits | group_by(attribute="group") -%}
{%- set_global groups_arr = [] -%}
{%- for group, _commits in grouped_commits -%}
{%- set_global groups_arr = groups_arr | concat(with=group) -%}
{%- endfor -%}
{% for group in groups_arr | sort | reverse %}
{% set g_commits = grouped_commits[group] -%}
### {{ group | upper_first }}
{% for commit in g_commits -%}
{%- set message = commit.message | split(pat="\n") | first | split(pat=": ") | slice(start=1) | join(sep=" ") | trim | capitalize -%}
{% set pr_num = message | split(pat=" ") | last | trim_start_matches(pat="(") | trim_end_matches(pat=")") | trim_start_matches(pat="#") %}
{%- set message = message | split(pat=" ") | slice(end=-1) | join(sep=" ") | trim %}
1. [{{ pr_num }}](https://github.com/influxdata/influxdb/pull/{{ pr_num }}): {{ message }}
{%- endfor %}
{% endfor %}
"""
trim = true

[git]
conventional_commits = false
commit_parsers = [
{ message = "^feat*", group = "Features"},
{ message = "^fix*", group = "Bug Fixes"},
]
filter_commits = true
tag_pattern = "v[12].[0-9].[0-9]*"
1 change: 1 addition & 0 deletions scripts/ci/changelog-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
891e7d47827e99947e46c82f509e479aa13acf24
78 changes: 78 additions & 0 deletions scripts/ci/update-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -ex


dependencies="cargo git git-cliff"

for dependency in $dependencies
do
if ! command -v $dependency &>/dev/null
then
echo "error: $dependency was not found in PATH" >&2
exit 255
fi
done

# The default "starting" commit is a somewhat arbitrary starting point for
# cataloging recent commits in a way that breaks from the old convention
DEFAULT_START_COMMIT="891e7d47827e99947e46c82f509e479aa13acf24"
DEFAULT_NEWEST_COMMIT="$(git rev-parse HEAD)"
DEFAULT_COMMIT_RANGE="${DEFAULT_START_COMMIT}..${DEFAULT_NEWEST_COMMIT}"

COMMIT_RANGE="${DEFAULT_COMMIT_RANGE}"

DEFAULT_GIT_CLIFF_OPTIONS=""
PREPEND_TARGET=""

function print-usage {
cat << EOF >&2
usage: $0 [<options>] -- [<git cliff flags>] [<git cliff options>]
--commit-range <git commit range> The specific range of commits from which to generate the changelog.
A hardcoded default sets a range that is contemporaneous with the
addition of this script to influxdb CI.
Value: $COMMIT_RANGE
--prepend <file path> Target a file to which to prepend the git-cliff output. This is not
the same as the git-cliff prepend option, which can only be used with
the -l or -u flags in that tool.
Value: $PREPEND_TARGET
Options specified after '--' separator are used by git-cliff directly
EOF
}

while [[ $# -gt 0 ]]; do
case $1 in
--commit-range)
COMMIT_RANGE="$2"
shift
;;
--prepend)
PREPEND_TARGET="$2"
shift
;;
--help)
print-usage
exit 255
;;
--)
shift
break
;;
*)
echo "error: unknown option '$1'" >&2
exit 255
;;
esac
shift
done

output="$(git cliff ${@} ${DEFAULT_GIT_CLIFF_OPTIONS} ${COMMIT_RANGE})"

if [ -n "$PREPEND_TARGET" ] && [ -n "$output" ]; then
newline=$'\n\n'
echo "${output}${newline}$(cat $PREPEND_TARGET)" > $PREPEND_TARGET
else
echo "$output"
fi

0 comments on commit 824e76c

Please sign in to comment.