From fe6c3634a73a505e52ad2f1ae048cc17e71171d0 Mon Sep 17 00:00:00 2001 From: Will Cunningham Date: Fri, 12 Aug 2022 16:52:03 -0400 Subject: [PATCH] preparing for release (#13) * preparing for release * added changelog --- .github/workflows/changelog.yml | 102 ++++++++++ .github/workflows/changelog_reminder.yml | 40 ++++ .github/workflows/release.yml | 187 ++++++++++++++++++ .github/workflows/tests.yml | 60 ++++-- .github/workflows/version.yml | 77 ++++++++ CHANGELOG.md | 10 + README.md | 2 +- VERSION | 2 +- .../aws_ecs_readme_banner.jpg | Bin requirements.txt | 1 + setup.py | 2 +- 11 files changed, 468 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/changelog_reminder.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/version.yml rename {doc/source/_static => assets}/aws_ecs_readme_banner.jpg (100%) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..f376436 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -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: covalentopsbot@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..7619474 --- /dev/null +++ b/.github/workflows/changelog_reminder.yml @@ -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/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-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 }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..760c65f --- /dev/null +++ b/.github/workflows/release.yml @@ -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 "covalentopsbot@users.noreply.github.com" + 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<> $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/* diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed9da3b..7fcae43 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,9 +22,9 @@ name: tests on: pull_request: - push: - branches: - - develop + workflow_run: + workflows: [changelog] + types: [completed] jobs: tests: @@ -71,22 +71,58 @@ jobs: pip install --no-cache-dir -r requirements.txt pip install --no-cache-dir -r tests/requirements.txt - - name: Build distribution - run: python setup.py sdist - - name: Install Covalent run: pip install covalent --pre + - name: Build distribution + run: python setup.py sdist + + - name: Validate plugin + run: | + VERSION="$(cat ./VERSION)" + 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}/ + cd .. + + - name: Install ECS plugin + run: | + VERSION="$(cat ./VERSION)" + pip install ./dist/covalent-ecs-plugin-${VERSION}.tar.gz + - name: Run tests - run: PYTHONPATH=$PWD/ pytest tests/ -vv + run: PYTHONPATH=$PWD/tests pytest -vv tests/ + + - name: Get latest release + uses: actions-ecosystem/action-get-latest-tag@v1 + id: get-latest-tag + if: github.ref == 'refs/heads/develop' && matrix.os == 'ubuntu-latest' && matrix.container == 'python:3.8-buster' + with: + semver_only: true - name: Push to main - id: push if: github.ref == 'refs/heads/develop' && matrix.os == 'ubuntu-latest' && matrix.container == 'python:3.8-buster' run: | + MASTER_VERSION="$(echo ${{ steps.get-latest-tag.outputs.tag }} | cut -c2- )" VERSION="$(cat ./VERSION)" release=false - git config user.name "CovalentOpsBot" - git config user.email "covalentopsbot@users.noreply.github.com" - git remote set-url origin https://${{ secrets.COVALENT_OPS_BOT_TOKEN }}@github.com/AgnostiqHQ/covalent-ecs-plugin.git - git push origin HEAD:main + if [ "$MASTER_VERSION" = "$VERSION" ] ; then + echo "$VERSION has been previously released." + else + git config user.name "CovalentOpsBot" + git config user.email "covalentopsbot@users.noreply.github.com" + git remote set-url origin https://${{ secrets.COVALENT_OPS_BOT_TOKEN }}@github.com/AgnostiqHQ/covalent-ecs-plugin.git + git push origin HEAD:main + fi + echo "RELEASE=$release" >> $GITHUB_ENV + echo "::set-output name=release::$release" + + release: + needs: tests + if: github.ref == 'refs/heads/develop' && needs.tests.outputs.release == 'true' + uses: AgnostiqHQ/covalent-ecs-plugin/.github/workflows/release.yml@develop + secrets: inherit + with: + prerelease: true + diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..51d005b --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,77 @@ +# 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: 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 index 3d398d0..561fc02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ 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). +## [UNRELEASED] + +### Added + +- Workflow actions to support releases + +### Changed + +- Changed from alpha to beta + ## [0.4.0] - 2022-08-09 ### Changed diff --git a/README.md b/README.md index ebce69a..d778075 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@
- +
diff --git a/VERSION b/VERSION index 6e8bf73..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.4.0 diff --git a/doc/source/_static/aws_ecs_readme_banner.jpg b/assets/aws_ecs_readme_banner.jpg similarity index 100% rename from doc/source/_static/aws_ecs_readme_banner.jpg rename to assets/aws_ecs_readme_banner.jpg diff --git a/requirements.txt b/requirements.txt index a233711..c75acfe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ boto3==1.20.48 +covalent docker==5.0.3 diff --git a/setup.py b/setup.py index e16e5ac..6cfde73 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ "include_package_data": True, "install_requires": required, "classifiers": [ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "Environment :: Plugins", "Intended Audience :: Developers",