-
Notifications
You must be signed in to change notification settings - Fork 1.3k
100 lines (98 loc) · 3.33 KB
/
apidiff.yml
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
88
89
90
91
92
93
94
95
96
97
98
99
100
---
name: apidiff
on:
pull_request:
permissions:
contents: read
jobs:
scan_changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Get main commit
id: main
run: echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- name: Get changed directories
id: changed_dirs
# Ignore changes to the internal and root directories.
# Ignore added files with --diff-filter=a.
run: |
dirs=$(go run ./internal/actions/cmd/changefinder -q --diff-filter=a)
if [ -z "$dirs" ]
then
echo "skip=1" >> $GITHUB_OUTPUT
echo "No changes worth diffing!"
else
for d in $dirs; do list=${list},\"${d}\"; done
echo "changed={\"changed\":[${list#,}]}" >> $GITHUB_OUTPUT
echo "skip=" >> $GITHUB_OUTPUT
fi
outputs:
changed_dirs: ${{ steps.changed_dirs.outputs.changed }}
skip: ${{ steps.changed_dirs.outputs.skip }}
apidiff:
needs: scan_changes
runs-on: ubuntu-latest
if: ${{ !needs.scan_changes.outputs.skip && !contains(github.event.pull_request.labels.*.name, 'breaking change allowed') }}
continue-on-error: true
permissions:
pull-requests: write
strategy:
matrix: ${{ fromJson(needs.scan_changes.outputs.changed_dirs) }}
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- name: Install latest apidiff
run: go install golang.org/x/exp/cmd/apidiff@latest
- uses: actions/checkout@v4
with:
ref: main
- name: Create baseline
id: baseline
run: |
export CHANGED=${{ matrix.changed }}
echo pkg="${CHANGED//\//_}_pkg.main" >> $GITHUB_OUTPUT
- name: Create Go package baseline
run: cd ${{ matrix.changed }} && apidiff -m -w ${{ steps.baseline.outputs.pkg }} .
- name: Upload baseline package data
uses: actions/upload-artifact@v4
with:
name: ${{ steps.baseline.outputs.pkg }}
path: ${{ matrix.changed }}/${{ steps.baseline.outputs.pkg }}
retention-days: 1
- uses: actions/checkout@v4
- name: Download baseline package data
uses: actions/download-artifact@v4
with:
name: ${{ steps.baseline.outputs.pkg }}
path: ${{ matrix.changed }}
- name: Compare regenerated code to baseline
# Only ignore Go interface additions when the PR is from OwlBot as it is
# likely a new method added to the gRPC client stub interface, which is
# non-breaking.
env:
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
cd ${{ matrix.changed }} && apidiff -m -incompatible ${{ steps.baseline.outputs.pkg }} . > diff.txt
if [[ "$PR_HEAD_REF" == owl-bot-copy ]]; then
sed -i '/: added/d' ./diff.txt
fi
cat diff.txt && ! [ -s diff.txt ]
- name: Add breaking change label
if: ${{ failure() && !github.event.pull_request.head.repo.fork }}
uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
issue_number: ${{ github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['breaking change']
})