Skip to content

Commit

Permalink
ci: add a PR comment if labeled PR is coming from a fork
Browse files Browse the repository at this point in the history
We can't trigger CircleCI workflow automatically in this case as secret are not available in PR from forks.
  • Loading branch information
gaetanmaisse committed Dec 8, 2020
1 parent 25ca1a7 commit 4102c3d
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/trigger-circle-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@ on:

jobs:
trigger:
if: github.event.label.name == 'run all e2e tests'
if: github.event.label.name == 'run all e2e tests' && github.event.pull_request.head.repo.fork == false
name: Run workflow with all e2e tests
runs-on: ubuntu-latest
steps:
- name: Compute and export CircleCI ref from branch/fork
run: |
export IS_PR_FROM_FORK=${{ github.event.pull_request.head.repo.fork }}
echo $IS_PR_FROM_FORK
if [ $IS_PR_FROM_FORK = true ]
then
export CIRCLE_CI_BRANCH_REF=pull/${{ github.event.pull_request.number }}/head
else
export CIRCLE_CI_BRANCH_REF=${{ github.event.pull_request.head.ref }}
fi
echo CIRCLE_CI_BRANCH_REF is $CIRCLE_CI_BRANCH_REF
echo "CIRCLE_CI_BRANCH_REF=$CIRCLE_CI_BRANCH_REF" >> $GITHUB_ENV
- name: Make request to CircleCI
run: >
curl --request POST
--url https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline
--header 'Circle-Token: '"$CIRCLE_CI_TOKEN"' '
--header 'content-type: application/json'
--data '{ "branch" : "'"$CIRCLE_CI_BRANCH_REF"'" } '
--data '{"branch":"${{ github.event.pull_request.head.ref }}"}'
env:
CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN_GMAISSE_TEST }}
comment-pr:
if: github.event.label.name == 'run all e2e tests' && github.event.pull_request.head.repo.fork == true
name: Add reminder as PR comment
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
script: |
const comment = "👋🏻 @${{ github.actor }}, you just added the `run all e2e tests` label so all the next runs of CircleCI pipelines will now include the extended e2e test suite.\n\n" +
"As this PR is coming from a fork I was not able to trigger CircleCI automatically so if you don't want to wait for the next branch update " +
"you can trigger a workflow manually [here](https://app.circleci.com/pipelines/github/storybookjs/storybook?branch=pull/${{ github.event.pull_request.number }})."
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
})

0 comments on commit 4102c3d

Please sign in to comment.