generated from broadinstitute/golang-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (76 loc) · 2.58 KB
/
sherlock-check-api-diff.yaml
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
85
86
87
name: API Diff
on:
pull_request:
branches:
- main
concurrency:
# Don't run this workflow concurrently on the same branch
group: ${{ github.workflow }}-${{ github.ref }}
# For PRs, don't wait for completion of existing runs, cancel them instead
cancel-in-progress: true
jobs:
api-diff:
runs-on: ubuntu-latest
permissions:
contents: "read"
# Make comments
pull-requests: "write"
steps:
- name: Checkout Base
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
persist-credentials: false
- name: Checkout Head
uses: actions/checkout@v4
with:
path: head
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: head/sherlock/go.mod
- name: Set up Swag
working-directory: head
run: make install-swagger
- name: Generate Swagger source
working-directory: head
run: make generate-swagger
# This runs online, but if we hit issues with it, we can run it offline
# https://github.com/char0n/swagger-editor-validate/tree/master
- name: Validate Swagger source
uses: char0n/swagger-editor-validate@v1
with:
definition-file: head/sherlock/docs/swagger.yaml
- name: Create output directory
if: ${{ github.actor != 'dependabot[bot]' }}
run: mkdir output
- name: Generate diff
run: |
docker run --rm -t \
-v "$(pwd)/base/sherlock/docs:/specs/base:ro" \
-v "$(pwd)/head/sherlock/docs:/specs/head:ro" \
-v "$(pwd)/output:/output" \
openapitools/openapi-diff:latest \
--log INFO \
${{ (github.actor == 'dependabot[bot]' && '--fail-on-changed') || '--markdown /output/diff.md' }} \
/specs/base/swagger.yaml \
/specs/head/swagger.yaml
- name: Check diff
id: check-diff
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
if [[ -z $(grep '[^[:space:]]' output/diff.md) ]] ; then
echo present=false >> $GITHUB_OUTPUT
else
echo present=true >> $GITHUB_OUTPUT
fi
- name: Comment diff
if: ${{ github.actor != 'dependabot[bot]' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: api-diff
path: ${{ (steps.check-diff.outputs.present == 'true' && 'output/diff.md') || '' }}
message: |
No API changes detected