Skip to content

Commit

Permalink
added ref: github.event.pull_request.head.sha to actions checkout in …
Browse files Browse the repository at this point in the history
…order to better deal with PR from fork (#855)
  • Loading branch information
maxb-io authored Feb 29, 2024
1 parent 154b89b commit 3650775
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions .github/workflows/check_license_and_history.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Check License and History

on: # this workflow is planned to be called by the ci_pipeline and it will compare the PR files with the main
on:
workflow_call:
workflow_dispatch:
push:
Expand All @@ -17,27 +17,23 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Get changed files
id: changes
run: |
echo ${{github.event.pull_request.head.repo.full_name}}
if [ "${{ github.event.pull_request.head.repo.full_name }}" == "speedb-io/speedb" ]; then
echo "files added or changed in a PR that came from the speedb repo: "
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md'
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "added or changed files: "
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md'
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
echo "files added or changed in a PR: "
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md'
echo "added or changed files: "
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md'
echo "diff_list<<EOF" >> $GITHUB_OUTPUT
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: list new files
run: |
echo "New files in this PR ${{ steps.changes.outputs.diff_list }}"
lint:
runs-on: ubuntu-latest
needs: changedfiles
Expand All @@ -48,6 +44,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Check License
run: |
exit_code=0
Expand All @@ -59,7 +56,6 @@ jobs:
done
exit $exit_code
- name: Check HISTORY PR
if: github.event.pull_request.head.repo.full_name == 'speedb-io/speedb'
run: |
set +e
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]
Expand Down Expand Up @@ -91,4 +87,4 @@ jobs:
exit $history_not_in
fi
echo "No files were added"
exit 0
exit 0

0 comments on commit 3650775

Please sign in to comment.