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
Links
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
Variable | Description | Example |
---|---|---|
AZURE_BLOB_CONNECTION_STRING | Azure blob connection string | |
AZURE_CREDENTIALS | Azure credentials | |
OPENAPI_SPECIFICATION_PATH | Azure blob connection string | Code/BackendAPI/backendApi.yaml |
OPENAPI_URL_PATH | Azure blob connection string | /v2 |
RESOURCE_GROUP | Azure blob connection string | similarity-detector |
API_MANAGEMENT_SERVICE_NAME | Azure blob connection string | apim-similarity-detector |
API_MANAGEMENT_API_ID | Azure blob connection string | apim-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
Links
- https://github.com/snok/install-poetry
- https://blog.dennisokeeffe.com/blog/2021-08-08-pytest-with-github-actions
- https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs-or-python?langId=py
- https://thiagolopessilva.medium.com/running-unit-testing-on-github-action-using-pytest-61653d993c9c
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
.
Links
- https://github.com/marketplace/actions/azure-blob-upload
- https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal#view-account-access-keys
- https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Storage%2FStorageAccounts
3 Execute act
Use act (https://github.com/nektos/act ) to run GitHub Actions locally.
Helpful commands:
Command | Description |
---|---|
act | Run workflows |
act -l | List workflows |
act -n | Run 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
Links
- https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
- https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onpushpull_requestpaths
- https://github.com/actions/setup-python
- https://github.com/marketplace/actions/azure-functions-action
- https://github.com/Azure/actions-workflow-samples/blob/master/FunctionApp/linux-python-functionapp-on-azure.yml