Skip to content

CI pr-format: GitHub Appのトークンを使う #12053

CI pr-format: GitHub Appのトークンを使う

CI pr-format: GitHub Appのトークンを使う #12053

Workflow file for this run

---
name: pr-format
# pull_requestで何かあった時に起動する
on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
push:
branches:
- master
permissions:
contents: write
pull-requests: write
jobs:
# PRが来たらformatをかけてみて、差分があればPRを作って、エラーで落ちるjob
pr-format:
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
with:
app-id: ${{ secrets.PROJECT_AUTOMATION_APP_ID }}
private-key: ${{ secrets.PROJECT_AUTOMATION_PRIVATE_KEY }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
if: github.event_name != 'pull_request' || github.event.action != 'closed'
with:
# ここでsubmodule持ってくるとdetached headにcommitして死ぬ
# submodule: 'recursive'
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
token: ${{steps.generate_token.outputs.token}}
- name: Get uv version
id: get_uv_version
if: github.event_name != 'pull_request' || github.event.action != 'closed'
run: echo "uv_version=$(sed -e 's/uv==//g' requirements.txt)" >> "$GITHUB_OUTPUT"
- name: Set up uv
uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5.1.0
if: github.event_name != 'pull_request' || github.event.action != 'closed'
with:
version: ${{steps.get_uv_version.outputs.uv_version}}
enable-cache: true
- name: Install dependencies
if: github.event_name != 'pull_request' || github.event.action != 'closed'
run: bash "${GITHUB_WORKSPACE}/scripts/uv_install.sh"
# formatする
# --exit-codeをつけることで、autopep8内でエラーが起きれば1、差分があれば2のエラーステータスコードが返ってくる。正常時は0が返る
- name: Format files
id: format
if: github.event_name != 'pull_request' || github.event.action != 'closed'
run: bash "${GITHUB_WORKSPACE}/scripts/pr_format/pr_format/format.sh"
- uses: dev-hato/actions-diff-pr-management@cc201e3df74a342983025c4e97b7216b4e77f9f1 # v2.0.0
if: success() || failure()
with:
github-token: ${{steps.generate_token.outputs.token}}
branch-name-prefix: fix-format
pr-title-prefix: formatが間違ってたので直してあげたよ!
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true