|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - v[0-9]+.[0-9]+.[0-9]+* |
| 7 | + release: |
| 8 | + types: |
| 9 | + - published |
| 10 | +jobs: |
| 11 | + prep: |
| 12 | + name: Prepare release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: ${{ github.event_name == 'push' && github.ref_name != 'main' }} |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + steps: |
| 22 | + |
| 23 | + - name: Checkout release branch |
| 24 | + uses: actions/checkout@v3 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup Python |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: 3.8 |
| 32 | + cache: 'pip' |
| 33 | + cache-dependency-path: pyproject.toml |
| 34 | + |
| 35 | + - name: Install Python dependencies |
| 36 | + run: | |
| 37 | + pip install --upgrade pip |
| 38 | + pip install build twine |
| 39 | + pip install . |
| 40 | + pip install ".[lint, test]" |
| 41 | +
|
| 42 | + - name: Update version |
| 43 | + id: version |
| 44 | + run: | |
| 45 | + ref="${{ github.ref_name }}" |
| 46 | + version="${ref#"v"}" |
| 47 | + python scripts/update_version.py -v "$version" |
| 48 | + python -c "import modflowapi; print('Version: ', modflowapi.__version__)" |
| 49 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + - name: Touch changelog |
| 52 | + run: touch HISTORY.md |
| 53 | + |
| 54 | + - name: Generate changelog |
| 55 | + id: cliff |
| 56 | + uses: orhun/git-cliff-action@v1 |
| 57 | + with: |
| 58 | + config: cliff.toml |
| 59 | + args: --verbose --unreleased --tag ${{ steps.version.outputs.version }} |
| 60 | + env: |
| 61 | + OUTPUT: CHANGELOG.md |
| 62 | + |
| 63 | + - name: Update changelog |
| 64 | + run: | |
| 65 | + # substitute full group names |
| 66 | + sed -i 's/#### Ci/#### Continuous integration/' CHANGELOG.md |
| 67 | + sed -i 's/#### Feat/#### New features/' CHANGELOG.md |
| 68 | + sed -i 's/#### Fix/#### Bug fixes/' CHANGELOG.md |
| 69 | + sed -i 's/#### Refactor/#### Refactoring/' CHANGELOG.md |
| 70 | + sed -i 's/#### Test/#### Testing/' CHANGELOG.md |
| 71 | + |
| 72 | + # prepend release changelog to cumulative changelog |
| 73 | + clog="HISTORY.md" |
| 74 | + temp="temp.md" |
| 75 | + echo "$(tail -n +2 $clog)" > $clog |
| 76 | + cat CHANGELOG.md $clog > $temp |
| 77 | + sudo mv $temp $clog |
| 78 | + sed -i '1i # Changelog' $clog |
| 79 | +
|
| 80 | + - name: Upload changelog |
| 81 | + uses: actions/upload-artifact@v3 |
| 82 | + with: |
| 83 | + name: changelog |
| 84 | + path: CHANGELOG.md |
| 85 | + |
| 86 | + - name: Format Python files |
| 87 | + run: python scripts/pull_request_prepare.py |
| 88 | + |
| 89 | + - name: Push release branch |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ github.token }} |
| 92 | + run: | |
| 93 | + ver="${{ steps.version.outputs.version }}" |
| 94 | + changelog=$(cat CHANGELOG.md | grep -v "### Version $ver") |
| 95 | + |
| 96 | + # remove this release's changelog so we don't commit it |
| 97 | + # the changes have already been prepended to HISTORY.md |
| 98 | + rm -f CHANGELOG.md |
| 99 | + |
| 100 | + # commit and push changes |
| 101 | + git config core.sharedRepository true |
| 102 | + git config user.name "github-actions[bot]" |
| 103 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 104 | + git add -A |
| 105 | + git commit -m "ci(release): set version to ${{ steps.version.outputs.version }}, update changelog" |
| 106 | + git push origin "${{ github.ref_name }}" |
| 107 | +
|
| 108 | + title="Release $ver" |
| 109 | + body=' |
| 110 | + # Release '$ver' |
| 111 | + |
| 112 | + The release can be approved by merging this pull request into `main`. This will trigger jobs to publish the release to PyPI and reset `develop` from `main`, incrementing the minor version number. |
| 113 | + |
| 114 | + ## Changelog |
| 115 | + |
| 116 | + '$changelog' |
| 117 | + ' |
| 118 | + gh pr create -B "main" -H "${{ github.ref_name }}" --title "$title" --draft --body "$body" |
| 119 | +
|
| 120 | + release: |
| 121 | + name: Draft release |
| 122 | + # runs only when changes are merged to main |
| 123 | + if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} |
| 124 | + runs-on: ubuntu-latest |
| 125 | + permissions: |
| 126 | + contents: write |
| 127 | + pull-requests: write |
| 128 | + steps: |
| 129 | + |
| 130 | + - name: Checkout repo |
| 131 | + uses: actions/checkout@v3 |
| 132 | + with: |
| 133 | + ref: main |
| 134 | + |
| 135 | + - name: Setup Python |
| 136 | + uses: actions/setup-python@v4 |
| 137 | + with: |
| 138 | + python-version: 3.8 |
| 139 | + |
| 140 | + - name: Install Python dependencies |
| 141 | + run: | |
| 142 | + pip install --upgrade pip |
| 143 | + pip install . |
| 144 | + pip install ".[test]" |
| 145 | +
|
| 146 | + # actions/download-artifact won't look at previous workflow runs but we need to in order to get changelog |
| 147 | + - name: Download artifacts |
| 148 | + uses: dawidd6/action-download-artifact@v2 |
| 149 | + |
| 150 | + - name: Draft release |
| 151 | + env: |
| 152 | + GITHUB_TOKEN: ${{ github.token }} |
| 153 | + run: | |
| 154 | + version=$(python scripts/update_version.py -g) |
| 155 | + title="modflowapi $version" |
| 156 | + notes=$(cat "changelog/CHANGELOG.md" | grep -v "### Version $version") |
| 157 | + gh release create "$version" \ |
| 158 | + --target main \ |
| 159 | + --title "$title" \ |
| 160 | + --notes "$notes" \ |
| 161 | + --draft \ |
| 162 | + --latest |
| 163 | +
|
| 164 | + publish: |
| 165 | + name: Publish package |
| 166 | + # runs only after release is published (manually promoted from draft) |
| 167 | + if: github.event_name == 'release' && github.repository_owner == 'MODFLOW-USGS' |
| 168 | + runs-on: ubuntu-22.04 |
| 169 | + permissions: |
| 170 | + contents: write |
| 171 | + pull-requests: write |
| 172 | + id-token: write |
| 173 | + environment: # requires a 'release' environment in repo settings |
| 174 | + name: release |
| 175 | + url: https://pypi.org/p/modflowapi |
| 176 | + steps: |
| 177 | + |
| 178 | + - name: Checkout main branch |
| 179 | + uses: actions/checkout@v3 |
| 180 | + with: |
| 181 | + ref: main |
| 182 | + |
| 183 | + - name: Setup Python |
| 184 | + uses: actions/setup-python@v4 |
| 185 | + with: |
| 186 | + python-version: 3.8 |
| 187 | + |
| 188 | + - name: Install Python dependencies |
| 189 | + run: | |
| 190 | + pip install --upgrade pip |
| 191 | + pip install build twine |
| 192 | + pip install . |
| 193 | +
|
| 194 | + - name: Build package |
| 195 | + run: python -m build |
| 196 | + |
| 197 | + - name: Check package |
| 198 | + run: twine check --strict dist/* |
| 199 | + |
| 200 | + - name: Upload package |
| 201 | + uses: actions/upload-artifact@v4 |
| 202 | + with: |
| 203 | + name: dist |
| 204 | + path: dist |
| 205 | + |
| 206 | + - name: Publish to PyPI |
| 207 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments