Skip to content

Commit ebc59b7

Browse files
committed
chore: update documentation workflow
1 parent 66be184 commit ebc59b7

File tree

4 files changed

+96
-42
lines changed

4 files changed

+96
-42
lines changed

.github/workflows/documentation.yml

+91-36
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,112 @@
1-
name: Build documentation
1+
# https://github.com/discordjs/discord.js/blob/main/.github/workflows/documentation.yml
2+
3+
name: Documentation
24

35
on:
46
push:
57
branches:
68
- next
7-
workflow_dispatch:
8-
release:
9-
types:
10-
- published
9+
tags:
10+
- '**'
1111

1212
jobs:
13-
deploy:
13+
build:
14+
name: Build documentation
1415
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 }}
1721
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v3
22+
- name: Checkout repository
23+
uses: actions/checkout@v2
2024

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/
2330

24-
- name: Build
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Build docs
2535
run: npm run build:docs
2636

27-
- name: Deploy
28-
uses: peaceiris/actions-gh-pages@v3
37+
- name: Upload artifacts
38+
uses: actions/upload-artifact@v2
2939
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
3542

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}"
3949
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 }}
4058
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
4364

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'
4671

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+
uses: frabert/[email protected]
76+
with:
77+
pattern: '(^@.*\\/(?<package>.*)@v?)?(?<semver>\\d+.\\d+.\\d+)-?.*'
78+
string: ${{ env.BRANCH_NAME }}
79+
replace-with: '$<package>'
4980

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+
uses: frabert/[email protected]
5285
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

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ package-lock.json
1010
.commitlintrc.json
1111
.github/
1212
tsconfig.tsbuildinfo
13-
docs.yml
1413
tsconfig.json
1514
renovate.json

docs.yml docs/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
files:
33
- name: Welcome
44
id: welcome
5-
path: ../README.md
5+
path: ../README.md

scripts/docs.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {runGenerator} from '@discordjs/ts-docgen';
1+
import { runGenerator } from '@discordjs/ts-docgen';
22

33
runGenerator({
4-
existingOutput: 'docs/out-latest.json',
5-
output: 'docs/latest.json',
6-
custom: 'docs.yml'
4+
existingOutput: 'docs/typedoc-out.json',
5+
output: 'docs/docs.json',
6+
custom: 'docs/docs.yml'
77
});

0 commit comments

Comments
 (0)