ci: introduce `classify-pr.sh` script which determines whether a PR should have CI run
This commit is contained in:
parent
b93397d472
commit
9aca8a18c7
|
@ -14,9 +14,13 @@ jobs:
|
||||||
crates: ${{ steps.get_matrix.outputs.crates }}
|
crates: ${{ steps.get_matrix.outputs.crates }}
|
||||||
deps: ${{ steps.get_matrix.outputs.deps }}
|
deps: ${{ steps.get_matrix.outputs.deps }}
|
||||||
nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }}
|
nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }}
|
||||||
|
pr_changed_source: ${{ steps.classify_pr.outputs.pr_changed_source }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Crate
|
- name: Checkout Crate
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
- name: Determine what files the PR changes.
|
||||||
|
id: classify_pr
|
||||||
|
run: contrib/classify-pr.sh ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }}
|
||||||
- name: Read nightly version
|
- name: Read nightly version
|
||||||
id: read_toolchain
|
id: read_toolchain
|
||||||
run: echo "nightly_version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
|
run: echo "nightly_version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Usage: $0 <tip of master> <tip of PR>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pr_tip=$1
|
||||||
|
master_tip=$2
|
||||||
|
|
||||||
|
# When called on `pull_request`, GA fails to pull down master by default.
|
||||||
|
# When called on `push`, GA fails to pull down the PR by default, only its merge commit.
|
||||||
|
# The simplest way to deal with this is to just pull both explicitly.
|
||||||
|
git fetch origin "$master_tip":master_tip
|
||||||
|
git fetch origin "$pr_tip":pr_tip
|
||||||
|
|
||||||
|
pr_base=$(git merge-base master_tip pr_tip)
|
||||||
|
|
||||||
|
# If something modifies any non-markdown file, it's considered a source code change.
|
||||||
|
if git diff --name-only "$pr_base" "$pr_tip" | grep -qv "^.md$"; then
|
||||||
|
echo "pr_changed_source=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "pr_changed_source=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue