-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added the slack notifications for Github actions (#304)
* feat: Added the slack notifications for Github actions * Added single success notifiction. * Update slack-notification.yml * Update oclif-release.yml * Converted the community action into script * Update slack-notification.yml * Update slack-notification.yml
- Loading branch information
1 parent
b2b12e8
commit 8a14fdb
Showing
7 changed files
with
318 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#!/bin/sh | ||
|
||
#Functionality from convictional/trigger-workflow-and-wait. | ||
#Link: https://github.com/convictional/trigger-workflow-and-wait | ||
|
||
usage_docs() { | ||
echo "" | ||
echo " owner: twilio" | ||
echo " repo: twilio-cli" | ||
echo " github_token: \${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}" | ||
echo " workflow_file_name: main.yaml" | ||
} | ||
|
||
validate_args() { | ||
wait_interval=10 # Waits for 10 seconds | ||
if [ "${INPUT_WAITING_INTERVAL}" ] | ||
then | ||
wait_interval=${INPUT_WAITING_INTERVAL} | ||
fi | ||
|
||
propagate_failure=true | ||
if [ -n "${INPUT_PROPAGATE_FAILURE}" ] | ||
then | ||
propagate_failure=${INPUT_PROPAGATE_FAILURE} | ||
fi | ||
|
||
trigger_workflow=true | ||
if [ -n "${INPUT_TRIGGER_WORKFLOW}" ] | ||
then | ||
trigger_workflow=${INPUT_TRIGGER_WORKFLOW} | ||
fi | ||
|
||
wait_workflow=true | ||
if [ -n "${INPUT_WAIT_WORKFLOW}" ] | ||
then | ||
wait_workflow=${INPUT_WAIT_WORKFLOW} | ||
fi | ||
|
||
if [ -z "${INPUT_OWNER}" ] | ||
then | ||
echo "Error: Owner is a required argument." | ||
usage_docs | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${INPUT_REPO}" ] | ||
then | ||
echo "Error: Repo is a required argument." | ||
usage_docs | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${INPUT_GITHUB_TOKEN}" ] | ||
then | ||
echo "Error: Github token is required. You can head over settings and" | ||
echo "under developer, you can create a personal access tokens. The" | ||
echo "token requires repo access." | ||
usage_docs | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${INPUT_WORKFLOW_FILE_NAME}" ] | ||
then | ||
echo "Error: Workflow File Name is required" | ||
usage_docs | ||
exit 1 | ||
fi | ||
|
||
inputs=$(echo '{}' | jq) | ||
if [ "${INPUT_INPUTS}" ] | ||
then | ||
inputs=$(echo "${INPUT_INPUTS}" | jq) | ||
fi | ||
|
||
ref="main" | ||
if [ "$INPUT_REF" ] | ||
then | ||
ref="${INPUT_REF}" | ||
fi | ||
} | ||
|
||
trigger_workflow() { | ||
echo "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/dispatches" | ||
|
||
curl -X POST "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/dispatches" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ | ||
--data "{\"ref\":\"${ref}\",\"inputs\":${inputs}}" | ||
} | ||
|
||
wait_for_workflow_to_finish() { | ||
# Find the id of the last build | ||
last_workflow=$(curl -X GET "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/runs" \ | ||
-H 'Accept: application/vnd.github.antiope-preview+json' \ | ||
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" | jq '[.workflow_runs[]] | first') | ||
last_workflow_id=$(echo "${last_workflow}" | jq '.id') | ||
last_workflow_url="https://github.com/${INPUT_OWNER}/${INPUT_REPO}/actions/runs/${last_workflow_id}" | ||
echo "The workflow id is [${last_workflow_id}]." | ||
echo "The workflow logs can be found at ${last_workflow_url}" | ||
echo "::set-output name=workflow_id::${last_workflow_id}" | ||
echo "::set-output name=workflow_url::${last_workflow_url}" | ||
echo "" | ||
conclusion=$(echo "${last_workflow}" | jq '.conclusion') | ||
status=$(echo "${last_workflow}" | jq '.status') | ||
|
||
while [[ "${conclusion}" == "null" && "${status}" != "\"completed\"" ]] | ||
do | ||
echo "Sleeping for \"${wait_interval}\" seconds" | ||
sleep "${wait_interval}" | ||
workflow=$(curl -X GET "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/runs" \ | ||
-H 'Accept: application/vnd.github.antiope-preview+json' \ | ||
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" | jq '.workflow_runs[] | select(.id == '${last_workflow_id}')') | ||
conclusion=$(echo "${workflow}" | jq '.conclusion') | ||
status=$(echo "${workflow}" | jq '.status') | ||
echo "Checking conclusion [${conclusion}]" | ||
echo "Checking status [${status}]" | ||
done | ||
|
||
if [[ "${conclusion}" == "\"success\"" && "${status}" == "\"completed\"" ]] | ||
then | ||
echo "Yes, success" | ||
else | ||
# Alternative "failure" | ||
echo "Conclusion is not success, its [${conclusion}]." | ||
if [ "${propagate_failure}" = true ] | ||
then | ||
echo "Propagating failure to upstream job" | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
main() { | ||
validate_args | ||
|
||
if [ "${trigger_workflow}" = true ] | ||
then | ||
trigger_workflow | ||
else | ||
echo "Skipping triggering the workflow." | ||
fi | ||
|
||
if [ "${wait_workflow}" = true ] | ||
then | ||
wait_for_workflow_to_finish | ||
else | ||
echo "Skipping waiting for workflow." | ||
fi | ||
} | ||
|
||
main |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Slack Notification | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_run: | ||
workflows: | ||
- Cli Release | ||
branches: [main] | ||
types: | ||
- completed | ||
jobs: | ||
wait-for-releases: | ||
env: | ||
INPUT_OWNER: twilio | ||
INPUT_REPO: twilio-cli | ||
INPUT_GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} | ||
INPUT_REF: ${{steps.extract_branch.outputs.branch}} | ||
INPUT_WAITING_INTERVAL: 10 | ||
INPUT_PROPAGATE_FAILURE: true | ||
INPUT_TRIGGER_WORKFLOW: false | ||
name: Wait for Docker, Homebrew, RPM and Platform executables Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Extract branch name | ||
id: extract_branch | ||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
- name: Checkout cli repo | ||
uses: actions/checkout@v2 | ||
- name: Wait for Docker Release | ||
run: source .github/scripts/trigger-and-wait.sh | ||
env: | ||
INPUT_WORKFLOW_FILE_NAME: docker-release.yml | ||
- name: Wait for Oclif Release | ||
run: source .github/scripts/trigger-and-wait.sh | ||
env: | ||
INPUT_WORKFLOW_FILE_NAME: oclif-release.yml | ||
- name: Wait for Platform Executables Release | ||
run: source .github/scripts/trigger-and-wait.sh | ||
env: | ||
INPUT_WORKFLOW_FILE_NAME: platform-executables.yml | ||
- name: Wait for RPM Build | ||
run: source .github/scripts/trigger-and-wait.sh | ||
env: | ||
INPUT_WORKFLOW_FILE_NAME: rpmbuild.yml | ||
notify-complete-success: | ||
needs: [ wait-for-releases ] | ||
name: Notify Release Completed | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Slack Notification | ||
uses: rtCamp/action-slack-notify@v2 | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEB_HOOK }} | ||
SLACK_COLOR: "#36a64f" | ||
SLACK_USERNAME: CLI Release Bot | ||
SLACK_ICON_EMOJI: ":ship:" | ||
SLACK_TITLE: 'Twilio CLI' | ||
SLACK_MESSAGE: 'Release Completed.' | ||
MSG_MINIMAL: actions url |