-
Notifications
You must be signed in to change notification settings - Fork 120
63 lines (59 loc) · 2.28 KB
/
ci_submodule.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
name: CI for libsc check
on:
pull_request:
jobs:
linux-sub:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NODE_ID: ${{ github.event.pull_request.node_id }}
INPUT_PATH: sc
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: true
- name: Determine hashes to compare
shell: bash
run: |
EVENT_PATH="${GITHUB_EVENT_PATH}"
cd "${GITHUB_WORKSPACE}" \
|| error "__Line:${LINENO}__Error: Cannot change directory to Github Workspace"
echo "PR=`jq -r ".number" "${EVENT_PATH}"`" >> $GITHUB_ENV
PR_BRANCH=`jq -r ".pull_request.head.ref" "${EVENT_PATH}"`
BASE_BRANCH=`jq -r ".pull_request.base.ref" "${EVENT_PATH}"`
echo "Run for PR of ${PR_BRANCH} into ${BASE_BRANCH}"
echo "Fetch Branch Histories"
git fetch origin "${PR_BRANCH}" --recurse-submodules=no \
|| error "__Line:${LINENO}__Error: Could not fetch history of ${PR_BRANCH}"
git fetch origin "${BASE_BRANCH}" --recurse-submodules=no \
|| error "__Line:${LINENO}__Error: Could not fetch history of ${BASE_BRANCH}"
echo "TO_HASH=`git rev-parse origin/${PR_BRANCH}`" >> $GITHUB_ENV
echo "FROM_HASH=`git rev-parse origin/${BASE_BRANCH}`" >> $GITHUB_ENV
- name: Convert PR to draft if necessary
shell: bash
run: |
CHANGED=`git diff --name-only ${{ env.FROM_HASH }}...${{ env.TO_HASH }}`
if grep "^${INPUT_PATH}$" <<< "${CHANGED}"; then
echo "${TOKEN}" | gh auth login --with-token
gh pr comment ${PR} --body \
"Submodule has been changed by this PR. \
This is forbidden by the repository policy. \
Your PR is turned into a draft PR."
gh api graphql -F id="${PR_NODE_ID}" -f query='
mutation($id: ID!) {
convertPullRequestToDraft(input: { pullRequestId: $id }) {
pullRequest {
id
number
isDraft
}
}
}
'
echo "PR was converted to draft successfully."
exit 1
fi
echo "Success: submodule has not been changed."
exit 0