On-Demand PR Test #56
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: On-Demand PR Test | |
on: | |
workflow_dispatch: | |
inputs: | |
pr: | |
description: 'PR Number' | |
type: string | |
required: true | |
comment-id: | |
description: 'Comment ID (Optional)' | |
type: string | |
required: false | |
env: | |
AIRBYTE_ANALYTICS_ID: ${{ vars.AIRBYTE_ANALYTICS_ID }} | |
jobs: | |
start-workflow: | |
name: Append 'Starting' Comment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR JSON | |
id: pr-info | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }}) | |
echo "$PR_JSON" > pr-info.json | |
echo "sha=$(cat pr-info.json | jq -r .head.sha)" >> $GITHUB_OUTPUT | |
echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT | |
- name: Upload PR details as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: pr-info | |
path: pr-info.json | |
- name: Append comment with job run link | |
id: first-comment-action | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ github.event.inputs.comment-id }} | |
issue-number: ${{ github.event.inputs.pr }} | |
body: | | |
> PR test job started... [Check job output.][1] | |
[1]: ${{ steps.pr-info.outputs.run-url }} | |
# This is copied from the `python_pytest.yml` file. | |
# Only the first two steps of the job are different, and they check out the PR's branch. | |
pytest-on-demand: | |
name: On-Demand PR Pytest (All, Python ${{ matrix.python-version }}, ${{ matrix.os }}) | |
needs: [start-workflow] | |
strategy: | |
matrix: | |
python-version: [ | |
'3.9', | |
'3.10', | |
'3.11', | |
] | |
os: [ | |
Ubuntu, | |
Windows, | |
] | |
fail-fast: false | |
runs-on: "${{ matrix.os }}-latest" | |
permissions: | |
actions: read | |
statuses: write | |
env: | |
# Enforce UTF-8 encoding so Windows runners don't fail inside the connector code. | |
# TODO: See if we can fully enforce this within PyAirbyte itself. | |
PYTHONIOENCODING: utf-8 | |
steps: | |
# Custom steps to fetch the PR and checkout the code: | |
- name: Download PR info | |
# This puts the `pr-info.json` file in the current directory. | |
# We need this to get the PR's SHA at the time of the workflow run. | |
uses: actions/download-artifact@v2 | |
with: | |
name: pr-info | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout PR (${{ github.event.inputs.pr }}) | |
id: checkout-pr | |
uses: dawidd6/action-checkout-pr@v1 | |
with: | |
pr: ${{ github.event.inputs.pr }} | |
# - name: Get SHA of checked-out PR | |
# id: get-sha | |
# run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- id: get-sha | |
uses: hudsonm62/short-sha@v1 | |
# - name: Get SHA of checked-out PR | |
# id: get-sha-2 | |
# uses: actions/github-script@v6 | |
# with: | |
# script: | | |
# const sha = await github.rest.repos.getCommit({ | |
# owner: context.repo.owner, | |
# repo: context.repo.repo, | |
# ref: context.sha | |
# }); | |
# return { sha: sha.data.sha }; | |
- name: CI job status tracker (commit ${{ steps.get-sha.outputs.sha }}) | |
uses: aaronsteers/action-job-status@feat/allow-job-name-override | |
with: | |
commit_sha: ${{ steps.get-sha.outputs.sha }} | |
job_name: On-Demand PR Pytest (All, Python ${{ matrix.python-version }}, ${{ matrix.os }}) | |
# Same as the `python_pytest.yml` file: | |
- name: Set up Poetry | |
uses: Gr1N/setup-poetry@v9 | |
with: | |
poetry-version: "1.7.1" | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'poetry' | |
- name: Install dependencies | |
run: poetry install | |
- name: Run Pytest | |
timeout-minutes: 60 | |
env: | |
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }} | |
run: > | |
poetry run pytest | |
--verbose | |
-m "not super_slow and not flaky" | |
- name: Run Pytest (Flaky Only) | |
continue-on-error: true | |
timeout-minutes: 60 | |
env: | |
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }} | |
run: > | |
poetry run pytest | |
--verbose | |
-m "flaky and not super_slow" | |
log-success-comment: | |
name: Append 'Success' Comment | |
needs: [pytest-on-demand] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Append success comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.inputs.pr }} | |
comment-id: ${{ github.event.inputs.comment-id }} | |
reactions: hooray | |
body: | | |
> ✅ Tests passed. | |
log-failure-comment: | |
name: Append 'Failure' Comment | |
# This job will only run if the workflow fails | |
needs: [pytest-on-demand, start-workflow] | |
if: always() && needs.pytest-on-demand.result == 'failure' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Append failure comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.inputs.pr }} | |
comment-id: ${{ github.event.inputs.comment-id }} | |
reactions: confused | |
body: | | |
> ❌ Tests failed. |