Skip to content

Feature database dev #101

Feature database dev

Feature database dev #101

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- "**" # Match all branches
pull_request:
branches:
- "**" # Match all branches
jobs:
lint:
name: Run Ruff Linting
runs-on: ubuntu-latest
steps:
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3
#with:
# submodules: recursive
# Step 2
- name: Debug Secrets
run: echo "${{ secrets.SSH_PRIVATE_KEY }}" | wc -c
# Step 3: Set up SSH key
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
- name: Set branch name
id: branch_ruff
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, use the head branch name
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_OUTPUT
else
# For pushes, use the branch name
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
# Step 2: Build the Docker container
- name: Build Docker container for Ruff
run: |
docker build -f Dockerfile.base \
--build-arg SSH_PRIVATE_KEY="${{ secrets.SSH_PRIVATE_KEY }}" \
--build-arg GIT_BRANCH="${{ steps.branch_ruff.outputs.BRANCH_NAME }}" \
-t assas-database-ruff .
# Step 3: Run Ruff linting inside the Docker container
- name: Run Ruff
run: |
docker run --rm assas-database-ruff \
ruff check . --exclude /app/test/dev_test/
test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Set branch name
id: branch_test
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, use the head branch name
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_OUTPUT
else
# For pushes, use the branch name
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Build the Docker container for Unit Tests
- name: Build Docker container for Unit Tests
run: |
docker build -f Dockerfile.test \
--build-arg SSH_PRIVATE_KEY="${{ secrets.SSH_PRIVATE_KEY }}" \
--build-arg LSDF_USER="${{ secrets.LSDF_USER }}" \
--build-arg LSDF_PWD="${{ secrets.LSDF_PWD }}" \
--build-arg GIT_BRANCH="${{ steps.branch_test.outputs.BRANCH_NAME }}" \
-t assas-database-test .
# NEW: Create an env file for docker run (from GitHub Secrets)
- name: Create env file for tests
shell: bash
run: |
cat > .env.ci <<EOF
BACKUP_DIRECTORY=/app/backup_mongodb
UPLOAD_DIRECTORY=/app/upload_test
CONNECTIONSTRING=${{ secrets.MONGO_CONNECTIONSTRING }}
MONGO_DB_NAME=${{ secrets.MONGO_DB_NAME }}
USER_COLLECTION_NAME=users
FILE_COLLECTION_NAME=files
ASTEC_TYPE=linux_64
ASTEC_ROOT=/app/astecV3.1.2
EOF
# Step 3: Run tests in Docker container (use --env-file)
- name: Run tests in Docker container
run: |
docker run --rm \
--env-file ./.env.ci \
assas-database-test \
bash -c "python3.11 test/test_astec_archive.py && \
python3.11 test/test_database_handler.py && \
python3.11 test/test_document_file.py && \
python3.11 test/test_database_manager.py && \
python3.11 test/test_conversion_handler.py && \
python3.11 test/test_odessa_netcdf4_converter.py"