11name : " Test Library CI (main)"
22
3- # This workflow always run in the context of Classiq/classiq-library (base repo) but might use a branch from a fork to test its contribution
4- # PRs from users (should be from a fork) need to targePrint repository namet `main` branch which runs against `prod` environment
5-
63on :
7- push : # Trigger the workflow on push to the specific branch
4+ push :
85 branches :
96 - main
10- pull_request_target : # Trigger the workflow on pull requests targeting the specific branch
7+ pull_request_target :
118 # Note: `pull_request_target` ensures that the tests run in the context of the `main` branch, not in the user's fork.
129 branches :
1310 - main
@@ -26,57 +23,28 @@ jobs:
2623
2724 runs-on : ubuntu-latest
2825
26+ env :
27+ # Previosly we had:
28+ # if workflow_dispatch: True
29+ # if pull_request_target: False
30+ # if push: nothing, which translates to False
31+ SHOULD_TEST_ALL_FILES : ${{ github.event_name == 'workflow_dispatch' }}
32+
2933 steps :
3034 #
3135 # Setup Repository
3236 #
33- - name : Checkout repository
37+ - name : Checkout (push / workflow_dispatch)
38+ if : github.event_name != 'pull_request_target'
3439 uses : actions/checkout@v4
3540
36- - name : Checkout the target branch
37- id : checkout
38- run : |
39- set -ex
40-
41- # Debugging: initial git status
42- echo "==== Git status before checkout ===="
43- git status
44-
45- # Handle different GitHub Actions events
46- if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
47- echo "Handling pull_request_target event"
48- echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV
49-
50- if [ "$REPO_NAME" != "${{ github.repository }}" ]; then
51- echo "PR from a fork detected. Checking out the fork's branch."
52- git remote add fork "https://github.com/$REPO_NAME.git"
53- git fetch fork "$BRANCH_NAME"
54- git checkout -B ci-testing-branch FETCH_HEAD # Tested code is comming from this branch (contributer's)
55- else
56- echo "PR from the same repository detected. Checking out the branch."
57- git fetch origin "$BRANCH_NAME"
58- git checkout "$BRANCH_NAME"
59- fi
60-
61- elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
62- echo "Handling workflow_dispatch event: No checkout needed"
63- echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV
64- echo "list_of_ipynb_changed=**/*.ipynb" >> $GITHUB_ENV
65-
66- elif [[ "${{ github.event_name }}" == "push" ]]; then
67- echo "Handling push event: No checkout needed"
68-
69- else
70- echo "Unsupported event type: ${github.event_name}. Exiting."
71- exit 1
72- fi
73-
74- # Debugging: final git status
75- echo "==== Git status after checkout ===="
76- git status
77- env :
78- REPO_NAME : " ${{ github.event.pull_request.head.repo.full_name }}"
79- BRANCH_NAME : " ${{ github.event.pull_request.head.ref }}"
41+ - name : Checkout PR head (pull_request_target)
42+ if : github.event_name == 'pull_request_target'
43+ uses : actions/checkout@v4
44+ with :
45+ repository : ${{ github.event.pull_request.head.repo.full_name }}
46+ ref : ${{ github.event.pull_request.head.sha }}
47+ persist-credentials : false
8048
8149 #
8250 # Setup Python
0 commit comments