Skip to content

Commit

Permalink
Added additonal input parameters for more flexibility. Updated depend…
Browse files Browse the repository at this point in the history
…encies and documentation
  • Loading branch information
davosian committed Aug 12, 2024
1 parent 0660ce2 commit 86ebd10
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: exit 1
- name: Notify workflow status
if: always()
uses: ajilach/notifications-ghaction@v1.0.0
uses: ajilach/notifications-ghaction@v1.4.0
with:
op_service_account_token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
slack_channel_id: "${{ inputs.slack_channel_id }}"
Expand Down Expand Up @@ -49,18 +49,19 @@ jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Get Previous Workflow Status
run: |
echo "Previous Workflow Status: ${{ github.event.workflow_run.conclusion }}"
echo "Previous Workflow Run ID: ${{ github.event.workflow_run.id }}"

- name: Notify workflow status
uses: ajilach/notifications-ghaction@v1.0.0
with:
op_service_account_token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
slack_channel_id: "C064M8AVB5G"
slack_channel_id: C064M8AVB5G
workflow_completion_notification: "true"
workflow_run_id: "${{ github.event.workflow_run.id }}"
workflow: ${{ github.workflow }}
workflow_run_id: ${{ github.event.workflow_run.id }}
repository: ${{ github.repository }}
repository_branch: ${{ github.ref }}
job_status: ${{ job.status }}

```


Expand All @@ -70,10 +71,18 @@ jobs:

`slack_channel_id`: the Slack channel ID used to post the messages to.

`job_status`: should always be set to `"${{ job.status }}"` so that the action has the job context. Only needed when reporting job status.
`job`: job to notify about. Only relevant when reporting on job level. Optional. Typically `${{ github.job }}`.

`job_status`: should always be set to `${{ job.status }}` so that the action has the job context. Optional.

`workflow_completion_notification`: can be set to either `"true"` or `"false"`. Note that we are passing in strings here since a composite action cannot accept boolean values. Set to `"true"` when reporting workflow status, omit otherwise (default is `"false"`).

`workflow_run_id`: set to the ID of the other workflow for which you would like to report: `"${{ github.event.workflow_run.id }}"`.
`workflow`: set to the other workflow for which you would like to report: Typically `${{ github.workflow }}`.

`workflow_run_id`: set to the ID of the other workflow for which you would like to report: `${{ github.event.workflow_run.id }}`.

`repository`: set to the git repository for which you would like to report. Typically `${{ github.repository }}`.

`repository_branch`: sot to the repository's branch for which you would like to report. Typically `${{ github.ref }}`.

`deploy_flag`: set to `true` if this is a CI/CD workflow and the deploy step has been executed as well. Leave blank if this is not a CI/CD workflow.
48 changes: 33 additions & 15 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,34 @@ inputs:
slack_channel_id:
required: true
description: Slack channel ID for notifications
job:
required: false
description: Job of the calling workflow
default: ${{ github.job }}
job_status:
required: false
description: Status of the calling workflow
default: ${{ job.status }}
workflow_completion_notification:
required: false
description: Send notification on workflow run
default: "false"
description: send notification on workflow run
repository:
required: false
description: Name of the git repository to notify for
default: ${{ github.repository }}
repository_branch:
required: false
description: Name of the git repository branch to notify for
default: ${{ github.ref }}
workflow:
required: false
description: Name of the workflow to notify for
default: ${{ github.workflow }}
workflow_run_id:
required: false
description: ID of the previous workflow run
default: ${{ github.run_id }}
deploy_flag:
required: false
description: Deployed artefacts to maven and Kubernetes
Expand All @@ -33,18 +51,18 @@ runs:

- name: Notify status on Slack
if: inputs.workflow_completion_notification == 'true'
uses: slackapi/slack-github-action@v1.25.0
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{
"channel_id": "${{ inputs.slack_channel_id }}",
"title": "The workflow '${{ github.workflow }}' completed with status *${{ job.status }}* for repo ${{ github.repository }}",
"job_status": "${{ job.status }}",
"job_name": "${{ github.job }}",
"workflow_run": "https://github.com/${{ github.repository }}/actions/runs/${{ inputs.workflow_run_id }}",
"github_repo": "https://github.com/${{ github.repository }}",
"title": "The workflow '${{ inputs.workflow }}' completed with status *${{ inputs.job_status }}* for repo ${{ inputs.repository }}",
"job_status": "n/a",
"job_name": "n/a",
"workflow_run": "https://github.com/${{ inputs.repository }}/actions/runs/${{ inputs.workflow_run_id }}",
"github_repo": "https://github.com/${{ inputs.repository }}",
"github_trigger": "${{ github.event_name }}",
"github_repo_branch": "${{ github.ref }}",
"github_repo_branch": "${{ inputs.repository_branch }}",
"github_actor": "${{ github.triggering_actor }}",
"deploy_flag": "${{ inputs.deploy_flag }}"
}
Expand All @@ -53,18 +71,18 @@ runs:

- name: Send Slack message on failure
if: inputs.job_status == 'failure'
uses: slackapi/slack-github-action@v1.25.0
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{
"channel_id": "${{ inputs.slack_channel_id }}",
"title": ":red_circle: job '${{ github.job }}' *failed* for repo ${{ github.repository }}",
"job_status": "${{ job.status }}",
"job_name": "${{ github.job }}",
"workflow_run": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"github_repo": "https://github.com/${{ github.repository }}",
"title": ":red_circle: job '${{ inputs.job }}' *failed* for repo ${{ inputs.repository }}",
"job_status": "${{ inputs.job_status }}",
"job_name": "${{ inputs.job }}",
"workflow_run": "https://github.com/${{ inputs.repository }}/actions/runs/${{ inputs.workflow_run_id }}",
"github_repo": "https://github.com/${{ inputs.repository }}",
"github_trigger": "${{ github.event_name }}",
"github_repo_branch": "${{ github.ref }}",
"github_repo_branch": "${{ inputs.repository_branch }}",
"github_actor": "${{ github.triggering_actor }}"
}
env:
Expand Down

0 comments on commit 86ebd10

Please sign in to comment.