Skip to content

Commit b61caa9

Browse files
committed
Tweak doc generation, commit and tag
1 parent 5188047 commit b61caa9

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ echo "$PRE preprocess docs..."
5050

5151
# Enable feature in each lib.rs file.
5252
# 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/' {} +
53+
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![cfg_attr(published_docs, feature(doc_cfg))]\n/' {} +
5454

5555
# Then do the actual replacements.
5656
# Could use \( -path "..." -o -path "..." \) to limit to certain paths.
@@ -61,14 +61,15 @@ find . -type f -name '*.rs' \
6161
| while read -r file; do
6262
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
6363
# shellcheck disable=SC2016
64-
$sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
64+
$sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[cfg_attr(published_docs, doc($2))]\n$3' "$file"
65+
# $sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
6566
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
6667
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
6768
done
6869

6970
if [[ "$rustfmt" == "true" ]]; then
7071
echo "$PRE Format code using rustfmt..."
71-
cargo fmt
72+
cargo fmt --all
7273
fi
7374

7475
echo "$PRE Docs post-processed."

.github/workflows/release-version.yml

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ name: "Release workflow"
77

88
on:
99
push:
10+
workflow_dispatch:
11+
inputs:
12+
skip-release:
13+
description: "Enter 'y' to skip release to crates.io"
14+
default: ""
15+
required: false
1016
# branches:
1117
# - '!**'
1218
# tags:
@@ -36,28 +42,33 @@ jobs:
3642
validation:
3743
runs-on: ubuntu-latest
3844
outputs:
39-
GDEXT_PUBLISHED_VERSION: ${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}
45+
GDEXT_PUBLISHED_VERSION: ${{ steps.parse-crate-version.outputs.GDEXT_PUBLISHED_VERSION }}
4046
steps:
4147
- uses: actions/checkout@v4
4248

43-
# sed: https://unix.stackexchange.com/a/589584
44-
- name: "Interpret tag version"
45-
id: interpret-tag-version
49+
- name: "Parse crate version from Cargo.toml"
50+
id: parse-crate-version
4651
run: |
47-
#version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/v\(.*\)#\1#p")
48-
version="0.1.0" # DEBUG
49-
[ -z "$version" ] && {
50-
printf "\n::error::Failed to parse '$GITHUB_REF'.\n"
52+
crateVer=$(grep -Po '^version = "\K[^"]*' godot/Cargo.toml)
53+
if [[ -z "$crateVer" ]]; then
54+
echo "::error::Failed to parse crate version from godot/Cargo.toml."
55+
exit 1
56+
fi
57+
58+
# Check if tag exists.
59+
git fetch --tags
60+
if git tag -l | grep -q "^v$crateVer$" ; then
61+
echo "::error::Tag 'v$crateVer' already exists."
5162
exit 2
52-
}
63+
fi
5364
54-
echo "Published version: $version"
55-
echo "GDEXT_PUBLISHED_VERSION=$version" >> $GITHUB_OUTPUT
65+
echo "GDEXT_PUBLISHED_VERSION=$crateVer" >> $GITHUB_OUTPUT
66+
echo "Validated version: $crateVer"
5667
57-
- name: "Verify that Cargo.toml versions match ${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}"
68+
- name: "Verify that Cargo.toml versions match ${{ steps.parse-crate-version.outputs.GDEXT_PUBLISHED_VERSION }}"
5869
run: |
5970
echo "Checking crate versions..."
60-
publishedVersion="${{ steps.interpret-tag-version.outputs.GDEXT_PUBLISHED_VERSION }}"
71+
publishedVersion="${{ steps.parse-crate-version.outputs.GDEXT_PUBLISHED_VERSION }}"
6172
6273
# Check if each Cargo.toml has that version
6374
IFS=' ' read -r -a publishedCrates <<< "$GDEXT_CRATES"
@@ -158,7 +169,7 @@ jobs:
158169
# Backup current repo, so we can checkout.
159170
mkdir -p /tmp/repo
160171
rsync -av --exclude .git --exclude target ./ /tmp/repo/
161-
git switch releases || git switch --orphan releases
172+
git fetch origin releases && git switch releases || git switch --orphan releases
162173
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
163174
# Restore.
164175
rsync -av --ignore-existing /tmp/repo/ .
@@ -167,19 +178,25 @@ jobs:
167178
git config user.name "Godot-Rust Automation"
168179
git config user.email "[email protected]"
169180
git add .
170-
git commit -m "Repo state for v${{ env.GDEXT_PUBLISHED_VERSION }}."
181+
git commit -m "Repo state for v${{ env.GDEXT_PUBLISHED_VERSION }}"
171182
172183
- name: "Apply #[doc(cfg(...))]"
173-
run: .github/other/apply-doc-cfg.sh --install-sd --rustfmt
184+
# Skip --rustfmt, as it causes weird reformatting of quote! {} statements.
185+
# #[doc(cfg(...))] on the same line is the lesser evil.
186+
run: .github/other/apply-doc-cfg.sh --install-sd
174187

175188
- name: "Commit post-processed changes"
176-
run: git commit -am "Postprocess docs for v${{ env.GDEXT_PUBLISHED_VERSION }}."
189+
run: git commit -am "Postprocess docs for v${{ env.GDEXT_PUBLISHED_VERSION }}"
177190

178-
- name: "Push changes"
179-
run: git push origin releases
191+
- name: "Push changes + tag version"
192+
run: |
193+
versionTag="v$GDEXT_PUBLISHED_VERSION"
194+
git tag "$versionTag"
195+
git push origin releases "$versionTag"
180196
181197
publish:
182198
runs-on: ubuntu-latest
199+
if: ${{ github.event.inputs.skip-release != 'y' }}
183200
# environment: 'Crates.io'
184201
needs:
185202
- docs-and-commit

0 commit comments

Comments
 (0)