@@ -7,6 +7,12 @@ name: "Release workflow"
77
88on :
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 "GodotRust@users.noreply.github.com"
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