forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
39 lines (35 loc) · 1.76 KB
/
trigger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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: |
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}")
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 --branch refs/pull/${pr_number}/merge --commit-id ${sha} --project ${project} --definition-name Fabric-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
env:
AZP_TOKEN: ${{ secrets.AZP_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}