Skip to content

Commit 5165843

Browse files
bors[bot]Bromeon
andauthored
Merge #786
786: Publish docs of master version r=Bromeon a=Bromeon Automatically generates docs of latest `master` version and publishes them to GitHub pages. Co-authored-by: Jan Haller <bromeon@gmail.com>
2 parents 9ffc935 + 124cad8 commit 5165843

File tree

7 files changed

+156
-30
lines changed

7 files changed

+156
-30
lines changed

.github/workflows/doc.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Doc
2+
3+
# To save env-var dynamically: https://github.com/actions/starter-workflows/issues/68#issuecomment-792338408
4+
# Persist env-var across steps: echo "var=value" >> $GITHUB_ENV
5+
6+
# Note: search-index.js is changing every single time, even if source is not changing. This file is around 2 MB.
7+
# Since the doc repo is cloned prior to committing, this might cause increasingly long CI times.defaults:
8+
# If necessary, archive the 'gh-pages' branch from time to time, or overwrite it altogether -- doc history might not be that important.
9+
10+
11+
on:
12+
push:
13+
branches: [master]
14+
15+
16+
env:
17+
GDNATIVE_LIB_RS_PREFIX: |-
18+
//! _**Note:** This documentation refers to the [latest GitHub version](https://github.com/godot-rust/godot-rust) and is subject to change._<br>
19+
//! _For stable releases, visit [docs.rs/gdnative](https://docs.rs/gdnative)._
20+
//! <br><br>
21+
//!
22+
GDNATIVE_DOC_REPO: git@github.com:godot-rust/doc.git
23+
GDNATIVE_DOC_BRANCH: gh-pages
24+
25+
26+
# In the very unlikely cases where two PRs are merged, and the first 'doc' job is still running when the 2nd 'full-ci' starts,
27+
# make sure the first one is awaited. Even though docs are eventually overwritten, this ensures continuitiy in the doc repo history.
28+
concurrency:
29+
group: 'sync-doc'
30+
cancel-in-progress: false
31+
32+
33+
jobs:
34+
sync-doc:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: "Checkout"
38+
uses: actions/checkout@v2
39+
40+
- name: "Install Rust"
41+
uses: ./.github/composite/rust
42+
with:
43+
rust: stable
44+
components: rustfmt
45+
46+
- name: "Pre-process input"
47+
run: |
48+
mv ${GITHUB_WORKSPACE}/gdnative/src/lib.rs tmp_lib.rs
49+
(echo "${GDNATIVE_LIB_RS_PREFIX}"; cat tmp_lib.rs) > ${GITHUB_WORKSPACE}/gdnative/src/lib.rs
50+
51+
- name: "Generate documentation"
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: doc
55+
args: -p gdnative --lib --no-deps --all-features
56+
57+
# For email address, see https://github.community/t/github-actions-bot-email-address/17204
58+
# As search-index.js changes every time, even if source hasn't changed, this will not need 'git commit --allow-empty'
59+
- name: "Prepare upload"
60+
run: |
61+
mkdir ~/.ssh
62+
echo '${{ secrets.DOC_DEPLOY_SSH_KEY }}' > ~/.ssh/id_rsa
63+
chmod 700 ~/.ssh/id_rsa
64+
git config --global user.name "godot-rust/doc[bot]"
65+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
66+
67+
mkdir doc && cd doc
68+
git clone --single-branch --branch ${GDNATIVE_DOC_BRANCH} --no-checkout ${GDNATIVE_DOC_REPO} . \
69+
|| (git init -b ${GDNATIVE_DOC_BRANCH} && git remote add origin ${GDNATIVE_DOC_REPO})
70+
71+
mv ${GITHUB_WORKSPACE}/target/doc/* .
72+
mv ${GITHUB_WORKSPACE}/.github/workflows/doc/* .
73+
74+
GDNATIVE_VERSION=$(grep -Po '^version = "\K[^"]*' ${GITHUB_WORKSPACE}/gdnative/Cargo.toml)
75+
GDNATIVE_SHORT_SHA=$(git rev-parse --short "${GITHUB_SHA}")
76+
77+
find gdnative -name .html -o -type f -print0 | xargs -0 sed -i 's/'"${GDNATIVE_VERSION}"'/master/g'
78+
79+
git add --all
80+
git commit -m "Sync doc from ${GDNATIVE_SHORT_SHA}
81+
82+
Revision in godot-rust: ${GITHUB_SHA}"
83+
84+
- name: "Upload"
85+
working-directory: doc
86+
run: git push origin ${GDNATIVE_DOC_BRANCH}
87+
88+
- name: "Cleanup"
89+
run: shred -u ~/.ssh/id_rsa
90+
91+
92+
93+
# Possible alternative: dispatching a remote workflow
94+
95+
# - name: 'Dispatch remote workflow'
96+
# run: >
97+
# curl
98+
# -X POST
99+
# -H "Accept: application/vnd.github.v3+json"
100+
# https://api.github.com/repos/godot-rust/doc/actions/workflows/triggered-remotely/dispatches
101+
# -d '{"ref":"master"}'
102+
103+
# - name: Repository Dispatch
104+
# uses: peter-evans/repository-dispatch@v1
105+
# with:
106+
# repository: godot-rust/doc
107+
# token: ${{ secrets.REPO_ACCESS_TOKEN }}
108+
# event-type: my-event

.github/workflows/doc/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head>
3+
<!-- Note: cache control not reliable through meta. The below redirection may remain cached in browsers. -->
4+
<!-- Alternatively, use JS. Also, consider https://github.com/rust-lang/cargo/issues/739 in the future. -->
5+
<meta http-equiv="refresh" content="0; url=/doc/gdnative" />
6+
</head>
7+
</html>

.github/workflows/ci.yml renamed to .github/workflows/full-ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ jobs:
118118
- name: Install LLVM
119119
uses: ./.github/composite/llvm
120120
if: ${{ matrix.os.id == 'windows-latest' }}
121+
- name: Compile tests
122+
run: cargo test --workspace --all-features --no-run;
121123
- name: Test
122124
run: cargo test --workspace --all-features ${{ matrix.testflags }};
123125

124-
check-release:
125-
name: check-release-${{ matrix.os.name }}
126+
build-release:
127+
name: build-release-${{ matrix.os.name }}
126128
needs: rustfmt
127129
strategy:
128130
fail-fast: true # cancel all jobs as soon as one fails?
@@ -147,7 +149,7 @@ jobs:
147149
- name: Release build (check only)
148150
run: cargo check --release;
149151

150-
test-ios:
152+
build-ios:
151153
needs: rustfmt
152154
#continue-on-error: ${{ matrix.rust == 'nightly' }}
153155
#strategy:
@@ -178,7 +180,7 @@ jobs:
178180
cd gdnative-sys;
179181
cargo dinghy --platform auto-ios-x86_64 test;
180182
181-
test-android:
183+
build-android:
182184
# Note: even though Android builds for another architecture than Linux, it can reuse downloaded crates (source code, maybe 'cargo check').
183185
needs: rustfmt
184186
#continue-on-error: ${{ matrix.rust == 'nightly' }}
@@ -295,10 +297,10 @@ jobs:
295297
#- rustfmt
296298
- clippy
297299
- test
298-
- test-ios
299-
- test-android
300300
- integration-test-godot
301-
- check-release
301+
- build-release
302+
- build-ios
303+
- build-android
302304
runs-on: ubuntu-latest
303305
steps:
304306
- name: Mark the job as a success

.github/workflows/minimal-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
- uses: actions/checkout@v2
6262
- name: Install Rust
6363
uses: ./.github/composite/rust
64+
- name: Compile tests
65+
run: cargo test --workspace --all-features --no-run;
6466
- name: Test
6567
run: cargo test --workspace --all-features;
6668

.github/workflows/publish.yml renamed to .github/workflows/release-version.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Publish to crates.io
33
on:
44
push:
55
branches:
6-
- '!*'
6+
- '!**'
77
tags:
8-
- '*'
8+
- '0.9.[0-9]+'
9+
- '0.10.[0-9]+'
910

1011
defaults:
1112
run:

bindings_generator/src/classes.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn generate_class_constants(class: &GodotClass) -> TokenStream {
6767

6868
let mut class_constants: Vec<(&ConstantName, &ConstantValue)> =
6969
class.constants.iter().collect();
70-
class_constants.sort_by(|a, b| a.0.cmp(b.0));
70+
class_constants.sort_by(constant_sorter);
7171

7272
for (name, value) in &class_constants {
7373
let name = format_ident!("{}", name);
@@ -88,33 +88,18 @@ pub(crate) fn generate_class_constants(class: &GodotClass) -> TokenStream {
8888
}
8989
}
9090

91-
fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
92-
// In order to not pollute the API with more Result types,
93-
// rename the Result enum used by Search to SearchResult
94-
// to_camel_case() is used to make the enums more Rust like.
95-
// DOFBlurQuality => DofBlurQuality
96-
match enum_name {
97-
"Result" => {
98-
let mut res = String::from(class_name);
99-
res.push_str(enum_name);
100-
res.to_camel_case()
101-
}
102-
_ => enum_name.to_camel_case(),
103-
}
104-
}
105-
10691
pub(crate) fn generate_enums(class: &GodotClass) -> TokenStream {
107-
// TODO: check whether the start of the variant name is
108-
// equal to the end of the enum name and if so don't repeat it
109-
// it. For example ImageFormat::Rgb8 instead of ImageFormat::FormatRgb8.
92+
// TODO: check whether the start of the variant name is equal to the end of the enum name and if so, don't repeat it.
93+
// For example ImageFormat::Rgb8 instead of ImageFormat::FormatRgb8.
94+
11095
let mut enums: Vec<&Enum> = class.enums.iter().collect();
11196
enums.sort();
11297
let enums = enums.iter().map(|e| {
11398
let enum_name = generate_enum_name(&class.name, &e.name);
11499
let typ_name = format_ident!("{}", enum_name);
115100

116101
let mut values: Vec<_> = e.values.iter().collect();
117-
values.sort_by(|a, b| a.1.cmp(b.1));
102+
values.sort_by(constant_sorter);
118103

119104
let consts = values.iter().map(|(key, val)| {
120105
let key = key.to_uppercase();
@@ -150,3 +135,24 @@ pub(crate) fn generate_enums(class: &GodotClass) -> TokenStream {
150135
#(#enums)*
151136
}
152137
}
138+
139+
fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
140+
// In order to not pollute the API with more Result types,
141+
// rename the Result enum used by Search to SearchResult
142+
// to_camel_case() is used to make the enums more Rust like.
143+
// DOFBlurQuality => DofBlurQuality
144+
match enum_name {
145+
"Result" => {
146+
let mut res = String::from(class_name);
147+
res.push_str(enum_name);
148+
res.to_camel_case()
149+
}
150+
_ => enum_name.to_camel_case(),
151+
}
152+
}
153+
154+
// Ensures deterministic order of constants, not dependent on inner hash-map or sort workings
155+
fn constant_sorter(a: &(&String, &i64), b: &(&String, &i64)) -> std::cmp::Ordering {
156+
Ord::cmp(a.1, b.1) // first, sort by integer value
157+
.then(Ord::cmp(a.0, b.0)) // and if equal, by name
158+
}

gdnative-derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn profiled(meta: TokenStream, input: TokenStream) -> TokenStream {
227227
///
228228
/// **Important**: This needs to be added to one and only one `impl` block for a given `NativeClass`.
229229
///
230-
/// For additional details about how `#[methods]` expands, please refer to [gdnative::methods](methods)
230+
/// For additional details about how `#[methods]` expands, please refer to [gdnative::methods](macro@methods)
231231
///
232232
/// ### `#[export]`
233233
/// Registers the attributed function signature to be used by Godot.

0 commit comments

Comments
 (0)