|
| 1 | +name: "Release workflow" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '!**' |
| 7 | + tags: |
| 8 | + # To include pre-releases: 'v0.1.[0-9]+-?*' |
| 9 | + - 'v0.1.[0-9]+' |
| 10 | + |
| 11 | +env: |
| 12 | + # Note: used for test and clippy, not for publish |
| 13 | + GDEXT_FEATURES: "--features godot/experimental-godot-api,godot/formatted,godot/serde" |
| 14 | + |
| 15 | + # Crates to publish -- important, this doesn't work when there are spaces in any of the paths! |
| 16 | + # Keep in sync with update-version.sh |
| 17 | + GDEXT_CRATES: > |
| 18 | + godot-bindings |
| 19 | + godot-codegen |
| 20 | + godot-ffi |
| 21 | + godot-cell |
| 22 | + godot-core |
| 23 | + godot-macros |
| 24 | + godot |
| 25 | +
|
| 26 | +defaults: |
| 27 | + run: |
| 28 | + shell: bash |
| 29 | + |
| 30 | +jobs: |
| 31 | + validation: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + # sed: https://unix.stackexchange.com/a/589584 |
| 37 | + - name: "Interpret tag version" |
| 38 | + run: | |
| 39 | + version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/v\(.*\)#\1#p") |
| 40 | + [ -z "$version" ] && { |
| 41 | + printf "\n::error::Failed to parse '$GITHUB_REF'.\n" |
| 42 | + exit 2 |
| 43 | + } |
| 44 | + |
| 45 | + echo "Published version: $version" |
| 46 | + echo "GDEXT_PUBLISHED_VERSION=$version" >> $GITHUB_ENV |
| 47 | +
|
| 48 | + - name: "Verify that Cargo.toml versions match ${{ env.GDEXT_PUBLISHED_VERSION }}" |
| 49 | + run: | |
| 50 | + echo "Checking crate versions..." |
| 51 | + |
| 52 | + # Check if each Cargo.toml has that version |
| 53 | + IFS=' ' read -r -a publishedCrates <<< "$GDEXT_CRATES" |
| 54 | + for crate in "${publishedCrates[@]}"; do |
| 55 | + readVersion=$(grep -Po '^version = "\K[^"]*' "$crate/Cargo.toml") |
| 56 | + printf "* $crate -> $readVersion" |
| 57 | + |
| 58 | + if [[ "$readVersion" != "$GDEXT_PUBLISHED_VERSION" ]]; then |
| 59 | + printf " ERROR\n" |
| 60 | + versionMismatch="1" |
| 61 | + else |
| 62 | + printf "\n" |
| 63 | + fi |
| 64 | + done |
| 65 | + |
| 66 | + if [[ -n "$versionMismatch" ]]; then |
| 67 | + printf "\n::error::At least one crate has a version mismatching the git tag.\n" |
| 68 | + exit 2 |
| 69 | + else |
| 70 | + printf "\nAll versions OK.\n" |
| 71 | + fi |
| 72 | +
|
| 73 | + # Keep all in sync with minimal-ci and full-ci. |
| 74 | + unit-test: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + needs: validation |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: "Install Rust (uncached)" |
| 81 | + run: rustup update stable |
| 82 | + |
| 83 | + - name: "Compile and run test" |
| 84 | + run: cargo test $GDEXT_FEATURES |
| 85 | + |
| 86 | + clippy: |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: validation |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + |
| 92 | + - name: "Install Rust (uncached)" |
| 93 | + run: rustup update stable |
| 94 | + |
| 95 | + - name: "Check clippy" |
| 96 | + run: | |
| 97 | + cargo clippy --all-targets $GDEXT_FEATURES -- \ |
| 98 | + -D clippy::suspicious \ |
| 99 | + -D clippy::style \ |
| 100 | + -D clippy::complexity \ |
| 101 | + -D clippy::perf \ |
| 102 | + -D clippy::dbg_macro \ |
| 103 | + -D clippy::todo \ |
| 104 | + -D clippy::unimplemented \ |
| 105 | + -D warnings |
| 106 | +
|
| 107 | + rustfmt: |
| 108 | + runs-on: ubuntu-latest |
| 109 | + needs: validation |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: "Install Rust (uncached)" |
| 114 | + run: rustup update stable |
| 115 | + |
| 116 | + - name: "Check rustfmt" |
| 117 | + run: cargo fmt --all -- --check |
| 118 | + |
| 119 | + - name: "Run custom repo checks" |
| 120 | + run: | |
| 121 | + cargo run -p repo-tweak |
| 122 | + git diff --quiet --exit-code || { |
| 123 | + echo "::error::Godot versions out of sync; update with `cargo run -p repo-tweak`." |
| 124 | + echo "Differences:" |
| 125 | + echo "----------------------------------------------------" |
| 126 | + git diff |
| 127 | + echo "----------------------------------------------------" |
| 128 | + exit 1 |
| 129 | + } |
| 130 | +
|
| 131 | + publish: |
| 132 | + runs-on: ubuntu-latest |
| 133 | +# environment: 'Crates.io' |
| 134 | + needs: |
| 135 | + - unit-test |
| 136 | + - clippy |
| 137 | + - rustfmt |
| 138 | + steps: |
| 139 | + # 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. |
| 140 | + # Sleep to leave crates.io and docs.rs some time to index the dependencies, before releasing dependents. |
| 141 | + - uses: actions/checkout@v4 |
| 142 | + |
| 143 | + - name: "Install Rust (uncached)" |
| 144 | + run: rustup update stable |
| 145 | + |
| 146 | + - name: "Execute crates.io publishing" |
| 147 | +# env: |
| 148 | +# CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} |
| 149 | + run: | |
| 150 | + IFS=' ' read -r -a publishedCrates <<< "$GDEXT_CRATES" |
| 151 | + for crate in "${publishedCrates[@]}"; do |
| 152 | + echo "Publish $crate..." |
| 153 | + (cd "$crate" && cargo publish --dry-run) || { |
| 154 | + printf "\n::error::Failed to publish $crate\n" |
| 155 | + exit 2 |
| 156 | + } |
| 157 | + echo "Wait..." |
| 158 | + sleep 10s |
| 159 | + done |
0 commit comments