Skip to content

Commit

Permalink
preparing for release (#13)
Browse files Browse the repository at this point in the history
* preparing for release

* added changelog
  • Loading branch information
wjcunningham7 authored Aug 12, 2022
1 parent e726229 commit fe6c363
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 15 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Copyright 2021 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the GNU Affero General Public License 3.0 (the "License").
# A copy of the License may be obtained with this software package or at
#
# https://www.gnu.org/licenses/agpl-3.0.en.html
#
# Use of this file is prohibited except in compliance with the License. Any
# modifications or derivative works of this file must retain this copyright
# notice, and modified files must contain a notice indicating that they have
# been altered from the originals.
#
# Covalent is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
#
# Relief from the License may be granted by purchasing a commercial license.

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.COVALENT_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: CovalentOpsBot
author_email: [email protected]
message: ${{ env.MESSAGE }}
push: origin develop --force

40 changes: 40 additions & 0 deletions .github/workflows/changelog_reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2021 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the GNU Affero General Public License 3.0 (the "License").
# A copy of the License may be obtained with this software package or at
#
# https://www.gnu.org/licenses/agpl-3.0.en.html
#
# Use of this file is prohibited except in compliance with the License. Any
# modifications or derivative works of this file must retain this copyright
# notice, and modified files must contain a notice indicating that they have
# been altered from the originals.
#
# Covalent is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
#
# Relief from the License may be granted by purchasing a commercial license.

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/[email protected]
with:
changelog_regex: 'CHANGELOG.md'
customPrMessage: |
Hello. You may have forgotten to update the changelog!
Please edit [`CHANGELOG.md`](/AgnostiqHQ/covalent-ecs-plugin/blob/main/CHANGELOG.md) with a one-to-two sentence description of the change. You may include a small working example for new features.
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
187 changes: 187 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Copyright 2021 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the GNU Affero General Public License 3.0 (the "License").
# A copy of the License may be obtained with this software package or at
#
# https://www.gnu.org/licenses/agpl-3.0.en.html
#
# Use of this file is prohibited except in compliance with the License. Any
# modifications or derivative works of this file must retain this copyright
# notice, and modified files must contain a notice indicating that they have
# been altered from the originals.
#
# Covalent is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
#
# Relief from the License may be granted by purchasing a commercial license.

name: release

on:
workflow_dispatch:
inputs:
stable_version:
description: "Stable version number, e.g. 0.32.3"
type: string
test_release:
description: "Test the workflow but don't create the release. Uncheck this box to create a release."
required: true
type: boolean
default: true
workflow_call:
inputs:
prerelease:
description: "true: Create a prerelease. false: Create a stable release"
required: true
type: boolean
default: true


env:
PAUL_BLART: >
'['
'"scottwn",'
'"FyzHsn",'
'"wjcunningham7",'
'"santoshkumarradha"]'
jobs:
github:
runs-on: ubuntu-latest
steps:
- name: Check out release tag
uses: actions/checkout@v2
if: github.event.inputs.stable_version
with:
persist-credentials: false
fetch-depth: 0
ref: "v${{ github.event.inputs.stable_version }}"

- name: Check out master
uses: actions/checkout@v2
if: inputs.prerelease
with:
persist-credentials: false
fetch-depth: 0

- name: Read version
run: |
if [ -z ${{ inputs.prerelease }} ] && \
[ -z ${{ github.event.inputs.stable_version }} ] ; then
echo "You can't create a stable release without specifying the stable version number."
exit 1
fi
VERSION="$(cat ./VERSION)"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE=v$VERSION" >> $GITHUB_ENV
- name: Tag commit
if: inputs.prerelease
id: push
run: |
git config user.name "CovalentOpsBot"
git config user.email "[email protected]"
git tag -a $RELEASE -m "Release $RELEASE"
git remote set-url origin https://${{ secrets.COVALENT_OPS_BOT_TOKEN }}@github.com/AgnostiqHQ/covalent-ecs-plugin.git
git push origin $RELEASE
- name: Check conditions for stable release
if: >
github.event.inputs.stable_version
&& contains(env.PAUL_BLART, github.actor)
id: no-push
run: echo "Stable release for version ${{ github.event.inputs.stable_version }}"

- 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.no-push.outcome == 'success')
&& steps.message.outcome == 'success'
&& (!github.event.inputs.test_release || github.event.inputs.test_release == 'false') }}
uses: ncipollo/release-action@v1
with:
body: ${{ env.MESSAGE }}
token: ${{ secrets.COVALENT_OPS_BOT_TOKEN }}
tag: ${{ env.RELEASE }}
prerelease: ${{ inputs.prerelease }}

pypi:
runs-on: ubuntu-latest
steps:
- name: Check out release tag
uses: actions/checkout@v2
if: github.event.inputs.stable_version
with:
persist-credentials: false
fetch-depth: 0
ref: "v${{ github.event.inputs.stable_version }}"

- name: Check out master
uses: actions/checkout@v2
if: inputs.prerelease
with:
persist-credentials: false
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Build Prerelease Distribution
if: inputs.prerelease
id: pre-build
run: python setup.py egg_info --tag-build=pre sdist

- name: Build Stable Distribution
if: >
github.event.inputs.stable_version
&& contains(env.PAUL_BLART, github.actor)
id: stable-build
run: python setup.py sdist

- name: Validate Distribution
id: validate
run: |
VERSION="$(cat ./VERSION)"
if [ -z ${{ inputs.prerelease }} ] && \
[ -z ${{ github.event.inputs.stable_version }} ] ; then
echo "You can't create a stable release without specifying the stable version number."
exit 1
fi
if ${{ inputs.prerelease == true }} ; then
VERSION="${VERSION}rc0"
fi
VERSION="$(echo $VERSION | sed 's/-/.post/')"
cd dist
tar xzf covalent-ecs-plugin-${VERSION}.tar.gz
diff -r covalent-ecs-plugin-${VERSION}/covalent_ecs_plugin ../covalent_ecs_plugin
rm -rf covalent-ecs-plugin-${VERSION}/
- name: Upload Distribution
if: >
steps.pre-build.outcome == 'success'
|| steps.stable-build.outcome == 'success'
&& steps.validate.outcome == 'success'
&& ${{ !github.event.inputs.test_release }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
Loading

0 comments on commit fe6c363

Please sign in to comment.