-
Notifications
You must be signed in to change notification settings - Fork 20
78 lines (77 loc) · 3.08 KB
/
apidoc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: apidoc
on:
push:
branches:
- main
paths:
- '.github/workflows/apidoc.yml'
- '**/validate-input.json'
- '**/validate-output.json'
- '**/validator-definitions.json'
pull_request:
types: [opened, synchronize, closed]
paths:
- '.github/workflows/apidoc.yml'
- '**/validate-input.json'
- '**/validate-output.json'
- '**/validator-definitions.json'
jobs:
push_image:
name: 'Build API docs for ${{ github.head_ref }}'
runs-on: ubuntu-22.04
steps:
- id: checkout
uses: actions/checkout@v4
- id: configure
name: "Configure git environment"
run: |
git config user.name nethbot
git config user.email [email protected]
- id: schemadocs
name: "Build the images"
if: "${{ github.event_name == 'push' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')) }}"
run: |
# Build the images
set -e
buildah from --name schemadocs -v "${PWD}:/usr/src:Z" docker.io/library/node:slim
buildah run schemadocs npm install -g @adobe/jsonschema2md
buildah run schemadocs sh <<'EOF'
set -e
cd /usr/src
rm -rf .apidoc/{dst,src}
for MODULE_DIR in $(find . -type d -name imageroot -printf '%h\n'); do
SRCDIR=.apidoc/src/${MODULE_DIR#./}
DSTDIR=.apidoc/dst/${MODULE_DIR#./}
mkdir -vp ${SRCDIR}
find ${MODULE_DIR} -name validate-input.json -o -name validate-output.json -o -name validator-definitions.json | node .apidoc/id-rename.js ${SRCDIR}
jsonschema2md -d ${SRCDIR} -o ${DSTDIR} -x ${DSTDIR} -e json
done
EOF
- id: publish
name: "Publish the API documents"
if: "${{ github.event_name == 'push' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')) }}"
run: |
# Publish the API documents
set -e
git add .apidoc/dst
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
if (( PR_NUMBER > 0 )); then
COMMIT_MESSAGE="apidoc@${{ github.head_ref }} #${PR_NUMBER}"
REMOTE_BRANCH="apidoc-${{ github.head_ref }}"
else
BRANCH=$(basename ${{ github.ref }})
COMMIT_MESSAGE="apidoc@$BRANCH"
REMOTE_BRANCH="apidoc"
fi
TREE=$(git write-tree --prefix=.apidoc/dst)
COMMIT=$(git commit-tree -m "${COMMIT_MESSAGE}" ${TREE})
git push -f origin $COMMIT:refs/heads/${REMOTE_BRANCH}
echo "API documentation has been published to"
echo ""
echo " https://github.com/${{ github.repository }}/tree/${REMOTE_BRANCH}"
echo ""
- id: cleanup
name: "Cleanup apidoc-${{ github.head_ref }} branch"
if: "github.event_name == 'pull_request' && github.event.action == 'closed'"
run: |
git push -f origin :refs/heads/apidoc-${{ github.head_ref }}