From 5cf3dcc4812c90e6e614af45f33345f2ed057e99 Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 3 Apr 2023 10:19:35 +0530 Subject: [PATCH] chore: using trigger and wait from twilio-cli-core --- .github/scripts/trigger-and-wait.js | 4 + .github/scripts/trigger-and-wait.sh | 156 ----------------------- .github/workflows/acceptance-tests.yml | 12 +- .github/workflows/cli-test-docker.yml | 4 +- .github/workflows/oclif-release.yml | 4 +- .github/workflows/slack-notification.yml | 12 +- 6 files changed, 20 insertions(+), 172 deletions(-) create mode 100644 .github/scripts/trigger-and-wait.js delete mode 100644 .github/scripts/trigger-and-wait.sh diff --git a/.github/scripts/trigger-and-wait.js b/.github/scripts/trigger-and-wait.js new file mode 100644 index 000000000..1537f1488 --- /dev/null +++ b/.github/scripts/trigger-and-wait.js @@ -0,0 +1,4 @@ +const { triggerAndWait } = require('@twilio/cli-core').releaseScripts.TriggerWaitWorkflow; +(async () => { + await triggerAndWait(); +})(); diff --git a/.github/scripts/trigger-and-wait.sh b/.github/scripts/trigger-and-wait.sh deleted file mode 100644 index 08e0a51d5..000000000 --- a/.github/scripts/trigger-and-wait.sh +++ /dev/null @@ -1,156 +0,0 @@ -#!/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}}" - - # Sleep after triggering workflow so it can be polled for status - echo "Sleeping for $wait_interval seconds" - sleep $wait_interval -} - -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 diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 8d59c566c..e0a15f827 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -53,7 +53,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for oclif executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_OWNER: ${{ github.repository_owner }} INPUT_GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} @@ -106,7 +106,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for windows executables Release - run: bash .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: windows-executable-release.yml INPUT_REF: ${{ needs.get-branch.outputs.branch }} @@ -144,7 +144,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for macos executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: macos-executable-release.yml INPUT_REF: ${{ needs.get-branch.outputs.branch }} @@ -174,7 +174,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for debian executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: debian-executable-release.yml INPUT_REF: ${{ needs.get-branch.outputs.branch }} @@ -203,7 +203,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for apt Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: apt-release.yml INPUT_REF: ${{ needs.get-branch.outputs.branch }} @@ -289,7 +289,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for Scoop release to finish - run: bash .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: update-release.yml INPUT_REF: main diff --git a/.github/workflows/cli-test-docker.yml b/.github/workflows/cli-test-docker.yml index 80217ee55..e440599e1 100644 --- a/.github/workflows/cli-test-docker.yml +++ b/.github/workflows/cli-test-docker.yml @@ -19,7 +19,7 @@ jobs: - name: Check Out Repo uses: actions/checkout@v2 - name: Wait for docker release to finish - run: bash .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_OWNER: ${{ github.repository_owner }} INPUT_WORKFLOW_FILE_NAME: docker-release.yml @@ -41,4 +41,4 @@ jobs: docker run --rm twilio/twilio-cli:2.36.1 /bin/bash -c "twilio api:accounts --help && twilio" && docker pull twilio/twilio-cli:latest && docker run --rm twilio/twilio-cli:latest /bin/bash -c "twilio api:accounts --help && twilio" - name: Test for the latest release run: | - docker run --rm twilio/twilio-cli /bin/bash -c "twilio api:accounts --help && twilio" + docker run --rm twilio/twilio-cli /bin/bash -c "twilio api:accounts --help && twilio" diff --git a/.github/workflows/oclif-release.yml b/.github/workflows/oclif-release.yml index 6bff98d4d..f7eca2a7a 100644 --- a/.github/workflows/oclif-release.yml +++ b/.github/workflows/oclif-release.yml @@ -71,7 +71,7 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Invoke HomeBrew workflow - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_OWNER: ${{ github.repository_owner }} INPUT_REPO: homebrew-brew @@ -93,7 +93,7 @@ jobs: run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - name: Invoke Scoop workflow if: ${{steps.extract_branch.outputs.branch == 'main'}} - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_OWNER: ${{ github.repository_owner }} INPUT_REPO: scoop-twilio-cli diff --git a/.github/workflows/slack-notification.yml b/.github/workflows/slack-notification.yml index 46c8897c9..6c07b677d 100644 --- a/.github/workflows/slack-notification.yml +++ b/.github/workflows/slack-notification.yml @@ -35,27 +35,27 @@ jobs: - name: Checkout cli repo uses: actions/checkout@v2 - name: Wait for Docker Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: docker-release.yml - name: Wait for Oclif, Homebrew and Scoop Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: oclif-release.yml - name: Wait for debian executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: debian-executable-release.yml - name: Wait for windows executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: windows-executable-release.yml - name: Wait for RPM Build - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: rpmbuild.yml - name: Wait for macos executables Release - run: source .github/scripts/trigger-and-wait.sh + run: node .github/scripts/trigger-and-wait.js env: INPUT_WORKFLOW_FILE_NAME: macos-executable-release.yml notify-complete-success: