|
1 |
| -name: Build documentation |
| 1 | +# https://github.com/discordjs/discord.js/blob/main/.github/workflows/documentation.yml |
| 2 | + |
| 3 | +name: Documentation |
2 | 4 |
|
3 | 5 | on:
|
4 | 6 | push:
|
5 | 7 | branches:
|
6 | 8 | - next
|
7 |
| - workflow_dispatch: |
8 |
| - release: |
9 |
| - types: |
10 |
| - - published |
| 9 | + tags: |
| 10 | + - '**' |
11 | 11 |
|
12 | 12 | jobs:
|
13 |
| - deploy: |
| 13 | + build: |
| 14 | + name: Build documentation |
14 | 15 | runs-on: ubuntu-latest
|
15 |
| - if: ${{ (github.event_name == 'release') || (github.event_name == 'workflow_dispatch') }} |
16 |
| - |
| 16 | + if: github.repository_owner == 'Garlic-Team' |
| 17 | + outputs: |
| 18 | + BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }} |
| 19 | + BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }} |
| 20 | + SHA: ${{ steps.env.outputs.SHA }} |
17 | 21 | steps:
|
18 |
| - - name: Checkout |
19 |
| - uses: actions/checkout@v3 |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v2 |
20 | 24 |
|
21 |
| - - name: Download |
22 |
| - run: npm i @discordjs/ts-docgen typedoc-plugin-djs-links |
| 25 | + - name: Install Node v16 |
| 26 | + uses: actions/setup-node@v3 |
| 27 | + with: |
| 28 | + node-version: 16 |
| 29 | + registry-url: https://registry.npmjs.org/ |
23 | 30 |
|
24 |
| - - name: Build |
| 31 | + - name: Install dependencies |
| 32 | + run: npm ci |
| 33 | + |
| 34 | + - name: Build docs |
25 | 35 | run: npm run build:docs
|
26 | 36 |
|
27 |
| - - name: Deploy |
28 |
| - uses: peaceiris/actions-gh-pages@v3 |
| 37 | + - name: Upload artifacts |
| 38 | + uses: actions/upload-artifact@v2 |
29 | 39 | with:
|
30 |
| - github_token: ${{ secrets.ACCESS_TOKEN }} |
31 |
| - publish_dir: ./docs |
32 |
| - publish_branch: docs |
33 |
| - destination_dir: ./docs/ |
34 |
| - keep_files: true |
| 40 | + name: docs |
| 41 | + path: docs/docs.json |
35 | 42 |
|
36 |
| - deploy_next: |
37 |
| - runs-on: ubuntu-latest |
38 |
| - if: ${{ github.event_name == 'push' }} |
| 43 | + - name: Set outputs for upload job |
| 44 | + id: env |
| 45 | + run: | |
| 46 | + echo "::set-output name=BRANCH_NAME::${GITHUB_REF_NAME}" |
| 47 | + echo "::set-output name=BRANCH_OR_TAG::${GITHUB_REF_TYPE}" |
| 48 | + echo "::set-output name=SHA::${GITHUB_SHA}" |
39 | 49 |
|
| 50 | + upload: |
| 51 | + name: Upload Documentation |
| 52 | + needs: build |
| 53 | + runs-on: ubuntu-latest |
| 54 | + env: |
| 55 | + BRANCH_NAME: ${{ needs.build.outputs.BRANCH_NAME }} |
| 56 | + BRANCH_OR_TAG: ${{ needs.build.outputs.BRANCH_OR_TAG }} |
| 57 | + SHA: ${{ needs.build.outputs.SHA }} |
40 | 58 | steps:
|
41 |
| - - name: Checkout |
42 |
| - uses: actions/checkout@v3 |
| 59 | + - name: Download artifacts |
| 60 | + uses: actions/download-artifact@v2 |
| 61 | + with: |
| 62 | + name: docs |
| 63 | + path: docs |
43 | 64 |
|
44 |
| - - name: Download |
45 |
| - run: npm i @discordjs/ts-docgen typedoc-plugin-djs-links |
| 65 | + - name: Checkout docs repository |
| 66 | + uses: actions/checkout@v2 |
| 67 | + with: |
| 68 | + repository: 'discordjs/docs' |
| 69 | + token: ${{ secrets.ACCESS_TOKEN }} |
| 70 | + path: 'out' |
46 | 71 |
|
47 |
| - - name: Build |
48 |
| - run: npm run build:next-docs |
| 72 | + - name: 'Extract package from tag' |
| 73 | + if: env.BRANCH_OR_TAG == 'tag' |
| 74 | + id: package-name |
| 75 | + |
| 76 | + with: |
| 77 | + pattern: '(^@.*\\/(?<package>.*)@v?)?(?<semver>\\d+.\\d+.\\d+)-?.*' |
| 78 | + string: ${{ env.BRANCH_NAME }} |
| 79 | + replace-with: '$<package>' |
49 | 80 |
|
50 |
| - - name: Deploy |
51 |
| - uses: peaceiris/actions-gh-pages@v3 |
| 81 | + - name: 'Extract semver from tag' |
| 82 | + if: env.BRANCH_OR_TAG == 'tag' |
| 83 | + id: semver |
| 84 | + |
52 | 85 | with:
|
53 |
| - github_token: ${{ secrets.ACCESS_TOKEN }} |
54 |
| - publish_dir: ./docs |
55 |
| - publish_branch: docs |
56 |
| - destination_dir: ./docs/ |
57 |
| - keep_files: true |
| 86 | + pattern: '(^@.*\\/(?<package>.*)@v?)?(?<semver>\\d+.\\d+.\\d+)-?.*' |
| 87 | + string: ${{ env.BRANCH_NAME }} |
| 88 | + replace-with: '$<semver>' |
| 89 | + |
| 90 | + - name: Move docs to correct directory |
| 91 | + if: env.BRANCH_OR_TAG == 'tag' |
| 92 | + env: |
| 93 | + PACKAGE: ${{ steps.package-name.outputs.replaced }} |
| 94 | + SEMVER: ${{ steps.semver.outputs.replaced }} |
| 95 | + run: | |
| 96 | + mkdir -p out/gcommands |
| 97 | + mv docs/docs.json out/gcommands/${SEMVER}.json |
| 98 | + - name: Move docs to correct directory |
| 99 | + if: env.BRANCH_OR_TAG == 'branch' |
| 100 | + env: |
| 101 | + PACKAGE: ${{ matrix.package }} |
| 102 | + run: | |
| 103 | + mkdir -p out/gcommands |
| 104 | + mv docs/docs.json out/gcommands/${BRANCH_NAME}.json |
| 105 | + - name: Commit and push |
| 106 | + run: | |
| 107 | + cd out |
| 108 | + git config user.name github-actions[bot] |
| 109 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 110 | + git add . |
| 111 | + git commit -m "Docs build for ${BRANCH_OR_TAG} ${BRANCH_NAME}: ${SHA}" || true |
| 112 | + git push |
0 commit comments