mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 14:06:14 +02:00
Add a release workflow for PyPI in CI (Github Actions) (#1095)
* Fixes for new CI pipeline (Github Actions) - Support ci skip tag on commits to avoid build dupes - Add smarter path detection so we don't spam tons of tests - Allow steps to cancel if previous steps were cancelled (don't always run) - Separate workflows to be more modular - Update release workflow to do a few more things - Add helpful messages - Be more strict in version checking (now with added regex) - Make changelog smarter about when to trigger - Add some functionality for changelog to handle releases and prereleases separately - Better error handling - Split up the version validation and the release to make way for more releases * add step in workflow to merge to release branch after a release * add check for git diff so commit doesn't error out constantly
This commit is contained in:
parent
e9d909a3ba
commit
4cad215560
4 changed files with 260 additions and 72 deletions
104
.github/workflows/changelog.yaml
vendored
104
.github/workflows/changelog.yaml
vendored
|
@ -2,11 +2,20 @@ name: Changelog
|
|||
|
||||
on:
|
||||
push:
|
||||
branches: [ develop ]
|
||||
branches:
|
||||
- develop
|
||||
create:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
if: contains(toJson(github.event.commits), 'Update changelog') == false
|
||||
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:
|
||||
|
@ -14,31 +23,70 @@ jobs:
|
|||
with:
|
||||
token: ${{ secrets.JRNL_BOT_TOKEN }}
|
||||
|
||||
- name: Check branch for new commits
|
||||
- name: Check branch for new commits, and env vars
|
||||
run: |
|
||||
git fetch origin
|
||||
git fetch --tags origin
|
||||
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 [[ $(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."
|
||||
|
||||
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
|
||||
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
|
||||
|
||||
- name: Prep environment variables
|
||||
run: |
|
||||
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
|
||||
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 "gittag=$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)' | awk 'NR==1')" >> $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 "^## \[\?$gittag\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
|
||||
tagline=$(grep -n "^## \[\?${SINCE_TAG}\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
|
||||
echo "tagline: ${tagline}"
|
||||
[[ ! -z $tagline ]] && sed -i "1,$(expr $tagline - 1)d" "$FILENAME"
|
||||
|
||||
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
|
||||
|
@ -59,10 +107,11 @@ jobs:
|
|||
compareLink: true
|
||||
includeLabels: bug,enhancement,documentation,build,deprecated
|
||||
excludeLabels: stale,wontfix
|
||||
excludeTagsRegex: '(alpha|beta|rc)'
|
||||
sinceTag: ${{ env.gittag }}
|
||||
excludeTagsRegex: ${{ env.TAG_REGEX }}
|
||||
sinceTag: ${{ env.SINCE_TAG }}
|
||||
maxIssues: 150
|
||||
releaseUrl: https://pypi.org/project/jrnl/%s/
|
||||
releaseBranch: develop
|
||||
verbose: false
|
||||
|
||||
- name: Small fixes
|
||||
|
@ -70,19 +119,28 @@ jobs:
|
|||
# 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
|
||||
- name: Diff and consistency check
|
||||
run: |
|
||||
git diff
|
||||
if [[ $(grep -c '^# Changelog$' "$FILENAME") != 1 ]]; then
|
||||
echo 'Something is wrong with the changelog.'
|
||||
git diff -- "$FILENAME"
|
||||
exit 1
|
||||
echo '::error::Something is wrong with the changelog.'
|
||||
fi
|
||||
SOMETHING_CHANGED=false
|
||||
git diff --exit-code || SOMETHING_CHANGED=true
|
||||
|
||||
- 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"
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue