Wwi21/32 e2e testing #821
Workflow file for this run
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 is a basic workflow to help you get started with Actions | |
name: Continious Integration | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
pull_request: | |
branches: [main] | |
types: [synchronize, opened, reopened] | |
workflow_dispatch: | |
env: | |
PYTHON_VERSION: '3.12' | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
build-and-test: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
function: | |
- name: health | |
entry_point: "get_health" | |
source_dir: "src/health" | |
description: "[CANARY] Health status endpoint." | |
- name: transform | |
entry_point: "post_transform" | |
source_dir: "src/transform" | |
description: "[CANARY] Transformation endpoint." | |
set_force_std_xml: true | |
- name: checkTokens | |
entry_point: "check_tokens" | |
source_dir: "src/checkTokens" | |
description: "[CANARY] Check Tokens endpoint." | |
# Add "id-token" with the intended permissions. | |
permissions: | |
contents: "read" | |
id-token: "write" | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Set relevant environment variables | |
- name: Set environment variables | |
run: | | |
PIPELINE_TIMESTAMP=$(date +%Y%m%d%H%M%S) | |
echo "PIPELINE_TIMESTAMP=$PIPELINE_TIMESTAMP" >> $GITHUB_ENV | |
echo "CANARY_FUNCTION_NAME=CANARY_${{ matrix.function.name }}_${{ github.event.pull_request.number || 'manual' }}_$PIPELINE_TIMESTAMP" >> $GITHUB_ENV | |
echo "GCP_SERVICE_ACCOUNT_CERTIFICATE=${{ secrets.GCP_SERVICE_ACCOUNT_CERTIFICATE }}" >> $GITHUB_ENV | |
# Set FORCE_STD_XML for transform function only if the flag exists and is true | |
- name: Set FORCE_STD_XML if required | |
if: matrix.function.set_force_std_xml == true | |
run: echo "FORCE_STD_XML=true" >> $GITHUB_ENV | |
- name: Set FORCE_STD_XML_ENV_KV_PAIR | |
run: | | |
if [ "${{ matrix.function.set_force_std_xml }}" == "true" ]; then | |
echo "FORCE_STD_XML_ENV_KV_PAIR=FORCE_STD_XML=true" >> $GITHUB_ENV | |
else | |
echo "FORCE_STD_XML_ENV_KV_PAIR=" >> $GITHUB_ENV | |
fi | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: "actions/checkout@v4" | |
# Setting up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: 'pip' | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
# Linting | |
- name: Linting check | |
run: ruff check . | |
# Run Unit Tests | |
- name: Run Unit tests | |
run: | | |
cd ${{ matrix.function.source_dir }} | |
python -m pytest tests/unit -v | |
cd ../.. | |
# Authenticating at GCP | |
# see https://github.com/google-github-actions/deploy-cloud-functions | |
- id: "auth" | |
name: "Authenticate to Google Cloud" | |
uses: "google-github-actions/auth@v2" | |
with: | |
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
# Deploy Canary Function | |
- id: "deploy" | |
name: "Deploy Canary Function" | |
uses: "google-github-actions/deploy-cloud-functions@v2" | |
with: | |
name: ${{ env.CANARY_FUNCTION_NAME }} | |
entry_point: ${{ matrix.function.entry_point }} | |
source_dir: ${{ matrix.function.source_dir }} | |
runtime: "python312" | |
region: "europe-west3" | |
description: ${{ matrix.function.description }} | |
env_vars: ${{ env.FORCE_STD_XML_ENV_KV_PAIR }},GCP_SERVICE_ACCOUNT_CERTIFICATE=${{ secrets.GCP_SERVICE_ACCOUNT_CERTIFICATE }} | |
# Authenticating at GCP to get id token for deployed function | |
# see https://github.com/google-github-actions/deploy-cloud-functions | |
- id: "authidtoken" | |
name: "Authenticate to Google Cloud to get id token" | |
uses: "google-github-actions/auth@v2" | |
with: | |
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
token_format: "id_token" | |
id_token_audience: ${{ steps.deploy.outputs.url }} | |
# Set Canary url as environment variable | |
- name: Set URL of deployed canary function as env variable | |
run: | | |
echo "E2E_URL=$(echo ${{ steps.deploy.outputs.url }})" >> $GITHUB_ENV | |
echo "E2E_IDENTITY_TOKEN=$(echo ${{ steps.authidtoken.outputs.id_token }})" >> $GITHUB_ENV | |
# Run e2e Tests against Canary Function | |
- name: Run e2e tests | |
run: | | |
cd ${{ matrix.function.source_dir }} | |
python -m pytest tests/e2e -v | |
cd ../.. | |
# Remove Canary Function | |
- name: Remove Canary Function | |
if: always() | |
run: | | |
gcloud functions delete ${{ env.CANARY_FUNCTION_NAME }} --region europe-west3 --quiet |