generated from snowcrystals/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (109 loc) · 3.44 KB
/
documentation.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Documentation
on:
workflow_dispatch:
push:
branches:
- main
tags:
- "v*"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
REPOSITORY: ${{ github.event.repository.name }}
jobs:
build:
name: Build Documentation
runs-on: ubuntu-latest
if: github.repository_owner == 'snowcrystals' && github.repository != 'snowcrystals/template'
outputs:
NAME: ${{ steps.env.outputs.NAME }}
TYPE: ${{ steps.env.outputs.TYPE }}
SHA: ${{ steps.env.outputs.SHA }}
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Use Node.js v18
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --immutable
- name: Build Documentation
run: yarn docs
- name: Upload Documentation Artifacts
uses: actions/upload-artifact@v4
with:
name: docs
path: docs/api.json
- name: Set Output
id: env
run: |
echo "NAME=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
echo "TYPE=${GITHUB_REF_TYPE}" >> $GITHUB_OUTPUT
echo "SHA=${GITHUB_SHA}" >> $GITHUB_OUTPUT
upload:
name: Upload Documentation
needs: build
runs-on: ubuntu-latest
env:
NAME: ${{ needs.build.outputs.NAME }}
TYPE: ${{ needs.build.outputs.TYPE }}
SHA: ${{ needs.build.outputs.SHA }}
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Use Node.js v18
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
registry-url: https://registry.yarnpkg.org/
- name: Install Dependencies
run: yarn --immutable
- name: Download Documentation Artifacts
uses: actions/download-artifact@v4
with:
name: docs
path: docs
- name: Checkout Documentation Project
uses: actions/checkout@v4
with:
repository: "snowcrystals/docs"
token: ${{ secrets.USER_TOKEN }}
path: "out"
- name: Move Documentation
if: ${{ env.TYPE == 'tag' }}
env:
SEMVER: ${{ env.NAME }}
run: |
mkdir -p out/docs/${{ env.REPOSITORY }}
mv docs/api.json out/docs/${{ env.REPOSITORY }}/${SEMVER}.json
- name: Move Documentation
if: ${{ env.TYPE == 'branch' }}
run: |
mkdir -p out/docs/${{ env.REPOSITORY }}
mv docs/api.json out/docs/${{ env.REPOSITORY }}/${NAME}.json
- name: Commit & Push
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3
with:
max_attempts: 3
retry_on: error
timeout_minutes: 1
command: |
cd out
git add .
if git diff-index --quiet HEAD --; then
echo "No changes to commit, exiting with code 0"
exit 0;
else
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git config rebase.autostash true
git config pull.rebase true
git commit -m "docs(${{ env.REPOSITORY }}): build for ${TYPE} ${NAME}: ${SHA}" || true
git pull
git push
fi