Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 18 additions & 50 deletions .github/workflows/Test-CI-main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: "Test Library CI (main)"

# 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
# PRs from users (should be from a fork) need to targePrint repository namet `main` branch which runs against `prod` environment

on:
push: # Trigger the workflow on push to the specific branch
push:
branches:
- main
pull_request_target: # Trigger the workflow on pull requests targeting the specific branch
pull_request_target:
# Note: `pull_request_target` ensures that the tests run in the context of the `main` branch, not in the user's fork.
branches:
- main
Expand All @@ -26,62 +23,33 @@

runs-on: ubuntu-latest

env:
# Previosly we had:
# if workflow_dispatch: True
# if pull_request_target: False
# if push: nothing, which translates to False
SHOULD_TEST_ALL_FILES: ${{ github.event_name == 'workflow_dispatch' }}

steps:
#
# Setup Repository
#
- name: Checkout repository
- name: Checkout (push / workflow_dispatch)
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v4

- name: Checkout the target branch
id: checkout
run: |
set -ex

# Debugging: initial git status
echo "==== Git status before checkout ===="
git status

# Handle different GitHub Actions events
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "Handling pull_request_target event"
echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV

if [ "$REPO_NAME" != "${{ github.repository }}" ]; then
echo "PR from a fork detected. Checking out the fork's branch."
git remote add fork "https://github.com/$REPO_NAME.git"
git fetch fork "$BRANCH_NAME"
git checkout -B ci-testing-branch FETCH_HEAD # Tested code is comming from this branch (contributer's)
else
echo "PR from the same repository detected. Checking out the branch."
git fetch origin "$BRANCH_NAME"
git checkout "$BRANCH_NAME"
fi

elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Handling workflow_dispatch event: No checkout needed"
echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV
echo "list_of_ipynb_changed=**/*.ipynb" >> $GITHUB_ENV

elif [[ "${{ github.event_name }}" == "push" ]]; then
echo "Handling push event: No checkout needed"

else
echo "Unsupported event type: ${github.event_name}. Exiting."
exit 1
fi

# Debugging: final git status
echo "==== Git status after checkout ===="
git status
env:
REPO_NAME: "${{ github.event.pull_request.head.repo.full_name }}"
BRANCH_NAME: "${{ github.event.pull_request.head.ref }}"
- name: Checkout PR head (pull_request_target)
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false

#
# Setup Python
#
- name: Set up Python

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context High

Potential execution of untrusted code on a privileged workflow (
pull_request_target
)
uses: actions/setup-python@v5
with:
python-version: "3.11"
Expand Down