Skip to content

Commit 3650775

Browse files
authored
added ref: github.event.pull_request.head.sha to actions checkout in order to better deal with PR from fork (#855)
1 parent 154b89b commit 3650775

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

.github/workflows/check_license_and_history.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Check License and History
22

3-
on: # this workflow is planned to be called by the ci_pipeline and it will compare the PR files with the main
3+
on:
44
workflow_call:
55
workflow_dispatch:
66
push:
@@ -17,27 +17,23 @@ jobs:
1717
uses: actions/checkout@v3
1818
with:
1919
fetch-depth: 0
20+
ref: ${{ github.event.pull_request.head.sha }}
2021
- name: Get changed files
2122
id: changes
2223
run: |
23-
echo ${{github.event.pull_request.head.repo.full_name}}
24-
if [ "${{ github.event.pull_request.head.repo.full_name }}" == "speedb-io/speedb" ]; then
25-
echo "files added or changed in a PR that came from the speedb repo: "
26-
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md'
27-
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
28-
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
29-
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
30-
echo "EOF" >> $GITHUB_OUTPUT
31-
else
32-
echo "added or changed files: "
33-
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md'
34-
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
35-
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
36-
echo "EOF" >> $GITHUB_OUTPUT
37-
fi
24+
echo "files added or changed in a PR: "
25+
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md'
26+
echo "added or changed files: "
27+
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md'
28+
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
29+
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
30+
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
31+
echo "EOF" >> $GITHUB_OUTPUT
32+
3833
- name: list new files
3934
run: |
4035
echo "New files in this PR ${{ steps.changes.outputs.diff_list }}"
36+
4137
lint:
4238
runs-on: ubuntu-latest
4339
needs: changedfiles
@@ -48,6 +44,7 @@ jobs:
4844
uses: actions/checkout@v3
4945
with:
5046
fetch-depth: 0
47+
ref: ${{ github.event.pull_request.head.sha }}
5148
- name: Check License
5249
run: |
5350
exit_code=0
@@ -59,7 +56,6 @@ jobs:
5956
done
6057
exit $exit_code
6158
- name: Check HISTORY PR
62-
if: github.event.pull_request.head.repo.full_name == 'speedb-io/speedb'
6359
run: |
6460
set +e
6561
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}|grep -v "\.github" |grep -q [a-z,A-Z]
@@ -91,4 +87,4 @@ jobs:
9187
exit $history_not_in
9288
fi
9389
echo "No files were added"
94-
exit 0
90+
exit 0

0 commit comments

Comments
 (0)