-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nadav Ben Ami
authored and
Nadav Ben Ami
committed
Oct 8, 2024
1 parent
f073698
commit 04bc441
Showing
7 changed files
with
219 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: "Test Notebooks Action" | ||
description: "Runs tests on a list of notebooks based on the specified environment." | ||
|
||
inputs: | ||
# diff files - set to python inside pytest | ||
should_test_all_files: | ||
description: "'true' / 'false'." | ||
required: true | ||
list_of_ipynb_changed: | ||
description: "The list of changed files." | ||
required: true | ||
# aws environment | ||
is_dev: | ||
description: "The secret for environment authentication." | ||
required: true | ||
m2m_secret_arn: | ||
description: "The secret for environment authentication." | ||
required: true | ||
aws_role: | ||
description: "The AWS role to assume for configuring credentials during the execution." | ||
required: true | ||
# environment | ||
classiq_ide: | ||
description: "The secret for environment authentication." | ||
required: true | ||
classiq_host: | ||
description: "The secret for environment authentication." | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: ${{ inputs.aws_role }} | ||
aws-region: us-east-1 | ||
mask-aws-account-id: true | ||
|
||
- name: Set authentication | ||
run: .github/scripts/get_m2m_token.sh | ||
shell: bash | ||
env: | ||
IS_DEV: "${{ inputs.is_dev }}" | ||
M2M_SECRET_ARN: "${{ inputs.m2m_secret_arn }}" | ||
|
||
- name: Run Notebooks | ||
run: python -m pytest --log-cli-level=INFO tests | ||
env: | ||
JUPYTER_PLATFORM_DIRS: "1" | ||
SHOULD_TEST_ALL_FILES: "${{ inputs.should_test_all_files }}" | ||
LIST_OF_IPYNB_CHANGED: "${{ inputs.list_of_ipynb_changed }}" | ||
CLASSIQ_IDE: "${{ inputs.classiq_ide }}" | ||
CLASSIQ_HOST: "${{ inputs.classiq_host }}" | ||
|
||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
export SECRET_ARN=$M2M_SECRET_ARN | ||
if [ "$IS_DEV" = "true" ]; then | ||
aws codeartifact login --tool pip --domain classiq-cadmium --repository Pypi-Classiq-Non-Prod | ||
fi | ||
|
||
aws secretsmanager get-secret-value --secret-id "$SECRET_ARN" | \ | ||
jq '{"classiqTokenAccount": .SecretString | fromjson | .access_token }' > "${HOME}/.classiq-credentials" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
name: "Test notebooks" | ||
name: "Test notebooks old" | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
- name: "Install dependencies" | ||
run: | | ||
python -m pip install -U -r requirements.txt | ||
python -m pip install -U -r requirements_tests.txt | ||
|
||
- name: Get changed files - all | ||
id: changed-files-all | ||
|
@@ -26,26 +29,51 @@ jobs: | |
files: | | ||
**.ipynb | ||
- uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE }} | ||
aws-region: us-east-1 | ||
mask-aws-account-id: true | ||
|
||
- name: Set environment variables | ||
run: | | ||
set -ex | ||
echo "CLASSIQ_TEXT_ONLY=true" >> $GITHUB_ENV | ||
if [ "${{ github.event_name }}" == 'pull_request' ]; then | ||
echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV | ||
echo "HAS_ANY_FILE_CHANGED=${{ steps.changed-files-all.outputs.any_changed }}" >> $GITHUB_ENV | ||
echo "LIST_OF_FILE_CHANGED=${{ steps.changed-files-all.outputs.all_changed_files }}" >> $GITHUB_ENV | ||
echo "HAS_ANY_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.any_changed }}" >> $GITHUB_ENV | ||
echo "LIST_OF_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.all_changed_files }}" >> $GITHUB_ENV | ||
elif [ "${{ github.event_name }}" == 'workflow_dispatch' ]; then | ||
elif [[ "${{ github.event_name }}" == 'workflow_dispatch' || "${{ github.head_ref || github.ref_name }}" == "dev" ]]; then | ||
echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV | ||
echo "HAS_ANY_FILE_CHANGED=None" >> $GITHUB_ENV | ||
echo "LIST_OF_FILE_CHANGED=None" >> $GITHUB_ENV | ||
echo "HAS_ANY_IPYNB_CHANGED=None" >> $GITHUB_ENV | ||
echo "LIST_OF_IPYNB_CHANGED=None" >> $GITHUB_ENV | ||
fi | ||
if [ "${{ github.head_ref || github.ref_name }}" == "dev" ]; then | ||
echo "CLASSIQ_IDE=https://nightly.platform.classiq.io" >> $GITHUB_ENV | ||
echo "CLASSIQ_HOST=https://staging.api.classiq.io" >> $GITHUB_ENV | ||
echo "IS_DEV=true" >> $GITHUB_ENV | ||
fi | ||
- name: Set authentication | ||
run: echo "${{ secrets.CLASSIQ_CREDENTIALS_B64 }}" | base64 --decode > "${HOME}/.classiq-credentials" | ||
run: .github/scripts/get_m2m_token.sh | ||
env: | ||
PROD_M2M_SECRET_ARN: "${{ secrets.PROD_M2M_SECRET_ARN }}" | ||
NIGHTLY_M2M_SECRET_ARN: "${{ secrets.NIGHTLY_M2M_SECRET_ARN }}" | ||
|
||
- name: Install dependencies | ||
run: | | ||
set -e | ||
# Pre is needed for Dev pre releases | ||
python -m pip install --extra-index-url https://pypi.org/simple --pre -U -r requirements.txt | ||
python -m pip install --extra-index-url https://pypi.org/simple -U -r requirements_tests.txt | ||
- name: "Run tests" | ||
run: python -m pytest tests | ||
run: python -m pytest --log-cli-level=INFO tests | ||
env: | ||
JUPYTER_PLATFORM_DIRS: "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
name: Test Library CI | ||
|
||
on: | ||
# Trigger the workflow on push to the specific branch | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
- | ||
# 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. This has important security implications and should not be changed to `pull_request` | ||
# types: [opened, synchronize] # Triggered when PR is open or updated with new commit | ||
branches: | ||
- dev | ||
- main | ||
|
||
# Add a manual trigger option for running the workflow | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install dependencies | ||
run: | | ||
set -e | ||
# Pre is needed for Dev pre releases | ||
python -m pip install --extra-index-url https://pypi.org/simple --pre -U -r requirements.txt | ||
python -m pip install --extra-index-url https://pypi.org/simple -U -r requirements_tests.txt | ||
# A bunch of if-else. Might move to an action | ||
# Decide environment based on the target branch (for both push and PR events) | ||
- name: Set environment based on target branch | ||
run: | | ||
set -ex | ||
if [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
# Use the target branch of the pull request | ||
target_branch="${{ github.event.pull_request.base.ref }}" | ||
else | ||
# Use the branch of the push event | ||
# todo: verify that dispatch works | ||
target_branch="${{ github.ref_name }}" | ||
fi | ||
if [[ "$target_branch" == "main" ]]; then | ||
echo "Running on prod environment." | ||
echo "M2M_SECRET_ARN=${{ secrets.PROD_M2M_SECRET_ARN }}" >> $GITHUB_ENV | ||
echo "CLASSIQ_IDE=https://platform.classiq.io" >> $GITHUB_ENV | ||
echo "CLASSIQ_HOST=https://api.classiq.io" >> $GITHUB_ENV | ||
echo "IS_DEV=false" >> $GITHUB_ENV | ||
else | ||
echo "Running on dev environment." | ||
echo "M2M_SECRET_ARN=${{ secrets.NIGHTLY_M2M_SECRET_ARN }}" >> $GITHUB_ENV | ||
echo "CLASSIQ_IDE=https://nightly.platform.classiq.io" >> $GITHUB_ENV | ||
echo "CLASSIQ_HOST=https://staging.api.classiq.io" >> $GITHUB_ENV | ||
echo "IS_DEV=true" >> $GITHUB_ENV | ||
fi | ||
shell: bash | ||
|
||
# The following 2 steps can also be grouped into one action | ||
# Step to detect changed .ipynb files | ||
- name: Get changed notebook files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
files: | | ||
**/*.ipynb | ||
- name: Set changed notebook into environment variables | ||
run: | | ||
set -ex | ||
if [ "${{ github.event_name }}" == 'pull_request' ]; then | ||
echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV | ||
elif [[ "${{ github.event_name }}" == 'workflow_dispatch' || "${{ github.head_ref || github.ref_name }}" == "dev" ]]; then | ||
echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV | ||
fi | ||
# Run notebook tests if any changed notebooks are detected | ||
- name: Run notebook tests | ||
if: steps.changed-files.outputs.any_changed == 'true' | ||
uses: ./.github/actions/run-tests # Calls your composite action | ||
with: | ||
# diff files - set to python inside pytest | ||
should_test_all_files: ${{ env.SHOULD_TEST_ALL_FILES }} | ||
list_of_ipynb_changed: ${{ steps.changed-files-ipynb.outputs.all_changed_files }} | ||
# aws environment | ||
m2m_secret_arn: ${{ env.M2M_SECRET_ARN }} | ||
aws_role: ${{ secrets.AWS_ROLE }} | ||
is_dev: ${{ env.IS_DEV }} | ||
# environment | ||
classiq_ide: ${{ env.CLASSIQ_IDE }} | ||
classiq_host: ${{ env.CLASSIQ_HOST }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest | ||
|
||
testbook | ||
torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters