Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOID] Adds job to apply formatting in PRs #520

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/actions/gradle-command-on-pr/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: "Run gradle command on pull request"

inputs:
gradle-command:
description: "Gradle command to run"
required: true
TEAMCITY_DEV_URL:
required: true
TEAMCITY_USER:
required: true
TEAMCITY_PASSWORD:
required: true
SERVICE_ACCOUNT_PAT:
required: true

runs:
using: "composite"
steps:
- name: Checkout branch from fork
uses: actions/checkout@v3
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- uses: ./.github/actions/setup-jdk
- uses: ./.github/actions/setup-gradle-cache

- name: Calls gradle command
shell: bash
env:
TEAMCITY_DEV_URL: ${{ inputs.TEAMCITY_DEV_URL }}
TEAMCITY_USER: ${{ inputs.TEAMCITY_USER }}
TEAMCITY_PASSWORD: ${{ inputs.TEAMCITY_PASSWORD }}
run: |
./gradlew ${{ inputs.gradle-command }}

- name: Check for modified files
shell: bash
id: git-check
run: echo modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi) >> $GITHUB_OUTPUT

- name: Commit to the PR branch
shell: bash
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'neo-technology-build-agent'
git config --global user.email '[email protected]'
git add -A
git commit -m "Run ${{ inputs.gradle-command }}"

- name: Push changes
uses: ad-m/github-push-action@d91a481090679876dfc4178fef17f286781251df # v0.8.0
with:
github_token: ${{ inputs.SERVICE_ACCOUNT_PAT }}
branch: ${{ github.event.client_payload.pull_request.head.ref }}

- name: Add reaction on pushed changes
if: ${{ success() && steps.git-check.outputs.modified == 'true' }}
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray

- name: Add reaction when no update is needed
if: ${{ success() && steps.git-check.outputs.modified == 'false' }}
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: '+1'

- name: Create URL to the run output for failure report
shell: bash
if: ${{ !success() }}
id: vars
run: echo run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID >> $GITHUB_OUTPUT

- name: Create comment with URL on failure
if: ${{ !success() }}
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
body: |
:x: [${{ inputs.gradle-command }} failed][1]

[1]: ${{ steps.vars.outputs.run-url }}

- name: Report failure to original comment with a reaction
if: ${{ !success() }}
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: '-1'

- name: Go back to original branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.base.ref }}
17 changes: 17 additions & 0 deletions .github/workflows/ChatOps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
permissions: write-all
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v3
with:
issue-type: pull-request
reaction-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.SERVICE_ACCOUNT_PAT }}
commands: |
spotlessApply
19 changes: 19 additions & 0 deletions .github/workflows/spotlessApply-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Formats PR
on:
repository_dispatch:
types: [spotlessApply-command]

jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Format and push changes to PR
uses: ./.github/actions/gradle-command-on-pr
with:
gradle-command: spotlessApply
TEAMCITY_DEV_URL: ${{ secrets.TEAMCITY_DEV_URL }}
TEAMCITY_USER: ${{ secrets.TEAMCITY_USER }}
TEAMCITY_PASSWORD: ${{ secrets.TEAMCITY_PASSWORD }}
SERVICE_ACCOUNT_PAT: ${{ secrets.SERVICE_ACCOUNT_PAT }}