-
Notifications
You must be signed in to change notification settings - Fork 208
109 lines (82 loc) · 3.92 KB
/
doc.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
name: Doc
# To save env-var dynamically: https://github.com/actions/starter-workflows/issues/68#issuecomment-792338408
# Persist env-var across steps: echo "var=value" >> $GITHUB_ENV
# Note: search-index.js is changing every single time, even if source is not changing. This file is around 2 MB.
# Since the doc repo is cloned prior to committing, this might cause increasingly long CI times.defaults:
# If necessary, archive the 'gh-pages' branch from time to time, or overwrite it altogether -- doc history might not be that important.
on:
push:
branches: [master]
env:
GDRUST_LIB_RS_PREFIX: |-
//! _**Note:** This documentation refers to the [latest GitHub version](https://github.com/godot-rust/godot-rust) and is subject to change._<br>
//! _For stable releases, visit [docs.rs/gdnative](https://docs.rs/gdnative)._
//! <br><br>
//!
GDRUST_DOC_REPO: git@github.com:godot-rust/docs.git
GDRUST_DOC_BRANCH: gh-pages
GDRUST_FEATURES: "async,serde"
# In the very unlikely cases where two PRs are merged, and the first 'doc' job is still running when the 2nd 'full-ci' starts,
# make sure the first one is awaited. Even though docs are eventually overwritten, this ensures continuitiy in the doc repo history.
concurrency:
group: 'sync-doc'
cancel-in-progress: false
jobs:
sync-doc:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Install Rust"
uses: ./.github/composite/rust
with:
rust: stable
components: rustfmt
- name: "Pre-process input"
run: |
mv ${GITHUB_WORKSPACE}/gdnative/src/lib.rs tmp_lib.rs
(echo "${GDRUST_LIB_RS_PREFIX}"; cat tmp_lib.rs) > ${GITHUB_WORKSPACE}/gdnative/src/lib.rs
- name: "Generate documentation"
uses: actions-rs/cargo@v1
with:
command: doc
args: -p gdnative --lib --no-deps --features ${{ env.GDRUST_FEATURES }}
# For email address, see https://github.community/t/github-actions-bot-email-address/17204
# As search-index.js changes every time, even if source hasn't changed, this will not need 'git commit --allow-empty'
- name: "Prepare upload"
run: |
mkdir ~/.ssh
echo '${{ secrets.DOC_DEPLOY_SSH_KEY }}' > ~/.ssh/id_rsa
chmod 700 ~/.ssh/id_rsa
git config --global user.name "godot-rust/doc[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
mkdir doc && cd doc
git clone --single-branch --branch ${GDRUST_DOC_BRANCH} --no-checkout ${GDRUST_DOC_REPO} . \
|| (git init -b ${GDRUST_DOC_BRANCH} && git remote add origin ${GDRUST_DOC_REPO})
mv ${GITHUB_WORKSPACE}/target/doc/* .
mv ${GITHUB_WORKSPACE}/.github/workflows/doc/* .
GDRUST_VERSION=$(grep -Po '^version = "\K[^"]*' ${GITHUB_WORKSPACE}/gdnative/Cargo.toml)
GDRUST_SHORT_SHA=$(git rev-parse --short "${GITHUB_SHA}")
find gdnative -name .html -o -type f -print0 | xargs -0 sed -i 's/'"${GDRUST_VERSION}"'/master/g'
git add --all
git commit -m "Sync doc from ${GDRUST_SHORT_SHA}
Revision in godot-rust: ${GITHUB_SHA}"
- name: "Upload"
working-directory: doc
run: git push origin ${GDRUST_DOC_BRANCH}
- name: "Cleanup"
run: shred -u ~/.ssh/id_rsa
# Possible alternative: dispatching a remote workflow
# - name: 'Dispatch remote workflow'
# run: >
# curl
# -X POST
# -H "Accept: application/vnd.github.v3+json"
# https://api.github.com/repos/godot-rust/doc/actions/workflows/triggered-remotely/dispatches
# -d '{"ref":"master"}'
# - name: Repository Dispatch
# uses: peter-evans/repository-dispatch@v1
# with:
# repository: godot-rust/doc
# token: ${{ secrets.REPO_ACCESS_TOKEN }}
# event-type: my-event