Skip to content

deploy_success

deploy_success #3076

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python Request API
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
repository_dispatch:
types: [ deploy_success ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to run tests against'
required: true
default: 'staging'
type: choice
options:
- staging
- production
- india
jobs:
set_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix-deploy.outputs.matrix || steps.set-matrix-manual.outputs.matrix || steps.set-matrix-default.outputs.matrix }}
steps:
- id: set-matrix-deploy
if: ${{ github.event_name == 'repository_dispatch' }}
run: |
echo "::set-output name=matrix::{\"environment\": [\"${{ github.event.client_payload.environment }}\"]}"
- id: set-matrix-manual
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "::set-output name=matrix::{\"environment\": [\"${{ inputs.environment }}\"]}"
- id: set-matrix-default
if: ${{ !contains(github.event_name , 'dispatch') }}
run: |
echo "::set-output name=matrix::{\"environment\": [\"production\", \"staging\",\"india\"]}"
build:
needs: set_matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set_matrix.outputs.matrix) }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.environment }}
cancel-in-progress: true
name: Request API on '${{ matrix.environment }}'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r RequestAPI/requirements.txt
- name: Requests API tests with pytest
env:
DIMAGIQA_ENV: ${{ matrix.environment }} #${{ secrets.DIMAGIQA_URL }}
DIMAGIQA_PASSWORD: ${{ secrets.DIMAGIQA_API_PASSWORD }}
DIMAGIQA_LOGIN_USER: ${{ secrets.DIMAGIQA_APILOGIN_USERNAME }}
DIMAGIQA_LOGIN_PASS: ${{ secrets.DIMAGIQA_APILOGIN_PASSWORD }}
DIMAGIQA_PROD_API_KEY: ${{secrets.DIMAGIQA_APIPROD_API_KEY}}
DIMAGIQA_STAGING_API_KEY: ${{secrets.DIMAGIQA_APISTAGING_API_KEY}}
DIMAGIQA_INDIA_API_KEY: ${{secrets.DIMAGIQA_INDIA_API_KEY}}
run: |
echo "client_payload: ${{ toJson(github.event.client_payload) }}"
echo "matrix environment: ${{ matrix.environment }}"
echo "NOW=$(date +'%m-%d %H:%M')" >> $GITHUB_ENV
echo ${{env.NOW}}
pytest -v --tb=short -n auto --dist=loadfile --reruns 1 --html=report_api_${{ matrix.environment }}.html --self-contained-html --rootdir= RequestAPI/testCases
- name: Send Failure Email
uses: dawidd6/action-send-mail@v3
if: failure()
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{secrets.DIMAGIQA_MAIL_USERNAME}}
password: ${{secrets.DIMAGIQA_MAIL_PASSWORD}}
subject: ${{ github.event.client_payload.environment }} FAIL - Request API Tests[#${{github.run_number}}] on branch "${{ github.ref_name }}", ${{env.NOW}}
to: qa@dimagi.com, sameena.shaik@fissionlabs.com, pruthvi.gottimukkula@fissionlabs.com
from: <${{secrets.DIMAGIQA_MAIL_USERNAME}}>
html_body: file:////home/runner/work/dimagi-qa/dimagi-qa/RequestAPI/email_fail.html
attachments: /home/runner/work/dimagi-qa/dimagi-qa/report_api_${{ matrix.environment }}.html
priority: normal
- name: Set slack vars
if: ${{ always() }}
id: configure_slack
uses: actions/github-script@v6
env:
JOB_STATUS: ${{ job.status }}
CC_ENV: ${{ matrix.environment }}
CC_EVENT: ${{ github.event_name }}
with:
result-encoding: string
script: |
const {CC_ENV, JOB_STATUS, CC_EVENT} = process.env
let SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
if (CC_EVENT == 'repository_dispatch' && CC_ENV == 'production') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_PROD_RESULTS }}'
console.log( "Prod deploy")
} else if (CC_EVENT != 'repository_dispatch' && CC_ENV == 'production' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
console.log( "Not Prod deploy but Prof failure")
} else if (CC_ENV == 'staging' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
console.log("Staging Failure")
} else if (CC_ENV == 'india' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_INDIA }}'
console.log("India Failure")
}else if (CC_ENV == 'india' && JOB_STATUS == 'success') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_INDIA }}'
console.log("India Success")
}else {
SLACK_WEBHOOK_URL = ' '
console.log("No notification sent")
}
return SLACK_WEBHOOK_URL
- name: Post to Slack channel on Failure
id: slack-api-staging-fail
uses: slackapi/slack-github-action@v1.23.0
if: ${{ steps.configure_slack.outputs.result != ' ' && failure() }}
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": " Hola 👋 \n*${{ github.workflow }}* were just triggered!"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Environment: *\n ${{ matrix.environment }} \n"
},
{
"type": "mrkdwn",
"text": " "
},
{
"type": "mrkdwn",
"text": "*Status: *\n ${{ job.status }} :x:"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here's the corresponding workflow execution :arrow_right::arrow_right:"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View on Github",
"emoji": true
},
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "button-action",
"style": "danger"
}
}
]
}
parse-json-secrets: true
env:
SLACK_WEBHOOK_URL: ${{ steps.configure_slack.outputs.result }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: Post to Slack channel on Success
id: slack-api-staging-pass
uses: slackapi/slack-github-action@v1.23.0
if: ${{ steps.configure_slack.outputs.result != ' ' && success() }}
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": " Hola 👋 \n*${{ github.workflow }}* were just triggered!"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Environment: *\n ${{ matrix.environment }} \n"
},
{
"type": "mrkdwn",
"text": " "
},
{
"type": "mrkdwn",
"text": "*Status: *\n ${{ job.status }} :white_check_mark:"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here's the corresponding workflow execution :arrow_right::arrow_right:"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View on Github",
"emoji": true
},
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "button-action",
"style": "primary"
}
}
]
}
parse-json-secrets: true
env:
SLACK_WEBHOOK_URL: ${{ steps.configure_slack.outputs.result }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: Archive test results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-result-reports
path: /home/runner/work/dimagi-qa/dimagi-qa/report_api_${{ matrix.environment }}.html
retention-days: 2