diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 6ff9b9a..93e104e 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -47,13 +47,20 @@ jobs: run: | git config --global init.defaultBranch main python -m pytest tests -o log_cli=true -vv --python_version ${{ matrix.python-version }} + + notify: + + needs: build + if: ${{ failure() && github.event_name != 'workflow_dispatch' }} + runs-on: ubuntu-latest + + steps: - name: Send status to Slack app - if: ${{ failure() && github.event_name != 'workflow_dispatch' }} id: slack uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 with: webhook: ${{ secrets.SLACK_WEBHOOK_URL }} - webhook-type: webhook-trigger + webhook-type: incoming-webhook payload: | { "blocks": [ @@ -68,7 +75,7 @@ jobs: "type": "section", "text": { "type": "mrkdwn", - "text": "GitHub Action build result: *${{ job.status }}* :${{ job.status }}:" + "text": "GitHub Action build result: *${{ needs.build.result }}* :${{ needs.build.result }}:" } }, { diff --git a/python-project-template/.github/workflows/{% if contains_code %}smoke-test.yml{% endif %}.jinja b/python-project-template/.github/workflows/{% if contains_code %}smoke-test.yml{% endif %}.jinja index af73239..4b602dd 100644 --- a/python-project-template/.github/workflows/{% if contains_code %}smoke-test.yml{% endif %}.jinja +++ b/python-project-template/.github/workflows/{% if contains_code %}smoke-test.yml{% endif %}.jinja @@ -47,9 +47,20 @@ jobs: - name: Run unit tests with pytest run: | python -m pytest -o log_cli=true -vv +{%- if 'email' in failure_notification or 'slack' in failure_notification %} + {%- raw %} + + notify: + + needs: build + # Only notify if the workflow failed and was not manually started. Customize this as necessary. + if: ${{ failure() && github.event_name != 'workflow_dispatch' }} + runs-on: ubuntu-latest + + steps: + {%- endraw %} {%- if 'email' in failure_notification %} - name: Send status to author's email - if: {% raw %}${{ failure() }} && github.event_name != 'workflow_dispatch' }}{% endraw %} # Only email if the workflow failed and was not manually started. Customize this as necessary. uses: dawidd6/action-send-mail@67ce3558d613188179559c61d3565140cf389968 # v22 with: # Required mail server address if not connection_url: @@ -65,7 +76,7 @@ jobs: to: {{ author_email }} # Required mail subject: - subject: {% raw %}Smoke test ${{ job.status }} in ${{github.repository}}{% endraw %} + subject: {% raw %}Smoke test ${{ needs.build.result }} in ${{github.repository}}{% endraw %} # Required sender full name: from: GitHub Actions Report # Optional body: @@ -73,8 +84,8 @@ jobs: -

Smoke test ${{ job.status }}

-

The smoke test in ${{ github.repository }} has completed with result: ${{ job.status }}

+

Smoke test ${{ needs.build.result }}

+

The smoke test in ${{ github.repository }} has completed with result: ${{ needs.build.result }}

${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

@@ -85,13 +96,12 @@ jobs: {%- if 'slack' in failure_notification %} {%- raw %} - name: Send status to Slack app - if: ${{ failure() && github.event_name != 'workflow_dispatch' }} id: slack uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 with: # For posting a rich message using Block Kit webhook: ${{ secrets.SLACK_WEBHOOK_URL }} - webhook-type: webhook-trigger + webhook-type: incoming-webhook payload: | { "blocks": [ @@ -99,10 +109,11 @@ jobs: "type": "section", "text": { "type": "mrkdwn", - "text": ":${{ job.status }}: *${{ github.repository }}:* ${{ matrix.python-version }} (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|run #${{ github.run_number }}>)" + "text": ":${{ needs.build.result }}: *${{ github.repository }}* (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|run #${{ github.run_number }}>)" } } ] } {%- endraw %} +{%- endif %} {%- endif %} \ No newline at end of file