121 lines
4.7 KiB
YAML
121 lines
4.7 KiB
YAML
name: Format Code (Python + Java)
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
jobs:
|
|
format-and-commit:
|
|
runs-on: ubuntu-latest
|
|
name: "Apply All Formatting Rules"
|
|
timeout-minutes: 40
|
|
steps:
|
|
- name: Checkout Airbyte
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ github.head_ref }}
|
|
# Important that this is set so that CI checks are triggered again
|
|
# Without this we would be be forever waiting on required checks to pass
|
|
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}
|
|
|
|
# IMPORTANT! This is nessesary to make sure that a status is reported on the PR
|
|
# even if the workflow is skipped. If we used github actions filters, the workflow
|
|
# would not be reported as skipped, but instead would be forever pending.
|
|
#
|
|
# I KNOW THIS SOUNDS CRAZY, BUT IT IS TRUE.
|
|
#
|
|
# Also it gets worse
|
|
#
|
|
# IMPORTANT! DO NOT CHANGE THE QUOTES AROUND THE GLOBS. THEY ARE REQUIRED.
|
|
# MAKE SURE TO TEST ANY SYNTAX CHANGES BEFORE MERGING.
|
|
- name: Get changed files
|
|
uses: tj-actions/changed-files@v39
|
|
id: changes
|
|
with:
|
|
files_yaml: |
|
|
format:
|
|
- '**/*'
|
|
- '!**/*.md'
|
|
|
|
- uses: actions/setup-java@v3
|
|
with:
|
|
distribution: "zulu"
|
|
java-version: "17"
|
|
|
|
- uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.10"
|
|
|
|
- name: Set up CI Gradle Properties
|
|
run: |
|
|
mkdir -p ~/.gradle/
|
|
cat > ~/.gradle/gradle.properties <<EOF
|
|
org.gradle.jvmargs=-Xmx8g -Xss4m \
|
|
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
|
|
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
|
|
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
|
|
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
|
|
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
|
|
org.gradle.workers.max=8
|
|
org.gradle.vfs.watch=false
|
|
EOF
|
|
|
|
- name: Format
|
|
if: steps.changes.outputs.format_any_changed == 'true'
|
|
uses: Wandalen/wretry.action@v1.0.42
|
|
with:
|
|
command: ./gradlew format --scan --info --stacktrace
|
|
attempt_limit: 3
|
|
attempt_delay: 5000 # in ms
|
|
|
|
# This is helpful in the case that we change a previously committed generated file to be ignored by git.
|
|
- name: Remove any files that have been gitignored
|
|
run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached
|
|
|
|
- name: Commit Formatting Changes (PR)
|
|
uses: stefanzweifel/git-auto-commit-action@v4
|
|
# do not commit if master branch
|
|
if: github.ref != 'refs/heads/master'
|
|
with:
|
|
commit_message: Automated Commit - Formatting Changes
|
|
commit_user_name: Octavia Squidington III
|
|
commit_user_email: octavia-squidington-iii@users.noreply.github.com
|
|
|
|
- name: "Fail on Formatting Changes (Master)"
|
|
if: github.ref == 'refs/heads/master'
|
|
run: git --no-pager diff && test -z "$(git --no-pager diff)"
|
|
|
|
notify-failure-slack-channel:
|
|
name: "Notify Slack Channel on Build Failures"
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- format-and-commit
|
|
if: ${{ failure() && github.ref == 'refs/heads/master' }}
|
|
steps:
|
|
- name: Checkout Airbyte
|
|
uses: actions/checkout@v3
|
|
- name: Match GitHub User to Slack User
|
|
id: match-github-to-slack-user
|
|
uses: ./.github/actions/match-github-to-slack-user
|
|
env:
|
|
AIRBYTE_TEAM_BOT_SLACK_TOKEN: ${{ secrets.SLACK_AIRBYTE_TEAM_READ_USERS }}
|
|
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Format Failure on Master Slack Channel
|
|
uses: abinoda/slack-action@master
|
|
env:
|
|
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN_AIRBYTE_TEAM }}
|
|
with:
|
|
args: >-
|
|
{\"channel\":\"C03BEADRPNY\", \"blocks\":[
|
|
{\"type\":\"divider\"},
|
|
{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Formatting is broken on master! :bangbang: \n\n\"}},
|
|
{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"_merged by_: *${{ github.actor }}* \n\"}},
|
|
{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"<@${{ steps.match-github-to-slack-user.outputs.slack_user_ids }}> \n\"}},
|
|
{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\" :octavia-shocked: <https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}|View Action Run> :octavia-shocked: \n\"}},
|
|
{\"type\":\"divider\"}]}
|