Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/self hosted runner #145

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
106 changes: 8 additions & 98 deletions .github/workflows/shared_integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ concurrency:

jobs:
integration_tests:
runs-on: ubuntu-latest
runs-on: self-hosted

defaults:
run:
Expand All @@ -68,6 +68,7 @@ jobs:
CI_TEST_RAS_PASSWORD: ${{ secrets.CI_TEST_RAS_PASSWORD }}
CI_TEST_RAS_2_USERID: ${{ secrets.CI_TEST_RAS_2_USERID }}
CI_TEST_RAS_2_PASSWORD: ${{ secrets.CI_TEST_RAS_2_PASSWORD }}
HOSTNAME: "hara.dev.planx-pla.net"

steps:
# # Enable step debugging. Uncomment this to debug pipeline issues
Expand All @@ -89,101 +90,24 @@ jobs:
if: ${{ env.SKIP_TESTS != 'true' }}
uses: actions/checkout@v4

# Skip tests when there are only markdown files
- name: Skip integration tests if PR contains only Markdown files
if: ${{ env.SKIP_TESTS != 'true' }}
working-directory: ${{ github.workspace }}
run: |
git fetch -q
FILE_TYPES=$(git show --name-only ${{ env.COMMIT_SHA }} | grep -o '\S\+\.\S\+' | grep -v '@' | awk -F . '{print $NF}' | sort -u)
echo $FILE_TYPES

# Check if the only file type is markdown
if [[ "$FILE_TYPES" == "md" ]]; then
echo "All files are markdown, skipping step."
echo "SKIP_TESTS=true" >> $GITHUB_ENV
fi

# Checkout master branch of gen3-code-vigil when another repo is under test
- name: Checkout integration test code
if: ${{ env.SKIP_TESTS != 'true' && github.event.repository.name != 'gen3-code-vigil' }}
uses: actions/checkout@v4
with:
repository: uc-cdis/gen3-code-vigil
ref: master

# gen3-integration-tests run with python 3.9
- name: Set up Python
if: ${{ env.SKIP_TESTS != 'true' }}
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Set up Go
if: ${{ env.SKIP_TESTS != 'true' }}
uses: actions/setup-go@v5
with:
go-version: '1.17'

# allure report generation needs node
- name: Set up node
if: ${{ env.SKIP_TESTS != 'true' }}
uses: actions/setup-node@v4
with:
node-version: 20

# Install gen3-integration-tests dependencies
# wamerican: data-simulator needs "/usr/share/dict/words" to generate data that isn't random strings
- name: Install dependencies
if: ${{ env.SKIP_TESTS != 'true' }}
run: |
sudo apt-get install -y --reinstall wamerican
python -m pip install --upgrade pip
python3 -m pip install --upgrade pip
pip install poetry
poetry install
poetry show
poetry run playwright install chromium

- name: Get commit time
if: ${{ env.SKIP_TESTS != 'true' }}
run: |
commit_time=$(gh api repos/$REPO_FN/commits/$COMMIT_SHA | jq -r '.commit.committer.date')
echo "COMMIT_TIME=$commit_time" >> $GITHUB_ENV

# TODO: Rely on a database in AWS to make this faster
# Select an unlocked environment
# If an env is specified in a PR label use it, else pick one from the pool
- name: Select CI environment
if: ${{ env.SKIP_TESTS != 'true' }}
id: select_ci_env
run: |
env_label=$(gh api repos/$REPO_FN/pulls/$PR_NUM --jq '.labels | map(select(.name | startswith("jenkins-"))) | .[0].name')
echo "$env_label"
if [[ $env_label != "" && $env_label != null ]]; then
echo "Found PR label $env_label"
poetry run python -m gen3_ci.scripts.select_ci_environment $env_label
else
poetry run python -m gen3_ci.scripts.select_ci_environment
fi

