Skip to content

On-Demand PR Auto-Fix #14

On-Demand PR Auto-Fix

On-Demand PR Auto-Fix #14

Workflow file for this run

name: On-Demand PR Auto-Fix
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:
# 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 }})
# Don't run on forks. Run on pushes to main, and on PRs that are not from forks.
strategy:
matrix:
python-version: [
'3.10',
]
os: [
Ubuntu,
]
fail-fast: false
runs-on: "${{ matrix.os }}-latest"
steps:
# Custom steps to fetch the PR and checkout the code:
- name: Checkout PR
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout PR (${{ github.event.inputs.pr }})
uses: dawidd6/action-checkout-pr@v1
with:
pr: ${{ github.event.inputs.pr }}
- name: Get PR info
id: pr-info
run: |
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }})
echo "::set-output name=repo::$(echo "$PR_JSON" | jq -r .head.repo.full_name)"
echo "::set-output name=branch::$(echo "$PR_JSON" | jq -r .head.ref)"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
- name: Create URL to the run output
id: vars
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
- name: Append comment with job run link
uses: peter-evans/create-or-update-comment@v4
with:
# token: ${{ secrets.PAT }}
# repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.inputs.comment-id }}
body: |
Job started... [Check job output.][1]
[1]: ${{ steps.vars.outputs.run-url }}
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
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
# Fix any lint or format issues
- name: Auto-Fix Ruff Lint Issues
run: poetry run ruff check --fix . || true
- name: Auto-Fix Ruff Format Issues
run: poetry run ruff format . || true
# Check for changes in git
- name: Check for changes
id: git-diff
run: |
git diff --quiet && echo "No changes to commit" || echo "::set-output name=changes::true"
shell: bash
# Commit changes (if any)
- name: Commit changes
if: steps.git-diff.outputs.changes == 'true'
run: |
git config --global user.name "octavia-squidington-iii"
git config --global user.email "contact@airbyte.com"
git add .
git commit -m "Auto-fix lint and format issues"
# Fix any further 'unsafe' lint issues in a separate commit
- name: Auto-Fix Ruff Lint Issues (Unsafe)
run: poetry run ruff check --fix --unsafe . || true
- name: Auto-Fix Ruff Format Issues
run: poetry run ruff format . || true
# Check for changes in git (2nd time, for 'unsafe' lint fixes)
- name: Check for changes ('unsafe' fixes)
id: git-diff-2
run: |
git diff --quiet && echo "No changes to commit" || echo "::set-output name=changes::true"
shell: bash
- name: Commit 'unsafe' lint fixes
if: steps.git-diff-2.outputs.changes == 'true'
run: |
git config --global user.name "octavia-squidington-iii"
git config --global user.email "contact@airbyte.com"
git add .
git commit -m "Auto-fix lint issues (unsafe)"
- name: Push changes
if: steps.git-diff.outputs.changes == 'true' || steps.git-diff-2.outputs.changes == 'true'
run: |
git remote add contributor https://github.com/${{ steps.pr-info.outputs.repo }}.git
git push contributor HEAD:${{ steps.pr-info.outputs.branch }}
- name: Append success comment
uses: peter-evans/create-or-update-comment@v4
if: steps.git-diff.outputs.changes == 'true' || steps.git-diff-2.outputs.changes == 'true'
with:
# token: ${{ secrets.PAT }}
# repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.inputs.comment-id }}
reactions: hooray
body: |
✅ Changes applied successfully.
- name: Append success comment (no-op)
uses: peter-evans/create-or-update-comment@v4
with:
# token: ${{ secrets.PAT }}
# repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.inputs.comment-id }}
reactions: thumbsup
body: |
🟦 Job completed successfully (no changes).
- name: Append failure comment
uses: peter-evans/create-or-update-comment@v4
if: failure()
with:
# token: ${{ secrets.PAT }}
# repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.inputs.comment-id }}
reactions: confused
body: |
❌ Job failed.