Skip to content

Commit 0dc4ef0

Browse files
committed
Release CI postprocesses docs and commits
1 parent 3e004fa commit 0dc4ef0

File tree

2 files changed

+135
-11
lines changed

2 files changed

+135
-11
lines changed

.github/other/apply-doc-cfg.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# Copyright (c) godot-rust; Bromeon and contributors.
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
# Adds #[doc(cfg(...))] annotations to Rust docs, based on #[cfg(...)] in the source code.
8+
9+
# Keep in sync with the same file in website repo.
10+
11+
# Usage:
12+
# apply-doc-cfg.sh [--install-sd] [--rustfmt]
13+
14+
set -e
15+
16+
17+
for arg in "$@"; do
18+
case "$arg" in
19+
--install-sd)
20+
installSd="true"
21+
;;
22+
--rustfmt)
23+
rustfmt="true"
24+
;;
25+
*)
26+
echo "Unknown argument: $arg"
27+
exit 1
28+
;;
29+
esac
30+
done
31+
32+
SD_VERSION="1.0.0"
33+
PRE="DocCfg | "
34+
35+
# For gdext, add feature/cfg annotations in docs. This needs nightly rustdoc + custom preprocessing.
36+
# Replace #[cfg(...)] with #[doc(cfg(...))], a nightly feature: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
37+
# Potential alternative: https://docs.rs/doc-cfg/latest/doc_cfg
38+
if [[ "$installSd" == "true" ]]; then
39+
# Install sd (modern sed). No point in waiting for eternal `cargo install` if we can fetch a prebuilt binary in 1s.
40+
echo "$PRE install sd (modern sed)..."
41+
curl -L https://github.com/chmln/sd/releases/download/v${SD_VERSION}/sd-v${SD_VERSION}-x86_64-unknown-linux-musl.tar.gz -o archive.tar.gz
42+
mkdir -p /tmp/tools
43+
tar -zxvf archive.tar.gz -C /tmp/tools --strip-components=1
44+
sd=/tmp/tools/sd
45+
else
46+
sd=sd
47+
fi
48+
49+
echo "$PRE preprocess docs..."
50+
51+
# Enable feature in each lib.rs file.
52+
# Note: first command uses sed because it's easier, and only handful of files.
53+
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![feature(doc_cfg)]\n/' {} +
54+
55+
# Then do the actual replacements.
56+
# Could use \( -path "..." -o -path "..." \) to limit to certain paths.
57+
# Do NOT include './target/debug/build/*' because generated files cannot be modified -- rustdoc will rerun the generation.
58+
# This is done by directly emitting #[cfg_attr(published_docs, doc(cfg(...)))] in the godot-codegen crate, and that cfg is passed below.
59+
find . -type f -name '*.rs' \
60+
\( -path './godot' -o -path './godot-*' \) \
61+
| while read -r file; do
62+
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
63+
# shellcheck disable=SC2016
64+
$sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
65+
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
66+
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
67+
done
68+
69+
if [[ "$rustfmt" == "true" ]]; then
70+
echo "$PRE Format code using rustfmt..."
71+
cargo fmt
72+
fi
73+
74+
echo "$PRE Docs post-processed."

.github/workflows/release-version.yml

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
# Copyright (c) godot-rust; Bromeon and contributors.
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
16
name: "Release workflow"
27

38
on:
49
push:
5-
branches:
6-
- '!**'
7-
tags:
8-
# To include pre-releases: 'v0.1.[0-9]+-?*'
9-
- 'v0.1.[0-9]+'
10+
# branches:
11+
# - '!**'
12+
# tags:
13+
# # To include pre-releases: 'v0.1.[0-9]+-?*'
14+
# - 'v0.1.[0-9]+'
1015

1116
env:
1217
# Note: used for test and clippy, not for publish
@@ -30,32 +35,37 @@ defaults:
3035
jobs:
3136
validation:
3237
runs-on: ubuntu-latest
38+
outputs:
39+
GDEXT_PUBLISHED_VERSION: ${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}
3340
steps:
3441
- uses: actions/checkout@v4
3542

