|
| 1 | +--- |
| 2 | +# This action is centrally managed in https://github.com/<organization>/.github/ |
| 3 | +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in |
| 4 | +# the above-mentioned repo. |
| 5 | + |
| 6 | +# Use the `rtd` repository label to identify repositories that should trigger have this workflow. |
| 7 | +# If the project slug is not the repository name, add a repository variable named `READTHEDOCS_SLUG` with the value of |
| 8 | +# the ReadTheDocs project slug. |
| 9 | + |
| 10 | +# Update readthedocs on release events. |
| 11 | + |
| 12 | +name: Update docs |
| 13 | + |
| 14 | +on: |
| 15 | + release: |
| 16 | + types: [created, edited, deleted] |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: "${{ github.workflow }}-${{ github.event.release.tag_name }}" |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + update-docs: |
| 24 | + env: |
| 25 | + RTD_SLUG: ${{ vars.READTHEDOCS_SLUG }} |
| 26 | + RTD_TOKEN: ${{ secrets.READTHEDOCS_TOKEN }} |
| 27 | + TAG: ${{ github.event.release.tag_name }} |
| 28 | + if: >- |
| 29 | + !github.event.release.draft |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Get RTD_SLUG |
| 33 | + run: | |
| 34 | + # if the RTD_SLUG is not set, use the repository name in lowercase |
| 35 | + if [ -z "${RTD_SLUG}" ]; then |
| 36 | + RTD_SLUG=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]') |
| 37 | + fi |
| 38 | + echo "RTD_SLUG=${RTD_SLUG}" >> $GITHUB_ENV |
| 39 | +
|
| 40 | + - name: Deactivate deleted release |
| 41 | + if: >- |
| 42 | + github.event_name == 'release' && |
| 43 | + github.event.action == 'deleted' |
| 44 | + run: | |
| 45 | + json_body=$(jq -n \ |
| 46 | + --arg active "false" \ |
| 47 | + --arg hidden "false" \ |
| 48 | + --arg privacy_level "public" \ |
| 49 | + '{active: $active, hidden: $hidden, privacy_level: $privacy_level}') |
| 50 | +
|
| 51 | + curl \ |
| 52 | + -X PATCH \ |
| 53 | + -H "Authorization: Token ${RTD_TOKEN}" \ |
| 54 | + https://readthedocs.org/api/v3/projects/${RTD_SLUG}/versions/${TAG}/ \ |
| 55 | + -H "Content-Type: application/json" \ |
| 56 | + -d "$json_body" |
| 57 | +
|
| 58 | + - name: Check if edited release is latest GitHub release |
| 59 | + id: check |
| 60 | + if: >- |
| 61 | + github.event_name == 'release' && |
| 62 | + github.event.action == 'edited' |
| 63 | + uses: actions/github-script@v7 |
| 64 | + with: |
| 65 | + script: | |
| 66 | + const latestRelease = await github.rest.repos.getLatestRelease({ |
| 67 | + owner: context.repo.owner, |
| 68 | + repo: context.repo.repo |
| 69 | + }); |
| 70 | +
|
| 71 | + core.setOutput('isLatestRelease', latestRelease.data.tag_name === context.payload.release.tag_name); |
| 72 | +
|
| 73 | + - name: Update RTD project |
| 74 | + # changing the default branch in readthedocs makes "latest" point to that branch/tag |
| 75 | + # we can also update other properties like description, etc. |
| 76 | + if: >- |
| 77 | + steps.check.outputs.isLatestRelease == 'true' |
| 78 | + run: | |
| 79 | + json_body=$(jq -n \ |
| 80 | + --arg default_branch "${TAG}" \ |
| 81 | + --arg description "${{ github.event.repository.description }}" \ |
| 82 | + '{default_branch: $default_branch}') |
| 83 | +
|
| 84 | + # change the default branch to the latest release |
| 85 | + curl \ |
| 86 | + -X PATCH \ |
| 87 | + -H "Authorization: Token ${RTD_TOKEN}" \ |
| 88 | + -H "Content-Type: application/json" \ |
| 89 | + https://readthedocs.org/api/v3/projects/${RTD_SLUG}/ \ |
| 90 | + -d "$json_body" |
| 91 | +
|
| 92 | + # trigger a build for the latest version |
| 93 | + curl \ |
| 94 | + -X POST \ |
| 95 | + -H "Authorization: Token ${RTD_TOKEN}" \ |
| 96 | + https://readthedocs.org/api/v3/projects/${RTD_SLUG}/versions/latest/builds/ |
0 commit comments