chore: gate restricted contexts with approval job for contributor workflow #1239
Workflow file for this run
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
name: "Trigger CircleCi Pipeline" | |
on: | |
pull_request_target: | |
types: | |
- opened | |
- ready_for_review | |
jobs: | |
main: | |
name: Trigger CircleCi Pipeline when PR is ready for review | |
runs-on: ubuntu-latest | |
steps: | |
- if: ${{ github.event.pull_request.draft == false }} | |
shell: bash | |
env: | |
CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} | |
BASE_ORG_AND_REPO: ${{ github.event.pull_request.head.full_name }} | |
PULL_ID: ${{ github.event.pull_request.number }} | |
run: | | |
if [[ "${CIRCLE_TOKEN}" == "" ]]; then | |
echo "The CIRCLE_TOKEN is unset. Cannot trigger pipeline..." | |
exit 1; | |
fi | |
BRANCH="$GITHUB_HEAD_REF" | |
if [[ "$BASE_ORG_AND_REPO" != "cypress-io/cypress" ]]; then | |
echo "Triggering CircleCi pipeline for outside contributor." | |
BRANCH="pull/$PULL_ID/head" | |
fi | |
echo "Triggering CircleCi pipeline for $BRANCH" | |
response=$(curl -X POST https://circleci.com/api/v2/project/github/cypress-io/cypress/pipeline \ | |
--header "Circle-Token:$CIRCLE_TOKEN" \ | |
--header "content-type:application/json" \ | |
--data "{\"branch\":\"$BRANCH\"}" \ | |
--silent | |
) | |
echo "$response" | |
if [ "$(jq 'has("message")' <<< $response )" == "true" ]; then | |
echo "Error triggering pipeline..." | |
exit 1; | |
fi |