3643
# sed: https://unix.stackexchange.com/a/589584
3744
- name: "Interpret tag version"
45+
id: interpret-tag-version
3846
run: |
39-
version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/v\(.*\)#\1#p")
47+
#version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/v\(.*\)#\1#p")
48+
version="0.1.0" # DEBUG
4049
[ -z "$version" ] && {
4150
printf "\n::error::Failed to parse '$GITHUB_REF'.\n"
4251
exit 2
4352
}
4453
4554
echo "Published version: $version"
46-
echo "GDEXT_PUBLISHED_VERSION=$version" >> $GITHUB_ENV
55+
echo "GDEXT_PUBLISHED_VERSION=$version" >> $GITHUB_OUTPUT
4756
48-
- name: "Verify that Cargo.toml versions match ${{ env.GDEXT_PUBLISHED_VERSION }}"
57+
- name: "Verify that Cargo.toml versions match ${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}"
4958
run: |
5059
echo "Checking crate versions..."
60+
publishedVersion="${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}"
5161
5262
# Check if each Cargo.toml has that version
5363
IFS=' ' read -r -a publishedCrates <<< "$GDEXT_CRATES"
5464
for crate in "${publishedCrates[@]}"; do
5565
readVersion=$(grep -Po '^version = "\K[^"]*' "$crate/Cargo.toml")
5666
printf "* $crate -> $readVersion"
5767
58-
if [[ "$readVersion" != "$GDEXT_PUBLISHED_VERSION" ]]; then
68+
if [[ "$readVersion" != "$publishedVersion" ]]; then
5969
printf " ERROR\n"
6070
versionMismatch="1"
6171
else
@@ -128,17 +138,57 @@ jobs:
128138
exit 1
129139
}
130140
131-
publish:
141+
docs-and-commit:
132142
runs-on: ubuntu-latest
133-
# environment: 'Crates.io'
134143
needs:
144+
- validation
135145
- unit-test
136146
- clippy
137147
- rustfmt
148+
env:
149+
GDEXT_PUBLISHED_VERSION: ${{ needs.validation.outputs.GDEXT_PUBLISHED_VERSION }}
150+
steps:
151+
- uses: actions/checkout@v4
152+
153+
- name: "Install Rust (uncached)"
154+
run: rustup update stable
155+
156+
- name: "Commit raw changes"
157+
run: |
158+
# Backup current repo, so we can checkout.
159+
mkdir -p /tmp/repo
160+
rsync -av --exclude .git --exclude target ./ /tmp/repo/
161+
git switch releases || git switch --orphan releases
162+
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
163+
# Restore.
164+
rsync -av --ignore-existing /tmp/repo/ .
165+
166+
# Commit.
167+
git config user.name "Godot-Rust Automation"
168+
git config user.email "[email protected]"
169+
git add .
170+
git commit -m "Repo state for v${{ env.GDEXT_PUBLISHED_VERSION }}."
171+
172+
- name: "Apply #[doc(cfg(...))]"
173+
run: .github/other/apply-doc-cfg.sh --install-sd --rustfmt
174+
175+
- name: "Commit post-processed changes"
176+
run: git commit -am "Postprocess docs for v${{ env.GDEXT_PUBLISHED_VERSION }}."
177+
178+
- name: "Push changes"
179+
run: git push origin releases
180+
181+
publish:
182+
runs-on: ubuntu-latest
183+
# environment: 'Crates.io'
184+
needs:
185+
- docs-and-commit
138186
steps:
139187
# Note: we cannot dry-run the publishing, since crates depend on each other, and dry-run will fail if they aren't yet on crates.io.
140188
# Sleep to leave crates.io and docs.rs some time to index the dependencies, before releasing dependents.
141189
- uses: actions/checkout@v4
190+
with:
191+
ref: releases
142192

143193
- name: "Install Rust (uncached)"
144194
run: rustup update stable

0 commit comments

Comments
 (0)