mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
The changelog was triggering after each branch create on a repo. That doesn't happen often on the main repo, but does happen often on contributor forks. This should stop the rampant GH actions.
147 lines
5.2 KiB
YAML
147 lines
5.2 KiB
YAML
name: Changelog
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- develop
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
generate:
|
|
if: >
|
|
! contains(github.event.head_commit.message, '[ci skip]') &&
|
|
! (
|
|
startsWith(github.event.head_commit.message, 'Increment version to v') &&
|
|
startsWith(github.ref, 'refs/heads/')
|
|
)
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
token: ${{ secrets.JRNL_BOT_TOKEN }}
|
|
|
|
- name: Check branch for new commits, and env vars
|
|
run: |
|
|
echo "::group::git fetch origin --tags --force"
|
|
git fetch origin --tags --force
|
|
echo "::endgroup::"
|
|
|
|
TAG_REGEX='include-all'
|
|
echo "::debug::GITHUB_REF: $GITHUB_REF"
|
|
BRANCH="${GITHUB_REF##*/}"
|
|
|
|
if [[ $GITHUB_REF =~ ^refs/tags/ ]]; then
|
|
# This is a tag build (i.e. a release)
|
|
echo '::debug::Release build'
|
|
if [[ ! $BRANCH =~ ^v[0-9]+(\.[0-9]+){1,2}(-(alpha|beta)(\.[0-9]+)?)?$ ]]; then
|
|
echo "::error::Invalid tag format: ${BRANCH}"
|
|
exit 1
|
|
fi
|
|
|
|
RELEASE=1
|
|
BRANCH=develop
|
|
git checkout $BRANCH
|
|
|
|
# if actual release (not pre), then changelog should exclude prereleases on update
|
|
prerelease_regex='(alpha|beta)'
|
|
if [[ ! ${GITHUB_REF##*/} =~ $prerelease_regex ]]; then
|
|
echo '::debug::Actual release (not a prerelease)'
|
|
TAG_REGEX="$prerelease_regex"
|
|
echo "FULL_RELEASE=true" >> $GITHUB_ENV
|
|
fi
|
|
fi
|
|
echo "::debug::TAG_REGEX: $TAG_REGEX"
|
|
|
|
if [[ "$(git rev-parse "origin/$BRANCH")" != $GITHUB_SHA ]]; then
|
|
# Normal build on a branch (no tag)
|
|
echo "::debug::BRANCH: $BRANCH"
|
|
echo "::debug::GITHUB_SHA: $GITHUB_SHA"
|
|
echo "::error::$BRANCH has been updated since build started. Aborting changelog."
|
|
exit 1
|
|
fi
|
|
|
|
SINCE_TAG=$(git tag --sort=-creatordate | grep -Ev "$TAG_REGEX" | awk "NR==$(( 1 + ${RELEASE:-0} ))")
|
|
|
|
echo "::debug::BRANCH: $BRANCH"
|
|
echo "::debug::TAG_REGEX: $TAG_REGEX"
|
|
echo "::debug::FILENAME: CHANGELOG.md"
|
|
echo "::debug::SINCE_TAG: $SINCE_TAG"
|
|
|
|
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
|
|
echo "TAG_REGEX=$TAG_REGEX" >> $GITHUB_ENV
|
|
echo "FILENAME=CHANGELOG.md" >> $GITHUB_ENV
|
|
echo "SINCE_TAG=$SINCE_TAG" >> $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 "^## \[\?${SINCE_TAG}\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
|
|
echo "tagline: ${tagline}"
|
|
|
|
if [[ -z $tagline ]]; then
|
|
echo "::error::Something is wrong. ${SINCE_TAG} isn't in the changelog."
|
|
exit 1
|
|
fi
|
|
|
|
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.JRNL_BOT_TOKEN }}
|
|
base: CHANGELOG.md
|
|
addSections: '{"build":{"prefix":"**Build:**","labels":["build"]},"docs":{"prefix":"**Documentation:**","labels":["documentation"]}}'
|
|
issues: true
|
|
pullRequests: true
|
|
issuesWoLabels: false
|
|
unreleased: true
|
|
compareLink: true
|
|
includeLabels: bug,enhancement,documentation,build,deprecated
|
|
excludeLabels: stale,wontfix
|
|
excludeTagsRegex: ${{ env.TAG_REGEX }}
|
|
sinceTag: ${{ env.SINCE_TAG }}
|
|
maxIssues: 150
|
|
releaseUrl: https://pypi.org/project/jrnl/%s/
|
|
releaseBranch: develop
|
|
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: Diff and consistency check
|
|
run: |
|
|
git diff
|
|
if [[ $(grep -c '^# Changelog$' "$FILENAME") != 1 ]]; then
|
|
echo '::error::Something is wrong with the changelog.'
|
|
fi
|
|
SOMETHING_CHANGED=false
|
|
git diff --exit-code || SOMETHING_CHANGED=true
|
|
echo "::debug::SOMETHING_CHANGED: $SOMETHING_CHANGED"
|
|
echo "SOMETHING_CHANGED=$SOMETHING_CHANGED" >> $GITHUB_ENV
|
|
|
|
- name: Commit
|
|
if: env.SOMETHING_CHANGED
|
|
run: |
|
|
git config user.email "jrnl.bot@gmail.com"
|
|
git config user.name "Jrnl Bot"
|
|
git add "$FILENAME"
|
|
git commit -m "Update changelog [ci skip]"
|
|
git push origin $BRANCH
|
|
|
|
- name: Merge to Release branch
|
|
if: env.FULL_RELEASE
|
|
run: |
|
|
git checkout release
|
|
git merge --ff-only $BRANCH
|
|
git push origin release
|
|
|