|
| 1 | +name: Publish API Docs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pages: write |
| 12 | + id-token: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 16 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 17 | +concurrency: |
| 18 | + group: "api-docs" |
| 19 | + cancel-in-progress: false |
| 20 | + |
| 21 | +env: |
| 22 | + DESTINATION_BRANCH: docs/${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}/${{ github.sha }} |
| 23 | + REPOSITORY: ${{ github.event.repository.name }} |
| 24 | + REPO: ${{ github.event.repository.owner.name }}/${{ github.event.repository.name }} |
| 25 | + DISPLAY_NAME: Xenoglot |
| 26 | + |
| 27 | +jobs: |
| 28 | + synchronize-documentation: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + name: Synchronize Repository API Documentation |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + # Grants execute permission to gradle (safety step) |
| 35 | + - name: Grant Permissions to gradlew |
| 36 | + run: chmod +x gradlew |
| 37 | + |
| 38 | + - name: Setup Java |
| 39 | + uses: actions/setup-java@v3 |
| 40 | + with: |
| 41 | + distribution: temurin |
| 42 | + java-version: 17 |
| 43 | + |
| 44 | + - name: Generate API Documentation |
| 45 | + run: ./gradlew dokkaHtmlMultiModule |
| 46 | + |
| 47 | + - name: Relocate API Documentation Assets |
| 48 | + run: | |
| 49 | + mkdir -p docs/${{ env.REPOSITORY }}/documentation |
| 50 | + cp -r build/dokka/htmlMultiModule/* docs/${{ env.REPOSITORY }}/documentation |
| 51 | +
|
| 52 | + - id: publish-docs |
| 53 | + name: Deploy API Documentation |
| 54 | + uses: ./.github/workflows/sync-docs/ |
| 55 | + env: |
| 56 | + API_TOKEN_GITHUB: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 57 | + with: |
| 58 | + source-file: docs/${{ env.REPOSITORY }}/documentation/ |
| 59 | + destination-folder: ${{ env.REPOSITORY }} |
| 60 | + destination-repo: teogor/source.teogor.dev |
| 61 | + user-email: open-source@teogor.dev |
| 62 | + user-name: Teodor Grigor |
| 63 | + destination-branch-create: ${{ env.DESTINATION_BRANCH }} |
| 64 | + |
| 65 | + build-and-deploy: |
| 66 | + needs: synchronize-documentation |
| 67 | + name: Build and Deploy Updated API Documentation |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Checkout other repository |
| 71 | + uses: actions/checkout@v3 |
| 72 | + with: |
| 73 | + repository: teogor/source.teogor.dev |
| 74 | + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 75 | + |
| 76 | + - name: Create PR (Pull Request) |
| 77 | + run: | |
| 78 | + json=$(curl -L \ |
| 79 | + -X POST \ |
| 80 | + -H "Accept: application/vnd.github+json" \ |
| 81 | + -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 82 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 83 | + https://api.github.com/repos/teogor/source.teogor.dev/pulls \ |
| 84 | + -d '{ |
| 85 | + "title":"Updated documentation for `${{ env.REPO }}`", |
| 86 | + "body":"## 🚀 **Updated Documentation for ${{ env.DISPLAY_NAME }}** 🚀\n\nThis pull request brings you the latest updates to the [${{ env.DISPLAY_NAME }}](https://github.com/${{ env.REPO }}) documentation, ensuring you have access to the most comprehensive and informative guide for using this powerful library.\n\n-------\n\n* Generated by [Publish Docs](https://github.com/${{ env.REPO }}/actions/workflows/publish-docs.yml)\n\n* From [${{ env.REPO }}](https://github.com/${{ env.REPO }})", |
| 87 | + "head":"${{ env.DESTINATION_BRANCH }}", |
| 88 | + "base":"main" |
| 89 | + }' | jq .) |
| 90 | +
|
| 91 | + number=$(jq '.number' <<< ${json}) |
| 92 | +
|
| 93 | + curl -L \ |
| 94 | + -X POST \ |
| 95 | + -H "Accept: application/vnd.github+json" \ |
| 96 | + -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 97 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 98 | + https://api.github.com/repos/teogor/source.teogor.dev/issues/${number}/labels \ |
| 99 | + -d '{"labels":["@documentation"]}' |
| 100 | +
|
| 101 | + curl -L \ |
| 102 | + -X PUT \ |
| 103 | + -H "Accept: application/vnd.github+json" \ |
| 104 | + -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 105 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 106 | + https://api.github.com/repos/teogor/source.teogor.dev/pulls/${number}/merge \ |
0 commit comments