|
| 1 | +name: "Release" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + type: string |
| 8 | + description: "Version number to release (e.g., 1.2.3, 1.2.3-rc1, 1.2.0)" |
| 9 | + required: true |
| 10 | + |
| 11 | +permissions: write-all |
| 12 | + |
| 13 | +jobs: |
| 14 | + safety_check: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + environment: release |
| 17 | + steps: |
| 18 | + - name: "Security Check" |
| 19 | + uses: Aiko-IT-Systems/[email protected] |
| 20 | + with: |
| 21 | + whitelisted-github-ids: ${{ vars.ALLOWED_USER_IDS }} |
| 22 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + |
| 24 | + pre_config: |
| 25 | + needs: [safety_check] |
| 26 | + outputs: |
| 27 | + branch_name: ${{ steps.determine_vars.outputs.branch_name }} |
| 28 | + is_rc: ${{ steps.determine_vars.outputs.is_rc }} |
| 29 | + version: ${{ steps.determine_vars.outputs.version }} |
| 30 | + previous_tag: ${{ steps.determine_vars.outputs.previous_tag }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: "Checkout Repository" |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + fetch-tags: true |
| 38 | + |
| 39 | + - name: "Determine Push Branch" |
| 40 | + id: determine_vars |
| 41 | + env: |
| 42 | + VERSION: ${{ github.event.inputs.version }} |
| 43 | + run: | |
| 44 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^) |
| 46 | + echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT |
| 47 | + if [[ $VERSION =~ -rc ]]; then |
| 48 | + MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+') |
| 49 | + echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT |
| 50 | + echo "is_rc=true" >> $GITHUB_OUTPUT |
| 51 | + elif [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 52 | + MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+') |
| 53 | + echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT |
| 54 | + echo "is_rc=false" >> $GITHUB_OUTPUT |
| 55 | + else |
| 56 | + MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+') |
| 57 | + echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT |
| 58 | + echo "is_rc=false" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | +
|
| 61 | + lib_release: |
| 62 | + needs: [safety_check,pre_config] |
| 63 | + runs-on: ubuntu-latest |
| 64 | + environment: release |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + steps: |
| 68 | + - name: "Checkout Repository" |
| 69 | + uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + fetch-tags: true |
| 73 | + |
| 74 | + - name: "Release Pycord" |
| 75 | + id: pycord-release |
| 76 | + uses: Aiko-IT-Systems/[email protected] |
| 77 | + with: |
| 78 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + pypi-token: ${{ secrets.PYPI_TOKEN }} |
| 80 | + version-branch-name: ${{ needs.pre_config.outputs.branch_name }} |
| 81 | + ref: ${{ github.ref_name }} |
| 82 | + repository: ${{ github.repository }} |
| 83 | + python-version: "3.12" |
| 84 | + release-requirements: "requirements/_release.txt" |
| 85 | + version: ${{ needs.pre_config.outputs.version }} |
| 86 | + is-rc: ${{ needs.pre_config.outputs.is_rc }} |
| 87 | + pypi-package: "py-cord" |
| 88 | + |
| 89 | + - name: "Echo release url" |
| 90 | + run: echo "${{ steps.pycord-release.outputs.gh-release }}" |
| 91 | + |
| 92 | + docs_release: |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: [lib_release,pre_config] |
| 95 | + if: needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc == 'true' && endsWith(needs.pre_config.outputs.version, '.0-rc1')) |
| 96 | + environment: release |
| 97 | + steps: |
| 98 | + - name: "Sync Versions on Read the Docs" |
| 99 | + run: | |
| 100 | + curl --location --request POST 'https://readthedocs.org/api/v3/projects/pycord/sync-versions/' \ |
| 101 | + --header 'Content-Type: application/json' \ |
| 102 | + --header "Authorization: Token ${{ secrets.READTHEDOCS_TOKEN }}" |
| 103 | +
|
| 104 | + - name: "Activate and Show Version on Read the Docs" |
| 105 | + run: | |
| 106 | + VERSION=${{ needs.pre_config.outputs.version }} |
| 107 | + MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+') |
| 108 | + PATCH_VERSION=${VERSION##*.} |
| 109 | + if [[ $PATCH_VERSION =~ ^[0-9]+$ ]]; then |
| 110 | + DOCS_VERSION="v$VERSION" |
| 111 | + else |
| 112 | + DOCS_VERSION="v$MAJOR_MINOR_VERSION.x" |
| 113 | + fi |
| 114 | + curl --location --request PATCH "https://readthedocs.org/api/v3/projects/pycord/versions/$DOCS_VERSION/" \ |
| 115 | + --header 'Content-Type: application/json' \ |
| 116 | + --header "Authorization: Token ${{ secrets.READTHEDOCS_TOKEN }}" \ |
| 117 | + --data '{ |
| 118 | + "active": true, |
| 119 | + "hidden": false |
| 120 | + }' |
| 121 | +
|
| 122 | + inform_discord: |
| 123 | + runs-on: ubuntu-latest |
| 124 | + needs: [lib_release,docs_release,close_milestone,pre_config] |
| 125 | + environment: release |
| 126 | + steps: |
| 127 | + - name: "Notify Discord" |
| 128 | + run: | |
| 129 | + VERSION=${{ needs.pre_config.outputs.version }} |
| 130 | + MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+') |
| 131 | + DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>" |
| 132 | + GITHUB_COMPARE_URL="<https://github.com/Pycord-Development/pycord/compare/${{ needs.pre_config.outputs.previous_tag }}...v$VERSION>" |
| 133 | + GITHUB_RELEASE_URL="<https://github.com/Pycord-Development/pycord/releases/tag/v$VERSION>" |
| 134 | + PYPI_RELEASE_URL="<https://pypi.org/project/py-cord/$VERSION/>" |
| 135 | + ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} is out!\n\n" |
| 136 | + ANNOUNCEMENT="${ANNOUNCEMENT}[@everyone]\n\n" |
| 137 | + ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n" |
| 138 | + ANNOUNCEMENT="${ANNOUNCEMENT}Feel free to take a look at the [GitHub changelog]($GITHUB_COMPARE_URL), [GitHub release page]($GITHUB_RELEASE_URL) and the [PyPI release page]($PYPI_RELEASE_URL).\n\n" |
| 139 | + ANNOUNCEMENT="${ANNOUNCEMENT}You can install this version by running the following command:\n\`\`\`sh\npip install -U py-cord==$VERSION\n\`\`\`\n\n" |
| 140 | + curl -H "Content-Type: application/json" \ |
| 141 | + -X POST \ |
| 142 | + -d "{\"content\":\"$ANNOUNCEMENT\"}" \ |
| 143 | + ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 144 | +
|
| 145 | + determine_milestone_id: |
| 146 | + runs-on: ubuntu-latest |
| 147 | + needs: [lib_release,pre_config] |
| 148 | + if: ${{ !contains(needs.pre_config.outputs.version, '-') && endsWith(needs.pre_config.outputs.version, '.0') }} |
| 149 | + outputs: |
| 150 | + old_milestone_version: ${{ steps.extract_version.outputs.old_milestone_version }} |
| 151 | + new_milestone_version: ${{ steps.extract_version.outputs.new_milestone_version }} |
| 152 | + env: |
| 153 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 154 | + environment: release |
| 155 | + steps: |
| 156 | + - name: "Extract Milestone Version" |
| 157 | + id: extract_version |
| 158 | + run: | |
| 159 | + gh extension install valeriobelli/gh-milestone |
| 160 | + VERSION=${{ needs.pre_config.outputs.version }} |
| 161 | + OLD_MILESTONE_VERSION=$(gh milestone list --query "v2.7" | grep "#" | awk '{print $2}') |
| 162 | + NEW_MILESTONE_VERSION="v$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')" |
| 163 | + echo "old_milestone_version=$OLD_MILESTONE_VERSION" >> $GITHUB_OUTPUT |
| 164 | + echo "new_milestone_version=$NEW_MILESTONE_VERSION" >> $GITHUB_OUTPUT |
| 165 | +
|
| 166 | + close_milestone: |
| 167 | + runs-on: ubuntu-latest |
| 168 | + needs: [determine_milestone_id,pre_config] |
| 169 | + if: ${{ !contains(needs.pre_config.outputs.version, '-') && endsWith(needs.pre_config.outputs.version, '.0') }} |
| 170 | + environment: release |
| 171 | + env: |
| 172 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + steps: |
| 174 | + - name: "Checkout Repository" |
| 175 | + uses: actions/checkout@v4 |
| 176 | + with: |
| 177 | + fetch-depth: 0 |
| 178 | + fetch-tags: true |
| 179 | + |
| 180 | + - name: "Close Milestone" |
| 181 | + run: | |
| 182 | + gh extension install valeriobelli/gh-milestone |
| 183 | + OLD_MILESTONE_ID=$(gh milestone list --query "${{ needs.determine_milestone_id.outputs.old_milestone_version }}" | grep "#" | cut -d' ' -f2 | cut -d '#' -f2) |
| 184 | + gh milestone edit $OLD_MILESTONE_ID --state closed |
| 185 | +
|
| 186 | + - name: "Create New Milestone" |
| 187 | + run: | |
| 188 | + gh extension install valeriobelli/gh-milestone |
| 189 | + gh milestone create "${{ needs.determine_milestone_id.outputs.new_milestone_version }}" |
0 commit comments