aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/openapi-pull-request.yml
blob: dc8ba3ab3e3bf9cf6e96a2cb57003b90965e5288 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: OpenAPI Check
on:
  pull_request:

jobs:
  ancestor:
    name: Common Ancestor
    runs-on: ubuntu-latest
    outputs:
      base_ref: ${{ steps.ancestor.outputs.base_ref }}
    steps:
    - name: Checkout Repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        repository: ${{ github.event.pull_request.head.repo.full_name }}
        fetch-depth: 0
    - name: Search History
      id: ancestor
      run: |
        git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}
        git fetch --prune --progress --no-recurse-submodules upstream +refs/heads/*:refs/remotes/upstream/* +refs/tags/*:refs/tags/*

        ANCESTOR_REF=$(git merge-base upstream/${{ github.base_ref }} HEAD)

        echo "ref: ${ANCESTOR_REF}"

        echo "base_ref=${ANCESTOR_REF}" >> "$GITHUB_OUTPUT"

  head:
    name: Head Artifact
    uses: ./.github/workflows/openapi-generate.yml
    with:
      ref: ${{ github.event.pull_request.head.sha }}
      repository: ${{ github.event.pull_request.head.repo.full_name }}
      artifact: openapi-head

  base:
    name: Base Artifact
    uses: ./.github/workflows/openapi-generate.yml
    needs:
    - ancestor
    with:
      ref: ${{ needs.ancestor.outputs.base_ref }}
      repository: ${{ github.event.pull_request.base.repo.full_name }}
      artifact: openapi-base

  diff:
    name: Generate Report
    runs-on: ubuntu-latest
    needs:
    - head
    - base
    steps:
    - name: Download Head
      uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
      with:
        name: openapi-head
        path: openapi-head
    - name: Download Base
      uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
      with:
        name: openapi-base
        path: openapi-base
    - name: Detect Changes
      runs-on: ubuntu-latest
      id: openapi-diff
      with:
        old-spec: openapi-base/openapi.json
        new-spec: openapi-head/openapi.json
      run: |
        sed 's:allOf:oneOf:g' openapi-head/openapi.json
        sed 's:allOf:oneOf:g' openapi-base/openapi.json

        mkdir -p /tmp/openapi-report
        mv openapi-head/openapi.json /tmp/openapi-report/head.json
        mv openapi-base/openapi.json /tmp/openapi-report/base.json

        docker run -v /tmp/openapi-report:/data openapitools/openapi-diff:2.1.6 /data/base.json /data/head.json --state -l ERROR --markdown /data/openapi-report.md
    - name: Upload Artifact
      uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
      with:
        name: openapi-report
        path: /tmp/openapi-report/openapi-report.md