Skip to content

Commit

Permalink
Allow slash commands on PRs from forks (#9742)
Browse files Browse the repository at this point in the history
This enables all slash commands to also work on PRs created from forks. This will not run CI on PRs coming from a fork. There are unfortunately some limitations around injecting secrets in pull_request actions, which I described in detail in this comment.

I've done most of the testing for this in https://github.com/timroes/github-actions-test to test out that the context are set the way I'd expect them.

There's one risk: if any of the actual build scripts called by one of the slash commands would use this repository hard-coded they might fail. I've tried to search through the whole code base and don't believe this is the case.
  • Loading branch information
timroes committed Mar 8, 2022
1 parent f232bd5 commit 3df0619
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/gke-kube-test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ on:
- cron: '0 */6 * * *'
workflow_dispatch:
inputs:
repo:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
comment-id:
description: 'The comment-id of the slash command. Used to update the comment with the status.'
required: false
Expand All @@ -19,6 +27,9 @@ jobs:
steps:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Start AWS Runner
id: start-ec2-runner
uses: ./.github/actions/start-aws-runner
Expand All @@ -43,6 +54,9 @@ jobs:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}

- uses: actions/setup-java@v1
with:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/publish-cdk-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Publish CDK
on:
workflow_dispatch:
inputs:
repo:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
dry-run:
description: 'By default dry-run publishes to Test PyPi. Use "false" to publish to actual PyPi servers.'
required: false
Expand All @@ -26,6 +34,9 @@ jobs:
java-version: '17'
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Build CDK Package
run: SUB_BUILD=CONNECTORS_BASE ./gradlew --no-daemon --no-build-cache :airbyte-cdk:python:build
- name: Add Failure Comment
Expand Down Expand Up @@ -56,6 +67,9 @@ jobs:
echo "pypi_url=https://test.pypi.org/legacy/" >> $GITHUB_ENV
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Publish Python Package
uses: mariamrf/py-package-publish-action@v1.1.0
with:
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/publish-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Publish Connector Image
on:
workflow_dispatch:
inputs:
repo:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
connector:
description: "Airbyte Connector"
required: true
Expand All @@ -26,7 +34,8 @@ jobs:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{github.event.pull_request.head.repo.full_name}} # always use the branch's repository
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Start AWS Runner
id: start-ec2-runner
uses: ./.github/actions/start-aws-runner
Expand Down Expand Up @@ -66,7 +75,8 @@ jobs:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{github.event.pull_request.head.repo.full_name}} # always use the branch's repository
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Install Java
uses: actions/setup-java@v1
with:
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/publish-external-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ on:
comment-id:
description: "The comment-id of the slash command. Used to update the comment with the status."
required: false
repo:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master

jobs:
## Gradle Build
Expand All @@ -25,7 +33,8 @@ jobs:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{github.event.pull_request.head.repo.full_name}} # always use the branch's repository
repository: ${{ gituhb.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Start AWS Runner
id: start-ec2-runner
uses: ./.github/actions/start-aws-runner
Expand Down Expand Up @@ -55,7 +64,8 @@ jobs:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{github.event.pull_request.head.repo.full_name}} # always use the branch's repository
repository: ${{ gituhb.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- run: |
echo "$SPEC_CACHE_SERVICE_ACCOUNT_KEY" > spec_cache_key_file.json && docker login -u airbytebot -p ${DOCKER_PASSWORD}
./tools/integrations/manage.sh publish_external ${{ github.event.inputs.connector }} ${{ github.event.inputs.version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: performance-test
on:
workflow_dispatch:
inputs:
repo:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
test-name:
description: "Test to run classname"
required: true
Expand All @@ -15,6 +23,9 @@ jobs:
steps:
- name: Checkout Airbyte
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}

- name: Npm Caching
uses: actions/cache@v2
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/slash-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Get PR Ref
- name: Get PR repo and ref
id: getref
run: |
echo "::set-output name=ref::$(curl ${{ github.event.issue.pull_request.url }} | jq -r '.head.ref')"
pr_info="$(curl ${{ github.event.issue.pull_request.url }})"
echo ::set-output name=ref::"$(echo $pr_info | jq -r '.head.ref')"
echo ::set-output name=repo::"$(echo $pr_info | jq -r '.head.repo.full_name')"
- name: Slash Command Dispatch
id: scd
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.SLASH_COMMAND_PAT }}
# Only allow slash commands on pull request (not on issues)
issue-type: pull-request
commands: |
test
test-performance
Expand All @@ -24,7 +28,8 @@ jobs:
gke-kube-test
run-specific-test
static-args: |
ref=${{ steps.getref.outputs.ref }}
repo=${{ steps.getref.outputs.repo }}
gitref=${{ steps.getref.outputs.ref }}
comment-id=${{ github.event.comment.id }}
dispatch-type: workflow
- name: Edit comment with error message
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
comment-id:
description: "The comment-id of the slash command. Used to update the comment with the status."
required: false
Expand All @@ -26,6 +30,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Start AWS Runner
id: start-ec2-runner
uses: ./.github/actions/start-aws-runner
Expand Down Expand Up @@ -62,6 +67,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Install Java
uses: actions/setup-java@v1
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-performance-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
description: "Repo to check out code from. Defaults to the main airbyte repo. Set this when building connectors from forked repos."
required: false
default: "airbytehq/airbyte"
gitref:
description: "The git ref to check out from the specified repository."
required: false
default: master
comment-id:
description: "The comment-id of the slash command. Used to update the comment with the status."
required: false
Expand All @@ -32,6 +36,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Start AWS Runner
id: start-ec2-runner
uses: ./.github/actions/start-aws-runner
Expand Down Expand Up @@ -68,6 +73,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Install Java
uses: actions/setup-java@v1
with:
Expand Down

0 comments on commit 3df0619

Please sign in to comment.