# TODO: Improve the logic to do differential updates to the env, not roll all services
# Apply the changes to the manifest of the selected CI environment, roll the pods and run usersync
# Generate API keys for test users for the environment
- name: Prepare CI environment
id: prep_ci_env
if: ${{ env.SKIP_TESTS != 'true' && steps.select_ci_env.outcome == 'success' }}
continue-on-error: true # if this fails, we still need to run clean-up steps
run: |
mkdir $HOME/.gen3
poetry run python -m gen3_ci.scripts.prepare_ci_environment
env:
QUAY_REPO: ${{ inputs.QUAY_REPO }}

# This is used for running specific test suites by labeling the PR with the test class
# Multiple suites can be executed by adding multiple labels
- name: Get test labels
id: get_test_labels
if: ${{ env.SKIP_TESTS != 'true' && steps.prep_ci_env.outcome == 'success' }}
if: ${{ env.SKIP_TESTS != 'true' }}
continue-on-error: true # if this fails, we still need to run clean-up steps
run: |
test_label=$(gh api repos/$REPO_FN/pulls/$PR_NUM --jq '.labels | map(select(.name | startswith("Test"))) | map(.name) | if length > 0 then "-k \"" + join(" or ") + "\"" else "" end')
Expand All @@ -192,19 +116,19 @@ jobs:

- name: Run tests pertaining to specific service
id: run_service_tests
if: ${{ env.SKIP_TESTS != 'true' && inputs.SERVICE_TO_TEST && steps.prep_ci_env.outcome == 'success' }}
if: ${{ env.SKIP_TESTS != 'true' && inputs.SERVICE_TO_TEST }}
continue-on-error: true # if this fails, we still need to run clean-up steps
run: |
mkdir output
GEN3_INSTANCE_TYPE="ADMINVM_REMOTE" poetry run pytest -n auto -m "${{ inputs.SERVICE_TO_TEST }} and not wip" --alluredir allure-results --no-header --dist loadscope ${{ env.TEST_LABEL }}
GEN3_INSTANCE_TYPE="HELM_LOCAL" poetry run pytest -n auto -m "${{ inputs.SERVICE_TO_TEST }} and not wip" --alluredir allure-results --no-header --dist loadscope ${{ env.TEST_LABEL }}

- name: Run tests
id: run_tests
if: ${{ env.SKIP_TESTS != 'true' && !inputs.SERVICE_TO_TEST && steps.prep_ci_env.outcome == 'success' }}
if: ${{ env.SKIP_TESTS != 'true' && !inputs.SERVICE_TO_TEST }}
continue-on-error: true # if this fails, we still need to run clean-up steps
run: |
mkdir output
GEN3_INSTANCE_TYPE="ADMINVM_REMOTE" poetry run pytest -n auto -m "not wip" --alluredir allure-results --no-header --dist loadscope ${{ env.TEST_LABEL }}
GEN3_INSTANCE_TYPE="HELM_LOCAL" poetry run pytest -n auto -m "not wip" --alluredir allure-results --no-header --dist loadscope ${{ env.TEST_LABEL }}

- name: Debug logging
if: ${{ env.SKIP_TESTS != 'true' }}
Expand Down Expand Up @@ -280,17 +204,3 @@ jobs:
payload-file-path: "./gen3-integration-tests/slack_report.json"
env:
SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }}

- name: Release CI environment
id: release_ci_env
if: ${{ env.SKIP_TESTS != 'true' && steps.select_ci_env.outcome == 'success' || cancelled() }}
continue-on-error: true # if this fails, we still need to run clean-up steps
run: poetry run python -m gen3_ci.scripts.release_ci_environment

- name: Mark workflow as failed for unsuccessful test runs
if: ${{ env.SKIP_TESTS != 'true' && steps.run_service_tests.outcome != 'success' && steps.run_tests.outcome != 'success' }}
run: echo "Test run was unsuccessful, marking workflow as failed" && exit 1

- name: Stop pending jenkins jobs for cancelled run
if: ${{ env.SKIP_TESTS != 'true' && cancelled() }}
run: poetry run python -m gen3_ci.scripts.clean_up_jenkins
Loading