1
name: pull request comment
6
GH_USER: "github-actions[bot]"
7
GH_EMAIL: "<41898282+github-actions[bot]@users.noreply.github.com>"
8
CI_TOOLS_DIR: /home/runner/work/kuma/kuma/.ci_tools
14
if: github.event.issue.pull_request != '' && (contains(github.event.comment.body, '/format') || contains(github.event.comment.body, '/golden_files'))
15
runs-on: ubuntu-latest
17
- name: Generate GitHub app token
19
uses: actions/create-github-app-token@f4c6bf6752984b3a29fcc135a5e70eb792c40c6b # v1.8.0
21
app-id: ${{ secrets.APP_ID }}
22
private-key: ${{ secrets.APP_PRIVATE_KEY }}
23
- name: check-maintainer
25
# Ensure the commenter is a maintainer
26
if [[ `gh api '/repos/${{ github.repository }}/collaborators?permission=maintain' --paginate --jq '.[].login' | grep ${{ github.event.comment.user.login }}` ]]; then
27
gh api --method POST -f content='+1' ${{ github.event.comment.url }}/reactions
29
gh api --method POST -f content='-1' ${{ github.event.comment.url }}/reactions
30
echo "${{ github.event.comment.user.login }} is not a maintainer of the repo, can't run this action"
34
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
37
echo "BRANCH_NAME=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName --jq '.headRefName')" >> $GITHUB_ENV
38
echo "REPO=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRepository,headRepositoryOwner --jq '[.headRepositoryOwner.login,.headRepository.name] | join("/")')" >> $GITHUB_ENV
40
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
41
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
44
repository: ${{ env.REPO }}
45
ref: ${{ env.BRANCH_NAME }}
46
token: ${{ steps.github-app-token.outputs.token }}
47
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
49
go-version-file: go.mod
50
- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
53
${{ env.CI_TOOLS_DIR }}
54
key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
56
${{ runner.os }}-${{ runner.arch }}-devtools
60
if: contains(github.event.comment.body, '/format') # check the comment if it contains the keywords
62
make clean/generated generate format
63
- name: run golden_files
64
if: contains(github.event.comment.body, '/golden_files') # check the comment if it contains the keywords
66
make test UPDATE_GOLDEN_FILES=true
67
- name: commit and push fixes
69
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
71
if git diff --exit-code --stat; then
72
echo "No change detected, skipping git push"
74
git config user.name "${GH_USER}"
75
git config user.email "${GH_EMAIL}"
76
git commit -s -m "fix(ci): format files" .
79
- run: gh api --method POST -f content='hooray' ${{ github.event.comment.url }}/reactions
81
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}