|
| 1 | +# Adapted from https://github.com/DisnakeDev/disnake/blob/master/.github/workflows/release.yaml |
| 2 | + |
| 3 | +name: Release |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Builds sdist and wheel, runs `twine check`, and uploads artifacts. |
| 15 | + build: |
| 16 | + name: Build package |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Bootstrap disnake-compass |
| 23 | + uses: ./.github/actions/bootstrap |
| 24 | + with: |
| 25 | + python-version: '3.10' |
| 26 | + |
| 27 | + - name: Build package |
| 28 | + run: | |
| 29 | + poetry build |
| 30 | + ls -la dist/ |
| 31 | +
|
| 32 | + - name: Twine check |
| 33 | + run: poetry run twine check --strict dist/* |
| 34 | + |
| 35 | + - name: Show metadata |
| 36 | + run: | |
| 37 | + mkdir out/ |
| 38 | + tar -xf dist/*.tar.gz -C out/ |
| 39 | +
|
| 40 | + echo -e "<details><summary>Metadata</summary>\n" >> $GITHUB_STEP_SUMMARY |
| 41 | + cat out/*/PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY |
| 42 | + echo -e "\n</details>\n" >> $GITHUB_STEP_SUMMARY |
| 43 | +
|
| 44 | + - name: Upload artifact |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: dist |
| 48 | + path: dist/ |
| 49 | + if-no-files-found: error |
| 50 | + |
| 51 | + |
| 52 | + # Ensures that git tag and built version match. |
| 53 | + validate-tag: |
| 54 | + name: Validate tag |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: |
| 57 | + - build |
| 58 | + env: |
| 59 | + GIT_TAG: ${{ github.ref_name }} |
| 60 | + outputs: |
| 61 | + bump_dev: ${{ steps.check-dev.outputs.bump_dev }} |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Download build artifact |
| 65 | + uses: actions/download-artifact@v4 |
| 66 | + with: |
| 67 | + name: dist |
| 68 | + path: dist/ |
| 69 | + |
| 70 | + - name: Compare sdist version to git tag |
| 71 | + run: | |
| 72 | + mkdir out/ |
| 73 | + tar -xf dist/*.tar.gz -C out/ |
| 74 | +
|
| 75 | + SDIST_VERSION="$(grep "^Version:" out/*/PKG-INFO | cut -d' ' -f2-)" |
| 76 | + echo "git tag: $GIT_TAG" |
| 77 | + echo "sdist version: $SDIST_VERSION" |
| 78 | +
|
| 79 | + if [ "$GIT_TAG" != "v$SDIST_VERSION" ]; then |
| 80 | + echo "error: git tag does not match sdist version" >&2 |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Determine if dev version PR is needed |
| 85 | + id: check-dev |
| 86 | + run: | |
| 87 | + BUMP_DEV= |
| 88 | + # if this is a new major/minor version, create a PR later |
| 89 | + if [[ "$GIT_TAG" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then |
| 90 | + BUMP_DEV=1 |
| 91 | + fi |
| 92 | + echo "bump_dev=$BUMP_DEV" | tee -a $GITHUB_OUTPUT |
| 93 | +
|
| 94 | +
|
| 95 | + # Creates a draft release on GitHub, and uploads the artifacts there. |
| 96 | + release-github: |
| 97 | + name: Create GitHub draft release |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: |
| 100 | + - build |
| 101 | + - validate-tag |
| 102 | + permissions: |
| 103 | + contents: write # required for creating releases |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Download build artifact |
| 107 | + uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + name: dist |
| 110 | + path: dist/ |
| 111 | + |
| 112 | + - name: Calculate versions |
| 113 | + id: versions |
| 114 | + env: |
| 115 | + GIT_TAG: ${{ github.ref_name }} |
| 116 | + run: | |
| 117 | + # v1.2.3 -> v1-2-3 (for changelog) |
| 118 | + echo "docs_version=${GIT_TAG//./-}" >> $GITHUB_OUTPUT |
| 119 | +
|
| 120 | + - name: Create Release |
| 121 | + uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 |
| 122 | + with: |
| 123 | + files: dist/* |
| 124 | + draft: true |
| 125 | + body: | |
| 126 | + TBD. |
| 127 | +
|
| 128 | + **Changelog**: https://docs.disnake.dev/en/stable/whats_new.html#${{ steps.versions.outputs.docs_version }} |
| 129 | + **Git history**: https://github.com/${{ github.repository }}/compare/vTODO...${{ github.ref_name }} |
| 130 | +
|
| 131 | +
|
| 132 | + # Creates a PyPI release (using an environment which requires separate confirmation). |
| 133 | + release-pypi: |
| 134 | + name: Publish package to pypi.org |
| 135 | + environment: |
| 136 | + name: release-pypi |
| 137 | + url: https://pypi.org/project/disnake/ |
| 138 | + runs-on: ubuntu-latest |
| 139 | + needs: |
| 140 | + - build |
| 141 | + - validate-tag |
| 142 | + permissions: |
| 143 | + id-token: write # this permission is mandatory for trusted publishing |
| 144 | + |
| 145 | + steps: |
| 146 | + - name: Download build artifact |
| 147 | + uses: actions/download-artifact@v4 |
| 148 | + with: |
| 149 | + name: dist |
| 150 | + path: dist/ |
| 151 | + |
| 152 | + - name: Upload to pypi |
| 153 | + uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450 # v1.8.14 |
| 154 | + with: |
| 155 | + print-hash: true |
| 156 | + |
| 157 | + |
| 158 | + # Creates a PR to bump to an alpha version for development, if applicable. |
| 159 | + create-dev-version-pr: |
| 160 | + name: Create dev version bump PR |
| 161 | + runs-on: ubuntu-latest |
| 162 | + if: needs.validate-tag.outputs.bump_dev |
| 163 | + needs: |
| 164 | + - validate-tag |
| 165 | + - release-github |
| 166 | + - release-pypi |
| 167 | + |
| 168 | + steps: |
| 169 | + # https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow |
| 170 | + - name: Generate app token |
| 171 | + id: generate_token |
| 172 | + uses: actions/create-github-app-token@f2acddfb5195534d487896a656232b016a682f3c # v1.9.0 |
| 173 | + with: |
| 174 | + app-id: ${{ secrets.BOT_APP_ID }} |
| 175 | + private-key: ${{ secrets.BOT_PRIVATE_KEY }} |
| 176 | + |
| 177 | + - uses: actions/checkout@v4 |
| 178 | + with: |
| 179 | + token: ${{ steps.generate_token.outputs.token }} |
| 180 | + persist-credentials: false |
| 181 | + ref: master # the PR action wants a proper base branch |
| 182 | + |
| 183 | + - name: Set git name/email |
| 184 | + env: |
| 185 | + GIT_USER: ${{ vars.GIT_APP_USER_NAME }} |
| 186 | + GIT_EMAIL: ${{ vars.GIT_APP_USER_EMAIL }} |
| 187 | + run: | |
| 188 | + git config user.name "$GIT_USER" |
| 189 | + git config user.email "$GIT_EMAIL" |
| 190 | +
|
| 191 | + - name: Update version to dev |
| 192 | + id: update-version |
| 193 | + run: | |
| 194 | + NEW_VERSION="$(poetry run python scripts/versiontool.py --set dev)" |
| 195 | + git commit -a -m "chore: update version to v$NEW_VERSION" |
| 196 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 197 | +
|
| 198 | + - name: Create pull request |
| 199 | + uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e # v6.0.2 |
| 200 | + with: |
| 201 | + token: ${{ steps.generate_token.outputs.token }} |
| 202 | + branch: auto/dev-v${{ steps.update-version.outputs.new_version }} |
| 203 | + delete-branch: true |
| 204 | + base: master |
| 205 | + title: "chore: update version to v${{ steps.update-version.outputs.new_version }}" |
| 206 | + body: | |
| 207 | + Automated dev version PR. |
| 208 | +
|
| 209 | + <sub>https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}</sub> |
| 210 | + labels: | |
| 211 | + skip news |
0 commit comments