|
| 1 | +name: Run what-rust-changed |
| 2 | +description: Determines which rust projects in a workspace have changed |
| 3 | +inputs: |
| 4 | + base: |
| 5 | + description: "The base ref to use for comparisons. Usually the PR base or the before of a push" |
| 6 | + required: true |
| 7 | + config: |
| 8 | + description: "Optional config file for what-rust-changed" |
| 9 | + required: false |
| 10 | + version: |
| 11 | + description: "Which version of what-rust-changed to use. The default should usually suffice" |
| 12 | + required: false |
| 13 | + default: "v0.1.0" |
| 14 | +outputs: |
| 15 | + # These 2 are JSON lists (encoded as strings because github actions, sigh) |
| 16 | + blah: |
| 17 | + value: ${{ steps.what-rust-changed.outputs.rust }} |
| 18 | + changed-packages: |
| 19 | + description: A JSON list of the packages that have changed |
| 20 | + value: ${{ steps.what-rust-changed.outputs.changed-packages }} |
| 21 | + changed-binaries: |
| 22 | + description: A JSON list of the binaries that have changed |
| 23 | + value: ${{ steps.what-rust-changed.outputs.changed-binaries }} |
| 24 | + |
| 25 | + # These 4 are Strings |
| 26 | + cargo-build-specs: |
| 27 | + description: A string suitable for passing to cargo that builds all the changed packages |
| 28 | + value: ${{ steps.what-rust-changed.outputs.cargo-build-specs }} |
| 29 | + cargo-test-specs: |
| 30 | + description: A string suitable for passing to cargo test that includes all the changed packages but not the docker-tests |
| 31 | + value: ${{ steps.what-rust-changed.outputs.rust.cargo-test-specs }} |
| 32 | + cargo-docker-test-specs: |
| 33 | + description: A string suitable for passing to cargo test that includes all the changed packages including the docker-tests |
| 34 | + value: ${{ steps.what-rust-changed.outputs.cargo-docker-test-specs }} |
| 35 | + cargo-bin-specs: |
| 36 | + description: A string suitable for passing to cargo that builds all the changed binaries |
| 37 | + value: ${{ steps.what-rust-changed.outputs.cargo-bin-specs }} |
| 38 | + |
| 39 | +runs: |
| 40 | + using: "composite" |
| 41 | + steps: |
| 42 | + - name: Cargo cache |
| 43 | + uses: actions/cache@v4 |
| 44 | + continue-on-error: false |
| 45 | + with: |
| 46 | + key: what-rust-changed-${{ inputs.version }} |
| 47 | + save-always: true |
| 48 | + path: | |
| 49 | + ~/.local/what-rust-changed/ |
| 50 | +
|
| 51 | + # If you're iterating on this you may want to change this to a cargo install |
| 52 | + # while you work |
| 53 | + - name: Install what-rust-changed |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + if [ ! -f ~/.local/what-rust-changed/what-rust-changed ]; then |
| 57 | + mkdir -p ~/.local/what-rust-changed |
| 58 | + curl -L https://github.com/grafbase/what-rust-changed/releases/download/${{ inputs.version }}/what-rust-changed-x86_64-unknown-linux-gnu.tar.gz --output ~/.local/what-rust-changed/wrc.tar.gz |
| 59 | + cd ~/.local/what-rust-changed |
| 60 | + tar xfv wrc.tar.gz |
| 61 | + rm wrc.tar.gz |
| 62 | + fi |
| 63 | + echo "$HOME/.local/what-rust-changed" >> $GITHUB_PATH |
| 64 | +
|
| 65 | + - name: Run what-rust-changed |
| 66 | + id: what-rust-changed |
| 67 | + shell: bash |
| 68 | + env: |
| 69 | + WHAT_RUST_CHANGED_CONFIG: ${{ inputs.config }} |
| 70 | + BASE_REF: remotes/origin/${{ inputs.base }} |
| 71 | + run: | |
| 72 | + HEAD_REF=$(git rev-parse HEAD) |
| 73 | + set -euo pipefail |
| 74 | + echo "Head: $HEAD_REF" |
| 75 | + echo "Base: $BASE_REF" |
| 76 | + MERGE_BASE=$(git merge-base $BASE_REF $HEAD_REF) |
| 77 | + echo "Merge Base: $MERGE_BASE" |
| 78 | + git checkout $MERGE_BASE |
| 79 | + cargo metadata > /tmp/base.metadata.json |
| 80 | + git checkout $HEAD_REF |
| 81 | + cargo metadata --locked > /tmp/target.metadata.json |
| 82 | + CHANGED_FILES=$(git diff --no-commit-id --name-only -r $MERGE_BASE HEAD) |
| 83 | + CHANGES=$(echo $CHANGED_FILES | xargs what-rust-changed /tmp/base.metadata.json /tmp/target.metadata.json) |
| 84 | + echo "Changes: $CHANGES" |
| 85 | +
|
| 86 | + echo "rust=$CHANGES" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + echo "changed-packages=$(echo $CHANGES | jq -c .[\"changed-packages\"])" >> "$GITHUB_OUTPUT" |
| 89 | + echo "changed-binaries=$(echo $CHANGES | jq -c .[\"changed-binaries\"])" >> "$GITHUB_OUTPUT" |
| 90 | +
|
| 91 | + echo "cargo-build-specs=$(echo $CHANGES | jq -r .[\"cargo-build-specs\"])" >> "$GITHUB_OUTPUT" |
| 92 | + echo "cargo-test-specs=$(echo $CHANGES | jq -r .[\"cargo-test-specs\"])" >> "$GITHUB_OUTPUT" |
| 93 | + echo "cargo-docker-test-specs=$(echo $CHANGES | jq -r .[\"cargo-docker-test-specs\"])" >> "$GITHUB_OUTPUT" |
| 94 | + echo "cargo-bin-specs=$(echo $CHANGES | jq -r .[\"cargo-bin-specs\"])" >> "$GITHUB_OUTPUT" |
| 95 | +
|
| 96 | + - name: Debug shit |
| 97 | + shell: bash |
| 98 | + env: |
| 99 | + BLAH: ${{ steps.what-rust-changed.outputs.rust }} |
| 100 | + run: | |
| 101 | + echo $BLAH |
0 commit comments