Skip to content

Commit

Permalink
adding workflows and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
wjcunningham7 committed Apr 10, 2022
1 parent 6a341b9 commit ef27742
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 1 deletion.
82 changes: 82 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: changelog

on:
push:
branches:
- develop
paths-ignore:
- 'CHANGELOG.md'
- 'VERSION'

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Check out head
uses: actions/checkout@v3
with:
token: ${{ secrets.FASTMATH_OPS_BOT_TOKEN }}
- name: Update version number
run: |
HEAD_VERSION="$(cat ./VERSION)"
begin=8
end=$(tail -n +$((begin+1)) ./CHANGELOG.md |
grep -n -m 1 "\b${HEAD_VERSION}\b" |
cut -d ':' -f 1)
patch=false
minor=false
noupdate=false
while IFS= read -r line ; do
if [[ $line = *"### Added"* ]] ||
[[ $line = *"### Changed"* ]] ||
[[ $line = *"### Removed"* ]] ; then
minor=true
fi
if [[ $line = *"### Fixed"* ]] ; then
patch=true
fi
if [[ $line = *"### Tests"* ]] ||
[[ $line = *"### Docs"* ]] ; then
noupdate=true
fi
done <<< "$(tail +$begin ./CHANGELOG.md | head -$end)"
IFS='.' read -ra semver <<< "$HEAD_VERSION"
vmajor="${semver[0]}"
vminor="${semver[1]}"
vpatch="${semver[2]}"
if $minor; then
#increment minor version
vminor="$(( vminor + 1 ))"
vpatch=0
elif $patch; then
#increment patch version
vpatch="$(( vpatch + 1 ))"
elif $noupdate; then
#do nothing
:
else
echo 'Changelog does not contain enough information to update the version.'
exit 1
fi
version="${vmajor}.${vminor}.${vpatch}"
changelog_header="## [${version}] - $(date -I)"
message="noop"
if $minor || $patch ; then
message="The new version will be $version"
nl=$'\n'
sed -i '/UNRELEASED/a\'$'\n''\'$'\n'"$changelog_header" CHANGELOG.md
echo $version > VERSION
echo $message
else
echo "This PR only contains updates to tests and docs. No release will be created."
fi
echo "MESSAGE=$message" >> $GITHUB_ENV
- name: Commit
if: ${{ env.MESSAGE != 'noop' }}
uses: EndBug/add-and-commit@v9
with:
author_name: FastMathOpsBot
author_email: fastmathopsbot@users.noreply.github.com
message: ${{ env.MESSAGE }}
push: origin develop --force

20 changes: 20 additions & 0 deletions .github/workflows/changelog_reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
pull_request

name: Changelog Reminder

jobs:
remind:
name: Changelog Reminder
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Changelog Reminder
uses: peterjgrainger/action-changelog-reminder@v1.3.0
with:
changelog_regex: 'CHANGELOG.md'
customPrMessage: |
Hello. You may have forgotten to update the changelog!
Please edit [`CHANGELOG.md`](/AgnostiqHQ/covalent/blob/master/CHANGELOG.md) with a one-to-two sentence description of the change in the UNRELEASED section. You may include a small working example for new features.
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out master
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
- name: Read version
run: |
VERSION="$(cat ./VERSION)"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE=v$VERSION" >> $GITHUB_ENV
- name: Tag commit
id: push
run: |
git config user.name "FastMathOpsBot"
git config user.email "fastmathopsbot@users.noreply.github.com"
git tag -a $RELEASE -m "Release $RELEASE"
git remote set-url origin https://${{ secrets.FASTMATH_OPS_BOT_TOKEN }}@github.com/wjcunningham7/fastmath.git
git push origin $RELEASE
- name: Generate release message
id: message
run: |
begin=$(grep -n "\b${VERSION}\b" ./CHANGELOG.md | cut -d ':' -f 1)
previous_version=$(git describe --abbrev=0 $RELEASE^ | cut -c2-)
end=$(tail -n +$((begin+1)) ./CHANGELOG.md | grep -n -m 1 "\b${previous_version}\b" | cut -d ':' -f 1)
echo 'MESSAGE<<EOF' >> $GITHUB_ENV
tail +$begin ./CHANGELOG.md | head -$end >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Create release
if: ${{ steps.push.outcome == 'success' && steps.message.outcome == 'success' }}
uses: ncipollo/release-action@v1
with:
body: ${{ env.MESSAGE }}
token: ${{ secrets.FASTMATH_OPS_BOT_TOKEN }}
tag: ${{ env.RELEASE }}
prerelease: true
57 changes: 57 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: version

on: pull_request

jobs:
version:
runs-on: ubuntu-latest
steps:
- name: Check out head
uses: actions/checkout@v1
with:
fetch-depth: 0
- name: Check git history
run: |
if git merge-base --is-ancestor $GITHUB_SHA origin/develop; then
echo "DEVELOP_COMMIT_HISTORY=$GITHUB_SHA" >> $GITHUB_ENV
fi
- name: Check for version change
id: changed-version-file
uses: tj-actions/changed-files@v18.4
with:
files: |
VERSION
- name: Fail if version changed
if: ${{ steps.changed-version-file.outputs.any_changed == 'true' && github.sha != env.DEVELOP_COMMIT_HISTORY }}
run: |
echo "Version changes are prohibited in pull requests."
exit 10
- name: Read head version
if: ${{ github.sha != env.DEVELOP_COMMIT_HISTORY }}
run: |
HEAD_VERSION="$(cat ./VERSION)"
echo "HEAD_VERSION=$HEAD_VERSION" >> $GITHUB_ENV
- name: Validate changelog entry
if: ${{ github.sha != env.DEVELOP_COMMIT_HISTORY }}
run: |
git diff --name-only origin/develop | grep CHANGELOG
unreleased_header_line=8
if [[ $(sed "${unreleased_header_line}q;d" CHANGELOG.md) != "## [UNRELEASED]" ]] ; then
echo 'Removing the [UNRELEASED] header is prohibited in pull requests.'
exit 4
fi
latest_release=$(sed -n "/\[[0-9]\+\.[0-9]\+\.[0-9]\+\]/=" CHANGELOG.md | head -n 1)
IFS='[]' read -ra changelog_version <<< $(sed "${latest_release}q;d" CHANGELOG.md)
if [[ "${changelog_version[1]}" != $HEAD_VERSION ]] ; then
echo 'The most recent CHANGELOG release does not match the VERSION'.
exit 3
fi
#Check that the lines in the diff are between unreleased_header_line and latest_release
IFS='@-+,' read -ra LINES <<< "$(git diff develop -- CHANGELOG.md | sed '5q;d')"
start_head="$(( LINES[5] + 3 ))"
lines_head="$(( LINES[6] - 6 ))"
if [[ $start_head -lt $unreleased_header_line ]] ||
[[ $((start_head + lines_head)) -gt $latest_release ]] ; then
echo 'Changes outside the UNRELEASED block are prohibited in pull requests.'
exit 6
fi
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0]

### Added

- Core repository files.
- Semantic versioning enforcement.
- Stylization enforcement.
- Basic workflows for changelog and versioning.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
1.0.0

0 comments on commit ef27742

Please sign in to comment.