forked from arcaneframework/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (101 loc) · 4.26 KB
/
Copy pathheader_check.yml
File metadata and controls
125 lines (101 loc) · 4.26 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Header/Encoding/Git checker
on:
pull_request:
branches: [ main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
env:
# Arcane
ARCANE_SOURCE_DIR: '/home/runner/work/framework/framework/arcane'
jobs:
check-headers:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
path: ${{ env.ARCANE_SOURCE_DIR }}
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Get hash commits
shell: bash
run: |
cd ${{ env.ARCANE_SOURCE_DIR }}
MY_COMMIT=$(git rev-parse HEAD)
echo "My commit : $MY_COMMIT"
echo "MY_COMMIT=${MY_COMMIT}" >> $GITHUB_ENV
PARENT_BRANCH="$(git rev-parse origin/main)"
echo "Parent branch : $PARENT_BRANCH"
echo "PARENT_BRANCH=${PARENT_BRANCH}" >> $GITHUB_ENV
if [[ $MY_COMMIT == $PARENT_BRANCH ]]; then
echo "Already on the parent branch, exit"
exit 0
fi
COMMON_COMMIT=$(git merge-base $PARENT_BRANCH $MY_COMMIT)
if [[ $MY_COMMIT == $COMMON_COMMIT ]]; then
echo "Already merged branch"
FIRST_MERGE_AFTER_MY_BRANCH=$(git rev-list --merges "$MY_COMMIT..$PARENT_BRANCH" | tail -1)
echo "First merge after my branch : $FIRST_MERGE_AFTER_MY_BRANCH"
COMMON_COMMIT=$(git rev-parse "$FIRST_MERGE_AFTER_MY_BRANCH^")
else
echo "Not merged branch"
fi
echo "Common commit : $COMMON_COMMIT"
echo "COMMON_COMMIT=${COMMON_COMMIT}" >> $GITHUB_ENV
- name: Merge detection
id: merge-detection
if: "${{ env.MY_COMMIT != env.PARENT_BRANCH }}"
shell: bash
run: |
cd ${{ env.ARCANE_SOURCE_DIR }}
git log --merges --oneline --ancestry-path "${{ env.COMMON_COMMIT }}..${{ env.MY_COMMIT }}" > merge.log
if [ -s merge.log ]; then
echo "::error::Merge main into your branch detected. Use rebase instead (see commands to fix it in this section)."
echo "::group::Commit :"
cat merge.log
echo "::endgroup::"
echo "::group::Commands to fix it (local changes) :"
echo "# Save your current working tree."
echo "git stash"
echo " "
echo "# Fetch from origin and update your branch."
echo "git pull"
echo " "
echo "# Rebase branch to main."
echo "git rebase --no-rebase-merges origin/main"
echo " "
echo "# Get your working tree back."
echo "git stash pop"
echo " "
echo "# Check your local new branch before git push -f !"
echo "::endgroup::"
exit 1
fi
- name: Check files
id: check-files
if: "${{ always() && env.MY_COMMIT != env.PARENT_BRANCH }}"
shell: bash
run: |
cd ${{ env.ARCANE_SOURCE_DIR }}
export CC_H_FILES=$(git diff --name-only --no-renames --diff-filter=a "${{ env.MY_COMMIT }}..${{ env.COMMON_COMMIT }}" -- '*.cc' '*.h')
echo "::group::Files to check :"
echo "$CC_H_FILES"
echo "::endgroup::"
echo "::notice::In case of error, see the section 'Error details of Check files step' or the artifact 'Header Check Logs'."
chmod u+x ${{ env.ARCANE_SOURCE_DIR }}/.github/scripts/header_check.sh
${{ env.ARCANE_SOURCE_DIR }}/.github/scripts/header_check.sh > ${{ env.ARCANE_SOURCE_DIR }}/output.log
- name: Error details of Check files step
if: ${{ failure() && steps.check-files.conclusion == 'failure' }}
shell: bash
run: |
cat ${{ env.ARCANE_SOURCE_DIR }}/output.log
- name: Upload the logs artifact
uses: actions/upload-artifact@v6
if: ${{ failure() && steps.check-files.conclusion == 'failure' }}
with:
name: Header Check Logs
path: ${{ env.ARCANE_SOURCE_DIR }}/output.log
retention-days: 7