forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-17133] Add Action to Trigger CI
This change adds a GitHub Action that is used to trigger CI builds when the PR is commented on using "/ci-run" Signed-off-by: Brett Logan <[email protected]>
- Loading branch information
Brett Logan
authored and
Brett Logan
committed
Nov 26, 2019
1 parent
db3b1cc
commit cfae78e
Showing
2 changed files
with
49 additions
and
1 deletion.
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,48 @@ | ||
# Copyright the Hyperledger Fabric contributors. All rights reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
name: Automatically Trigger Azure Pipeline | ||
jobs: | ||
trigger: | ||
name: TriggerAZP | ||
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/ci-run') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Trigger Build | ||
run: | | ||
author=$(jq -r ".issue.user.login" "${GITHUB_EVENT_PATH}") | ||
commenter=$(jq -r ".comment.user.login" "${GITHUB_EVENT_PATH}") | ||
org=$(jq -r ".repository.owner.login" "${GITHUB_EVENT_PATH}") | ||
pr_number=$(jq -r ".issue.number" "${GITHUB_EVENT_PATH}") | ||
project=$(jq -r ".repository.name" "${GITHUB_EVENT_PATH}") | ||
repo=$(jq -r ".repository.full_name" "${GITHUB_EVENT_PATH}") | ||
comment_url="https://api.github.com/repos/${repo}/issues/${pr_number}/comments" | ||
pr_url="https://api.github.com/repos/${repo}/pulls/${pr_number}" | ||
pr_resp=$(curl "${pr_url}") | ||
isReviewer=$(echo "${pr_resp}" | jq -r .requested_reviewers | jq -c ".[] | select(.login | contains(\"${commenter}\"))" | wc -l) | ||
if [[ "${commenter}" = "${author}" ]] || [[ "${isReviewer}" -ne 0 ]]; then | ||
sha=$(echo "${pr_resp}" | jq -r ".head.sha") | ||
az extension add --name azure-devops | ||
echo ${AZP_TOKEN} | az devops login --organization "https://dev.azure.com/${org}" | ||
runs=$(az pipelines build list --project ${project} | jq -c ".[] | select(.sourceVersion | contains(\"${sha}\"))" | jq -r .status | grep -v completed | wc -l) | ||
if [[ $runs -eq 0 ]]; then | ||
az pipelines build queue --commit-id ${sha} --project ${project} --definition-name Pull-Request | ||
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "AZP build triggered!"}' "${comment_url}" | ||
else | ||
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "AZP build already running!"}' "${comment_url}" | ||
fi | ||
else | ||
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"body": "You are not authorized to trigger builds for this pull request!"}' "${comment_url}" | ||
fi | ||
env: | ||
AZP_TOKEN: ${{ secrets.AZP_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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