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