|
| 1 | +name: Fix formatting on a PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + pr: |
| 7 | + description: "Pull request number. Used to pull the proper branch ref, including on forks." |
| 8 | + required: false |
| 9 | + comment-id: |
| 10 | + description: "Optional. The comment-id of the slash command. Used to update the comment with the status." |
| 11 | + required: false |
| 12 | + |
| 13 | +run-name: "Fix formatting on PR #${{ github.event.inputs.pr }}" |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.event.inputs.pr }} |
| 16 | + # Cancel any previous runs on the same branch if they are still in progress |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + format-fix: |
| 21 | + name: "Run airbyte-ci format fix all" |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout Airbyte |
| 25 | + uses: actions/checkout@v3 |
| 26 | + with: |
| 27 | + # Important that this is set so that CI checks are triggered again |
| 28 | + # Without this we would be forever waiting on required checks to pass |
| 29 | + token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }} |
| 30 | + fetch-depth: 1 |
| 31 | + |
| 32 | + - name: Checkout PR (${{ github.event.inputs.pr }}) |
| 33 | + uses: dawidd6/action-checkout-pr@v1 |
| 34 | + with: |
| 35 | + pr: ${{ github.event.inputs.pr }} |
| 36 | + |
| 37 | + - name: Get job variables |
| 38 | + id: job-vars |
| 39 | + env: |
| 40 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + shell: bash |
| 42 | + run: | |
| 43 | + PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }}) |
| 44 | + echo "::set-output name=repo::$(echo "$PR_JSON" | jq -r .head.repo.full_name)" |
| 45 | + echo "::set-output name=branch::$(echo "$PR_JSON" | jq -r .head.ref)" |
| 46 | + echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Append comment with job run link |
| 49 | + # If not comment-id is provided, this will create a new |
| 50 | + # comment with the job run link. |
| 51 | + id: first-comment-action |
| 52 | + uses: peter-evans/create-or-update-comment@v4 |
| 53 | + with: |
| 54 | + comment-id: ${{ github.event.inputs.comment-id }} |
| 55 | + issue-number: ${{ github.event.inputs.pr }} |
| 56 | + body: | |
| 57 | +
|
| 58 | + > Format-fix job started... [Check job output.][1] |
| 59 | +
|
| 60 | + [1]: ${{ steps.job-vars.outputs.run-url }} |
| 61 | +
|
| 62 | + - name: Run airbyte-ci format fix all |
| 63 | + uses: ./.github/actions/run-airbyte-ci |
| 64 | + continue-on-error: true |
| 65 | + with: |
| 66 | + context: "manual" |
| 67 | + dagger_cloud_token: ${{ secrets.DAGGER_CLOUD_TOKEN_2 }} |
| 68 | + docker_hub_password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
| 69 | + docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 70 | + gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }} |
| 71 | + sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }} |
| 72 | + github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }} |
| 73 | + subcommand: "format fix all" |
| 74 | + |
| 75 | + # This is helpful in the case that we change a previously committed generated file to be ignored by git. |
| 76 | + - name: Remove any files that have been gitignored |
| 77 | + run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached |
| 78 | + |
| 79 | + - name: Commit Formatting Changes (PR) |
| 80 | + id: commit-step |
| 81 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 82 | + # Don't commit if we're on master |
| 83 | + if: github.ref != 'refs/heads/master' |
| 84 | + with: |
| 85 | + commit_message: "chore: format code" |
| 86 | + commit_user_name: Octavia Squidington III |
| 87 | + commit_user_email: [email protected] |
| 88 | + |
| 89 | + - name: Append success comment |
| 90 | + uses: peter-evans/create-or-update-comment@v4 |
| 91 | + if: steps.commit-step.outputs.changes_detected == 'true' |
| 92 | + with: |
| 93 | + comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 94 | + reactions: hooray |
| 95 | + body: | |
| 96 | + > ✅ Changes applied successfully. (${{ steps.commit-step.outputs.commit_hash }}) |
| 97 | +
|
| 98 | + - name: Append success comment (no-op) |
| 99 | + uses: peter-evans/create-or-update-comment@v4 |
| 100 | + if: steps.commit-step.outputs.changes_detected != 'true' |
| 101 | + with: |
| 102 | + comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 103 | + reactions: "+1" |
| 104 | + body: | |
| 105 | + > 🟦 Job completed successfully (no changes). |
| 106 | +
|
| 107 | + - name: Append failure comment |
| 108 | + uses: peter-evans/create-or-update-comment@v4 |
| 109 | + if: failure() |
| 110 | + with: |
| 111 | + comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 112 | + reactions: confused |
| 113 | + body: | |
| 114 | + > ❌ Job failed. |
0 commit comments