CI/CD


Content


Test GitHub Actions locally

1. Install act

Setup

# Homebrew (Linux/macOS)
brew install act

# MacPorts (macOS)
sudo port install act

# Chocolatey (Windows)
choco install act-cli

2. Set Environment Variables

Copy the file template.secrets to a file named .secrets and replace "<Please set this variable>" with the right variables.

Update OpenAPI

VariableDescriptionExample
AZURE_BLOB_CONNECTION_STRINGAzure blob connection string
AZURE_CREDENTIALSAzure credentials
OPENAPI_SPECIFICATION_PATHAzure blob connection stringCode/BackendAPI/backendApi.yaml
OPENAPI_URL_PATHAzure blob connection string/v2
RESOURCE_GROUPAzure blob connection stringsimilarity-detector
API_MANAGEMENT_SERVICE_NAMEAzure blob connection stringapim-similarity-detector
API_MANAGEMENT_API_IDAzure blob connection stringapim-similarity-detector-id

To get the AZURE_CREDENTIALS fill out the variables in the script create_credentials.sh and execute it.

Unit tests

Setup environment variables online in GitHub

gh secret set -f ./Code/BackendAPI/tests/unit/unit_tests.env

cd Code/BackendAPI/scripts && python env_github.py

Update OpenAPI

For update_openapi.yaml file set the environment variables as follows.

Get the Azure Blob Storage connection string from View account access keys. Copy it to the clipboard.

Execute:

# Paste secret value for the current repository in an interactive prompt
gh secret set AZURE_BLOB_CONNECTION_STRING

# Paste the connection string in the interactive prompt

Copy the new list of environment variables to the env section of the Run unit tests command in unit_tests.yaml.

3 Execute act

Use act (https://github.com/nektos/act ) to run GitHub Actions locally.

Helpful commands:

CommandDescription
actRun workflows
act -lList workflows
act -nRun dryrun
act -j <jobname>Select specific job
act --secret-file <secret file>Specify secret file for environment variables

Execute workflows (run from amos2021ws06-exp-similarity-detector directory)

# Execute job unit_tests with act
act --secret-file .secrets -j unit_tests

# Execute job build_and_deploy with act
act --secret-file .secrets -j build_and_deploy  

# Execute job integration_tests with act
act --secret-file .secrets -j integration_tests

# Execute job update_openapi with act
act --secret-file .secrets -j upload_openapi