Merge pull request #101 from jonico/allianz-more-efficient-automation #153
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: Postman Governance checks on branch | |
on: push | |
jobs: | |
governance-tests: | |
name: Governance checks and staging | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get first example of company id in /companies/{:id} endpoint | |
id: get_first_example | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq '.paths.["/companies/{companyId}"].get.responses.'200'.content.application/json.example.id' postman/schemas/index.yaml | |
# get all materials possible for material query paramter of /companies/{:id} endpoint | |
- name: Get all possible materials for material query parameter | |
id: get_all_materials | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq '.paths.["/companies/{companyId}"].get.parameters[] | select (.name == "material").schema.enum[]' postman/schemas/index.yaml | |
- name: Get all examples of companies endpoint | |
id: get_all_examples | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq '.paths./companies.get.responses.'200'.content.application/json.example[].id' postman/schemas/index.yaml | |
- name: Check if first company example is in all examples list | |
run: | | |
echo "First example in /companies/{:id} endpoint : ${{ steps.get_first_example.outputs.result }}" | |
echo "All examples: ${{ steps.get_all_examples.outputs.result }}" | |
if [[ "${{ steps.get_all_examples.outputs.result }}" =~ "${{ steps.get_first_example.outputs.result }}" ]]; then | |
echo "First example is in all examples list" | |
else | |
echo "First example is not in all examples list" | |
exit 1 | |
fi | |
- name: Check if all company examples are in data/companies.csv | |
if: false | |
run: | | |
allCompanies=$(cat data/companies.csv) | |
allExamples="${{ steps.get_all_examples.outputs.result }}" | |
echo "All companies in data/companies.csv: $allCompanies" | |
for company in $allExamples; do | |
if [[ "$allCompanies" =~ "$company" ]]; then | |
echo "Company $company is in data/companies.csv" | |
else | |
echo "Company $company is not in data/companies.csv" | |
exit 1 | |
fi | |
done | |
- name: Check if all materials are in data/companies.csv | |
if: false | |
run: | | |
allCompanies=$(cat data/companies.csv) | |
allMaterials="${{ steps.get_all_materials.outputs.result }}" | |
echo "All companies in data/companies.csv: $allCompanies" | |
for material in $allMaterials; do | |
if [[ "$allCompanies" =~ "$material" ]]; then | |
echo "Material $material is in data/companies.csv" | |
else | |
echo "Material $material is not in data/companies.csv" | |
exit 1 | |
fi | |
done | |
- name: Install Postman CLI | |
run: | | |
curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh | |
- name: Login to Postman CLI | |
run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }} | |
- name: Run Mock API tests on preview mock server if branch is not main | |
if: github.ref != 'refs/heads/main' | |
run: postman collection run "${{ github.workspace }}/postman/collections/Governance Checks.json" -e "${{ secrets.POSTMAN_ENV_MOCK }}" --integration-id "${{vars.POSTMAN_INTEGRATION_ID}}-${{ github.run_id }}" --iteration-data "data/companies.csv" | |
- name: Run Mock API tests on staging mock server if branch is main | |
if: github.ref == 'refs/heads/main' | |
run: postman collection run "${{ github.workspace }}/postman/collections/Governance Checks.json" -e "${{ secrets.POSTMAN_ENV_MOCK_STAGING }}" --integration-id "${{vars.POSTMAN_INTEGRATION_ID}}-${{ github.run_id }}" --iteration-data "data/companies.csv" | |
- name: Check API for security and compliance | |
run: postman api lint --integration-id ${{vars.POSTMAN_INTEGRATION_ID}} | |
# if branch is main, wait for staging environment to be ready | |
- name: Wait for staging env to be ready | |
if: github.ref == 'refs/heads/main' | |
uses: jonico/wait-for-deployment-action@v3 | |
id: deployment | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
environment: aippealing-companies-staging | |
timeout: 60 | |
interval: 3 | |
# if branch is main, run contract tests on staging environment | |
- name: Run Contract tests on staging env | |
if: github.ref == 'refs/heads/main' | |
run: | | |
postman collection run "${{ github.workspace }}/postman/collections/(Generator) Contract Tests - OAS3.json" --integration-id "${{vars.POSTMAN_INTEGRATION_ID}}-${{ github.run_id }}" -e "${{ secrets.POSTMAN_ENV_CONTRACT_TESTING }}" --env-var "env-server=https://aippealing-companies-staging.herokuapp.com" | |
# if branch is main, run integration tests on staging environment | |
- name: Run Integration tests on staging env | |
if: github.ref == 'refs/heads/main' | |
run: | | |
postman collection run "${{ secrets.POSTMAN_INTEGRATION_TESTS_COLLECTION }}" -e "${{ secrets.POSTMAN_ENV_STAGING }}" --iteration-data "data/companies.csv" | |