aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/openapi-workflow-run.yml
blob: 9dbd2c40a0dcec6dcf6cd95a92b0915ba71346f9 (plain)
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
name: OpenAPI Report

on:
  workflow_run:
    workflows:
    - OpenAPI Check
    types:
    - completed

jobs:
  metadata:
    name: Generate Metadata
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    outputs:
      pr_number: ${{ steps.pr_number.outputs.pr_number }}
    steps:
    - name: Get Pull Request Number
      id: pr_number
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
      run: |
        API_RESPONSE=$(gh pr list --repo "${GITHUB_REPOSITORY}" --search "${HEAD_SHA}" --state open --json number)
        PR_NUMBER=$(echo "${API_RESPONSE}" | jq '.[0].number')

        echo "repository: ${GITHUB_REPOSITORY}"
        echo "sha: ${HEAD_SHA}"
        echo "response: ${API_RESPONSE}"
        echo "pr: ${PR_NUMBER}"

        echo "pr_number=${PR_NUMBER}" >> "${GITHUB_OUTPUT}"

  comment:
    name: Pull Request Comment
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    needs:
    - metadata
    permissions:
      pull-requests: write
      actions: read
      contents: read
    steps:
    - name: Download OpenAPI Report
      id: download_report
      uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
      with:
        name: openapi-diff-report
        path: openapi-diff-report
        run-id: ${{ github.event.workflow_run.id }}
        github-token: ${{ secrets.GITHUB_TOKEN }}
    - name: Push Comment
      uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
      with:
        github-token: ${{ secrets.JF_BOT_TOKEN }}
        file-path: ${{ steps.download_report.outputs.download-path }}/openapi-changelog.md
        pr-number: ${{ needs.metadata.outputs.pr_number }}
        comment-tag: openapi-report