-
-
Notifications
You must be signed in to change notification settings - Fork 196
139 lines (123 loc) · 4.77 KB
/
update-docs.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
130
131
132
133
134
135
136
137
138
# Copyright (c) godot-rust; Bromeon and contributors.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
name: Compile + Sync Docs
on:
pull_request:
types:
- opened
- reopened
- closed
- synchronize
push:
branches:
- master
env:
# Keep this a variable for easy search&replace.
MSRV: 1.80
jobs:
notify-docs:
# do not run this job in a fork
if: github.repository_owner == 'godot-rust'
runs-on: ubuntu-22.04
steps:
# Checkout is always needed, for the notify step
- name: "Checkout"
uses: actions/checkout@v4
# If Rust version is below msrv, install latest stable.
- name: "Install Rust"
run: |
# Get middle part of version, e.g. 78 from 1.78.0
isMinorVer=$(rustc --version | sed -E 's/rustc [0-9]+\.([0-9]+)\..*/\1/')
shouldMinorVer=$(echo $MSRV | sed -E 's/[0-9]+\.([0-9]+)(\.|$).*/\1/')
if [ $isMinorVer -lt $shouldMinorVer ]; then
echo "Rust version is below MSRV; install latest stable..."
rustup update stable
fi
# This is just a sanity check to make sure that the follow-up docs generation doesn't break.
# So we use the Rust version provided by the GitHub runners, which hopefully is >= MSRV.
- name: "Compile"
if: github.event_name == 'pull_request' && github.event.action != 'closed'
run: cargo check -p godot $GDEXT_FEATURES --ignore-rust-version
# - name: "Dump GitHub context"
# env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
# run: echo "$GITHUB_CONTEXT"
# Pushed to master: no PR-related information
- name: "Construct JSON (for master)"
if: github.ref == 'refs/heads/master'
run: |
payload=$(cat <<'HEREDOC'
{
"op": "put",
"repo": "gdext",
"repo-owner": "${{ github.repository_owner }}",
"num": "master",
"commit-sha": "${{ github.sha }}",
"date": "${{ github.event.head_commit.timestamp }}"
}
HEREDOC)
echo "VAR=$payload"
echo "GDEXT_JSON<<HEREDOC" >> $GITHUB_ENV
echo "${payload}" >> $GITHUB_ENV
echo "HEREDOC" >> $GITHUB_ENV
# Opened/reopened/updated PR: include PR author + title
- name: "Construct JSON (for PR sync)"
if: github.event_name == 'pull_request' && github.event.action != 'closed'
env:
# jq escapes backticks, double quotes etc. in PR title.
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
payload=$(jq -n \
--arg repoOwner '${{ github.repository_owner }}' \
--arg num '${{ github.event.number }}' \
--arg commitSha '${{ github.event.pull_request.head.sha }}' \
--arg date '${{ github.event.pull_request.updated_at }}' \
--arg prAuthor '${{ github.event.pull_request.user.login }}' \
--arg prTitle "$PR_TITLE" \
'{
"op": "put",
"repo": "gdext",
"repo-owner": $repoOwner,
"num": $num,
"commit-sha": $commitSha,
"date": $date,
"pr-author": $prAuthor,
"pr-title": $prTitle
}')
echo "VAR=$payload"
echo "GDEXT_JSON<<HEREDOC" >> $GITHUB_ENV
echo "${payload}" >> $GITHUB_ENV
echo "HEREDOC" >> $GITHUB_ENV
# Closed/merged PR: no more PR-related information necessary, as it will be removed
- name: "Construct JSON (for closed PR)"
if: github.event_name == 'pull_request' && github.event.action == 'closed'
run: |
payload=$(cat <<'HEREDOC'
{
"op": "delete",
"repo": "gdext",
"repo-owner": "${{ github.repository_owner }}",
"num": "${{ github.event.number }}",
"date": "${{ github.event.pull_request.updated_at }}"
}
HEREDOC)
echo "VAR=$payload"
echo "GDEXT_JSON<<HEREDOC" >> $GITHUB_ENV
echo "${payload}" >> $GITHUB_ENV
echo "HEREDOC" >> $GITHUB_ENV
- name: "Print payload"
run: |
echo "$GDEXT_JSON"
- name: "Prepare request"
run: |
token=$(cat .github/other/public-docs-token.txt | base64 -w0 -d)
echo "DOCS_GENERATOR_TOKEN=github_pat_$token" >> $GITHUB_ENV
- name: "Notify doc workflow"
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ env.DOCS_GENERATOR_TOKEN }}
repository: godot-rust/dispatch-forwarder
event-type: 'Generate docs'
client-payload: ${{ env.GDEXT_JSON }}