diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..99b220d --- /dev/null +++ b/.github/workflows/changelog.yml @@ -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 + diff --git a/.github/workflows/changelog_reminder.yml b/.github/workflows/changelog_reminder.yml new file mode 100644 index 0000000..0ef7d8b --- /dev/null +++ b/.github/workflows/changelog_reminder.yml @@ -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 }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..be963bd --- /dev/null +++ b/.github/workflows/release.yml @@ -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<> $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 diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..6662565 --- /dev/null +++ b/.github/workflows/version.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0fcedf4 --- /dev/null +++ b/CHANGELOG.md @@ -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. diff --git a/VERSION b/VERSION index 8c50098..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1 +1.0.0