|
| 1 | +# Copyright 2021 Agnostiq Inc. |
| 2 | +# |
| 3 | +# This file is part of Covalent. |
| 4 | +# |
| 5 | +# Licensed under the GNU Affero General Public License 3.0 (the "License"). |
| 6 | +# A copy of the License may be obtained with this software package or at |
| 7 | +# |
| 8 | +# https://www.gnu.org/licenses/agpl-3.0.en.html |
| 9 | +# |
| 10 | +# Use of this file is prohibited except in compliance with the License. Any |
| 11 | +# modifications or derivative works of this file must retain this copyright |
| 12 | +# notice, and modified files must contain a notice indicating that they have |
| 13 | +# been altered from the originals. |
| 14 | +# |
| 15 | +# Covalent is distributed in the hope that it will be useful, but WITHOUT |
| 16 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE. See the License for more details. |
| 18 | +# |
| 19 | +# Relief from the License may be granted by purchasing a commercial license. |
| 20 | + |
| 21 | +name: release |
| 22 | + |
| 23 | +on: |
| 24 | + workflow_dispatch: |
| 25 | + inputs: |
| 26 | + stable_version: |
| 27 | + description: "Stable version number, e.g. 0.32.3" |
| 28 | + type: string |
| 29 | + test_release: |
| 30 | + description: "Test the workflow but don't create the release. Uncheck this box to create a release." |
| 31 | + required: true |
| 32 | + type: boolean |
| 33 | + default: true |
| 34 | + workflow_call: |
| 35 | + inputs: |
| 36 | + prerelease: |
| 37 | + description: "true: Create a prerelease. false: Create a stable release" |
| 38 | + required: true |
| 39 | + type: boolean |
| 40 | + default: true |
| 41 | + |
| 42 | + |
| 43 | +env: |
| 44 | + PAUL_BLART: > |
| 45 | + '[' |
| 46 | + '"scottwn",' |
| 47 | + '"FyzHsn",' |
| 48 | + '"wjcunningham7",' |
| 49 | + '"santoshkumarradha"]' |
| 50 | +
|
| 51 | +jobs: |
| 52 | + github: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - name: Check out release tag |
| 56 | + uses: actions/checkout@v2 |
| 57 | + if: github.event.inputs.stable_version |
| 58 | + with: |
| 59 | + persist-credentials: false |
| 60 | + fetch-depth: 0 |
| 61 | + ref: "v${{ github.event.inputs.stable_version }}" |
| 62 | + |
| 63 | + - name: Check out master |
| 64 | + uses: actions/checkout@v2 |
| 65 | + if: inputs.prerelease |
| 66 | + with: |
| 67 | + persist-credentials: false |
| 68 | + fetch-depth: 0 |
| 69 | + |
| 70 | + - name: Read version |
| 71 | + run: | |
| 72 | + if [ -z ${{ inputs.prerelease }} ] && \ |
| 73 | + [ -z ${{ github.event.inputs.stable_version }} ] ; then |
| 74 | + echo "You can't create a stable release without specifying the stable version number." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + VERSION="$(cat ./VERSION)" |
| 78 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 79 | + echo "RELEASE=v$VERSION" >> $GITHUB_ENV |
| 80 | +
|
| 81 | + - name: Tag commit |
| 82 | + if: inputs.prerelease |
| 83 | + id: push |
| 84 | + run: | |
| 85 | + git config user.name "CovalentOpsBot" |
| 86 | + git config user.email "[email protected]" |
| 87 | + git tag -a $RELEASE -m "Release $RELEASE" |
| 88 | + git remote set-url origin https://${{ secrets.COVALENT_OPS_BOT_TOKEN }}@github.com/AgnostiqHQ/covalent-ecs-plugin.git |
| 89 | + git push origin $RELEASE |
| 90 | +
|
| 91 | + - name: Check conditions for stable release |
| 92 | + if: > |
| 93 | + github.event.inputs.stable_version |
| 94 | + && contains(env.PAUL_BLART, github.actor) |
| 95 | + id: no-push |
| 96 | + run: echo "Stable release for version ${{ github.event.inputs.stable_version }}" |
| 97 | + |
| 98 | + - name: Generate release message |
| 99 | + id: message |
| 100 | + run: | |
| 101 | + begin=$(grep -n "\b${VERSION}\b" ./CHANGELOG.md | cut -d ':' -f 1) |
| 102 | + previous_version=$(git describe --abbrev=0 $RELEASE^ | cut -c2-) |
| 103 | + end=$(tail -n +$((begin+1)) ./CHANGELOG.md | grep -n -m 1 "\b${previous_version}\b" | cut -d ':' -f 1) |
| 104 | + echo 'MESSAGE<<EOF' >> $GITHUB_ENV |
| 105 | + tail +$begin ./CHANGELOG.md | head -$end >> $GITHUB_ENV |
| 106 | + echo 'EOF' >> $GITHUB_ENV |
| 107 | +
|
| 108 | + - name: Create release |
| 109 | + if: >- |
| 110 | + ${{ (steps.push.outcome == 'success' || steps.no-push.outcome == 'success') |
| 111 | + && steps.message.outcome == 'success' |
| 112 | + && (!github.event.inputs.test_release || github.event.inputs.test_release == 'false') }} |
| 113 | + uses: ncipollo/release-action@v1 |
| 114 | + with: |
| 115 | + body: ${{ env.MESSAGE }} |
| 116 | + token: ${{ secrets.COVALENT_OPS_BOT_TOKEN }} |
| 117 | + tag: ${{ env.RELEASE }} |
| 118 | + prerelease: ${{ inputs.prerelease }} |
| 119 | + |
| 120 | + pypi: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Check out release tag |
| 124 | + uses: actions/checkout@v2 |
| 125 | + if: github.event.inputs.stable_version |
| 126 | + with: |
| 127 | + persist-credentials: false |
| 128 | + fetch-depth: 0 |
| 129 | + ref: "v${{ github.event.inputs.stable_version }}" |
| 130 | + |
| 131 | + - name: Check out master |
| 132 | + uses: actions/checkout@v2 |
| 133 | + if: inputs.prerelease |
| 134 | + with: |
| 135 | + persist-credentials: false |
| 136 | + fetch-depth: 0 |
| 137 | + |
| 138 | + - name: Set up Python |
| 139 | + uses: actions/setup-python@v2 |
| 140 | + with: |
| 141 | + python-version: 3.8 |
| 142 | + |
| 143 | + - name: Install Python dependencies |
| 144 | + run: | |
| 145 | + python -m pip install --upgrade pip |
| 146 | + pip install twine |
| 147 | +
|
| 148 | + - name: Build Prerelease Distribution |
| 149 | + if: inputs.prerelease |
| 150 | + id: pre-build |
| 151 | + run: python setup.py egg_info --tag-build=pre sdist |
| 152 | + |
| 153 | + - name: Build Stable Distribution |
| 154 | + if: > |
| 155 | + github.event.inputs.stable_version |
| 156 | + && contains(env.PAUL_BLART, github.actor) |
| 157 | + id: stable-build |
| 158 | + run: python setup.py sdist |
| 159 | + |
| 160 | + - name: Validate Distribution |
| 161 | + id: validate |
| 162 | + run: | |
| 163 | + VERSION="$(cat ./VERSION)" |
| 164 | + if [ -z ${{ inputs.prerelease }} ] && \ |
| 165 | + [ -z ${{ github.event.inputs.stable_version }} ] ; then |
| 166 | + echo "You can't create a stable release without specifying the stable version number." |
| 167 | + exit 1 |
| 168 | + fi |
| 169 | + if ${{ inputs.prerelease == true }} ; then |
| 170 | + VERSION="${VERSION}rc0" |
| 171 | + fi |
| 172 | + VERSION="$(echo $VERSION | sed 's/-/.post/')" |
| 173 | + cd dist |
| 174 | + tar xzf covalent-ecs-plugin-${VERSION}.tar.gz |
| 175 | + diff -r covalent-ecs-plugin-${VERSION}/covalent_ecs_plugin ../covalent_ecs_plugin |
| 176 | + rm -rf covalent-ecs-plugin-${VERSION}/ |
| 177 | +
|
| 178 | + - name: Upload Distribution |
| 179 | + if: > |
| 180 | + steps.pre-build.outcome == 'success' |
| 181 | + || steps.stable-build.outcome == 'success' |
| 182 | + && steps.validate.outcome == 'success' |
| 183 | + && ${{ !github.event.inputs.test_release }} |
| 184 | + env: |
| 185 | + TWINE_USERNAME: __token__ |
| 186 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 187 | + run: twine upload dist/* |
0 commit comments