From e23c4b78b5da8dcbded2763bb9b67493b77e58e8 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 21 Nov 2020 11:21:19 -0800 Subject: [PATCH] Add changelog generation workflow to github actions (#1086) * Add changelog workflow to github actions, remove old script This basically takes the exact script, and turns it into a workflow. The only difference is that the new workflow doesn't detect a release build like the script did (releases will be a separate workflow). * remove old config file for changelog generator (it's in workflow now) * whitespace change * remove ableist language --- .build/generate_changelog.sh | 64 ------------------------- .github/workflows/changelog.yaml | 82 ++++++++++++++++++++++++++++++++ .github_changelog_generator | 12 ----- 3 files changed, 82 insertions(+), 76 deletions(-) delete mode 100755 .build/generate_changelog.sh create mode 100644 .github/workflows/changelog.yaml delete mode 100644 .github_changelog_generator diff --git a/.build/generate_changelog.sh b/.build/generate_changelog.sh deleted file mode 100755 index 6b3704589..000000000 --- a/.build/generate_changelog.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -BRANCH=$TRAVIS_BRANCH -if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then - BRANCH='release' -fi - -# Check if branch has been updated since this build started -# This tends to happen if multiple things have been merged in at the same time. -if [[ -z $TRAVIS_TAG ]]; then - git fetch origin - if [[ $(git rev-parse "origin/${BRANCH}") != $TRAVIS_COMMIT ]]; then - echo "${BRANCH} has been updated since build started. Aborting changelog." - exit 0 - fi -fi - -FILENAME='CHANGELOG.md' - -# get the latest git tags -releases="$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)')" -release_latest=$(printf '%s' "$releases" | awk 'NR==1') -release_secondlatest=$(printf '%s' "$releases" | awk 'NR==2') - -echo "release_latest: ${release_latest}" -echo "release_secondlatest: ${release_secondlatest}" - -# 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" - -# determine correct tag to go back to -if [[ $TRAVIS_TAG == $release_latest ]]; then - echo "release build" - gittag=${release_secondlatest} -elif [[ ! -z $TRAVIS_TAG ]]; then - echo "beta elease" - gittag=${release_latest} -else - echo "merge into release or develop" - gittag=${release_latest} -fi -echo "gittag: ${gittag}" - -# find the line the tag starts on, and subtract 1 -tagline=$(grep -n "^## \[\?$gittag\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1) -echo "tagline: ${tagline}" -[[ ! -z $tagline ]] && sed -i "1,$(expr $tagline - 1)d" "$FILENAME" - -# generate the changelog -docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -t $GITHUB_TOKEN --since-tag $gittag - -# Put back our link (instead of the broken one) -sed -i 's!https://pypi.org/project/jrnl/HEAD/!https://github.com/jrnl-org/jrnl/!' "$FILENAME" - -git config --global user.email "jrnl.bot@gmail.com" -git config --global user.name "Jrnl Bot" -git checkout $BRANCH -git add "$FILENAME" -git commit -m "Update changelog [ci skip]" -git push https://${GITHUB_TOKEN}@github.com/jrnl-org/jrnl.git $BRANCH - diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 000000000..5e83c0eb5 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,82 @@ +name: Changelog + +on: + push: + branches: [ develop ] + +jobs: + generate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Check branch for new commits + run: | + git fetch origin + BRANCH="${GITHUB_REF##*/}" + if [[ $(git rev-parse "origin/$BRANCH") != $GITHUB_SHA ]]; then + echo "BRANCH: $BRANCH" + echo "GITHUB_SHA: $GITHUB_SHA" + echo "$BRANCH has been updated since build started. Aborting changelog." + exit 1 + fi + echo "BRANCH=$BRANCH" >> $GITHUB_ENV + + - name: Prep environment variables + run: | + echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + echo "FILENAME=CHANGELOG.md" >> $GITHUB_ENV + echo "gittag=$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)' | awk 'NR==1')" >> $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 "^## \[\?$gittag\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1) + echo "tagline: ${tagline}" + [[ ! -z $tagline ]] && 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.GITHUB_TOKEN }} + base: CHANGELOG.md + addSections: '{"build":{"prefix":"**Build:**","labels":["build"]},"docs":{"prefix":"**Documentation:**","labels":["documentation"]}}' + issues: true + issuesWoLabels: false + unreleased: true + compareLink: true + includeLabels: bug,enhancement,documentation,build,deprecated + excludeLabels: stale,wontfix + excludeTagsRegex: '(alpha|beta|rc)' + sinceTag: ${{ env.gittag }} + releaseUrl: https://pypi.org/project/jrnl/%s/ + 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: Consistency check + run: | + if [[ $(grep '^# Changelog$' "$FILENAME") != 1 ]]; then + echo 'Something is wrong with the changelog.' + git diff -- "$FILENAME" + exit 1 + fi + + - name: Commit + run: | + git config user.email "jrnl.bot@gmail.com" + git config user.name "Jrnl Bot" + git add "$FILENAME" + git commit -m "Update changelog" + git push origin $BRANCH + diff --git a/.github_changelog_generator b/.github_changelog_generator deleted file mode 100644 index b764f763f..000000000 --- a/.github_changelog_generator +++ /dev/null @@ -1,12 +0,0 @@ -project=jrnl -user=jrnl-org -base=CHANGELOG.md -issues=true -issues-wo-labels=false -include-labels=bug,enhancement,documentation,build,deprecated -exclude-labels=stale,wontfix -release-url=https://pypi.org/project/jrnl/%s/ -add-sections={ "build": { "prefix": "**Build:**", "labels": ["build"]}, "docs": { "prefix": "**Updated documentation:**", "labels": ["documentation"]}} -exclude-tags-regex=(alpha|beta|rc) -verbose=false -