Update cloudbuild.yaml #66
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
name: Python Test Workflow | |
on: | |
push: | |
branches: | |
- main | |
- citest | |
jobs: | |
test: | |
runs-on: ubuntu-22.04 | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
# Step 2: Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r pipeline/requirements.txt | |
# Step 4: Run tests and generate coverage report | |
- name: Run tests | |
run: | | |
pip install coverage | |
coverage run -m pytest pipeline/airflow/tests --maxfail=2 --disable-warnings | |
coverage html | |
coverage xml | |
# Step 5: Upload coverage report as artifact | |
- name: Upload coverage report | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: htmlcov/ | |
# Step 6: Upload XML coverage report as artifact | |
- name: Upload XML coverage report | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report-xml | |
path: coverage.xml | |
# Step 7: Install Google Cloud CLI | |
- name: Install Google Cloud CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y google-cloud-cli | |
# Step 8: Decode GCP Service Account Key | |
- name: Decode and Write GCP Service Account Key | |
run: | | |
echo "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" | base64 -d > /tmp/gcp-key.json | |
shell: bash | |
# Step 9: Authenticate with GCP using the Temporary File | |
- name: Authenticate with GCP | |
env: | |
GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp-key.json | |
run: gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} | |
# Step 10: Set GCP Project ID | |
- name: Set GCP Project ID | |
run: gcloud config set project ${{ secrets.GCP_PROJECT_ID }} | |
# Step 11: Upload coverage reports to GCP bucket | |
- name: Upload coverage reports to GCP bucket | |
env: | |
GCS_BUCKET_NAME: ${{ secrets.GCS_BUCKET_NAME }} | |
run: | | |
CURRENT_DATE=$(date +"%Y-%m-%d") | |
zip -r coverage-report.zip htmlcov/ | |
gsutil -m cp coverage-report.zip gs://${GCS_BUCKET_NAME}/Pytest-reports/${CURRENT_DATE}/coverage-report.zip | |
gsutil cp coverage.xml gs://${GCS_BUCKET_NAME}/Pytest-reports/${CURRENT_DATE}/coverage.xml |