github.com/kaituanwang/hyperledger@v2.0.1+incompatible/.github/workflows/trigger.yml (about) 1 # Copyright the Hyperledger Fabric contributors. All rights reserved. 2 # 3 # SPDX-License-Identifier: Apache-2.0 4 5 on: 6 issue_comment: 7 types: [created] 8 name: Automatically Trigger Azure Pipeline 9 jobs: 10 trigger: 11 name: TriggerAZP 12 if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/ci-run') 13 runs-on: ubuntu-latest 14 steps: 15 - name: Trigger Build 16 run: | 17 author=$(jq -r ".issue.user.login" "${GITHUB_EVENT_PATH}") 18 commenter=$(jq -r ".comment.user.login" "${GITHUB_EVENT_PATH}") 19 org=$(jq -r ".repository.owner.login" "${GITHUB_EVENT_PATH}") 20 pr_number=$(jq -r ".issue.number" "${GITHUB_EVENT_PATH}") 21 project=$(jq -r ".repository.name" "${GITHUB_EVENT_PATH}") 22 repo=$(jq -r ".repository.full_name" "${GITHUB_EVENT_PATH}") 23 24 comment_url="https://api.github.com/repos/${repo}/issues/${pr_number}/comments" 25 pr_url="https://api.github.com/repos/${repo}/pulls/${pr_number}" 26 27 pr_resp=$(curl "${pr_url}") 28 isReviewer=$(echo "${pr_resp}" | jq -r .requested_reviewers | jq -c ".[] | select(.login | contains(\"${commenter}\"))" | wc -l) 29 30 if [[ "${commenter}" = "${author}" ]] || [[ "${isReviewer}" -ne 0 ]]; then 31 sha=$(echo "${pr_resp}" | jq -r ".head.sha") 32 33 az extension add --name azure-devops 34 echo ${AZP_TOKEN} | az devops login --organization "https://dev.azure.com/${org}" 35 36 runs=$(az pipelines build list --project ${project} | jq -c ".[] | select(.sourceVersion | contains(\"${sha}\"))" | jq -r .status | grep -v completed | wc -l) 37 if [[ $runs -eq 0 ]]; then 38 az pipelines build queue --branch refs/pull/${pr_number}/merge --commit-id ${sha} --project ${project} --definition-name Pull-Request 39 curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "AZP build triggered!"}' "${comment_url}" 40 else 41 curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "AZP build already running!"}' "${comment_url}" 42 fi 43 else 44 curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "You are not authorized to trigger builds for this pull request!"}' "${comment_url}" 45 fi 46 env: 47 AZP_TOKEN: ${{ secrets.AZP_TOKEN }} 48 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}