-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (73 loc) · 2.67 KB
/
check_pr_scope.yml
File metadata and controls
82 lines (73 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Check PR Scope
on:
pull_request:
types: [opened, synchronize, reopened, edited]
jobs:
check_scope:
runs-on: ubuntu-latest
outputs:
outcome: ${{ steps.check_scope_step.outcome }}
pr_scopes: ${{ steps.check_scope_step.outputs.pr_scopes }}
files: ${{ steps.changed_files.outputs.files }}
required_scopes: ${{ steps.check_scope_step.outputs.required_scopes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Get PR title
id: pr_title
run: |
title=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH")
echo "$title"
echo "title=$title" >> $GITHUB_OUTPUT
- name: Debug PR title output
run: |
echo "PR title from output: ${{ steps.pr_title.outputs.title }}"
- name: Get changed files
id: changed_files
env:
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
run: |
files=$(git diff --name-only origin/"$BASE_REF"...origin/"$HEAD_REF")
{
echo "files<<EOF"
echo "$files"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Debug before Check PR scope
run: |
echo "PR title just before check: ${{ steps.pr_title.outputs.title }}"
echo "Changed files: ${{ steps.changed_files.outputs.files }}"
- name: Check PR scope
id: check_scope_step # Add id to this step
run: |
chmod +x scripts/check_pr_scope.sh
./scripts/check_pr_scope.sh "${{ steps.pr_title.outputs.title }}" "${{ steps.changed_files.outputs.files }}"
comment_on_pr:
if: failure() && needs.check_scope.outputs.outcome == 'failure'
needs: check_scope
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Set comment body
id: set_comment_body
run: |
{
echo 'comment_body<<EOF'
echo "PRのスコープが正しくありません。\n現在のスコープ: ${{ needs.check_scope.outputs.pr_scopes }}\n検知したスコープ: ${{ needs.check_scope.outputs.required_scopes }}"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Comment on PR
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const body = `${{ steps.set_comment_body.outputs.comment_body }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});