Debian Codegraph @

.github/workflows/apidiff.yaml

raw
1 ---
2 name: apidiff
3 on:
4 pull_request:
5
6 env:
7 PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
8
9 jobs:
10 scan_changes:
11 runs-on: ubuntu-latest
12 steps:
13 - uses: actions/checkout@v6
14 with:
15 ref: main
16 - name: Get main commit
17 id: main
18 run: echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
19 - uses: actions/checkout@v6
20 - uses: actions/setup-go@v6
21 with:
22 go-version: '1.26.2'
23 - name: Get changed directories
24 id: changed_dirs
25 # Ignore changes to the internal and root directories.
26 run: |
27 dirs=$(go run ./internal/actions/cmd/changefinder -q)
28 if [ -z "$dirs" ]
29 then
30 echo "skip=1" >> $GITHUB_OUTPUT
31 echo "No changes worth diffing!"
32 else
33 for d in $dirs; do list=${list},\"${d}\"; done
34 echo "changed={\"changed\":[${list#,}]}" >> $GITHUB_OUTPUT
35 echo "skip=" >> $GITHUB_OUTPUT
36 fi
37 outputs:
38 changed_dirs: ${{ steps.changed_dirs.outputs.changed }}
39 skip: ${{ steps.changed_dirs.outputs.skip }}
40 apidiff:
41 needs: scan_changes
42 runs-on: ubuntu-latest
43 if: "!needs.scan_changes.outputs.skip && !contains(github.event.pull_request.labels.*.name, 'breaking change allowed')"
44 continue-on-error: true
45 strategy:
46 matrix: ${{ fromJson(needs.scan_changes.outputs.changed_dirs) }}
47 steps:
48 - uses: actions/setup-go@v6
49 with:
50 go-version: '1.26.2'
51 - name: Install latest apidiff
52 run: go install golang.org/x/exp/cmd/apidiff@latest
53 - uses: actions/checkout@v6
54 with:
55 ref: main
56 - name: Create baseline
57 id: baseline
58 run: |
59 export CHANGED=${{ matrix.changed }}
60 echo pkg="${CHANGED//\//_}_pkg.main" >> $GITHUB_OUTPUT
61 - name: Create Go package baseline
62 run: cd ${{ matrix.changed }} && apidiff -m -w ${{ steps.baseline.outputs.pkg }} .
63 - name: Upload baseline package data
64 uses: actions/upload-artifact@v7
65 with:
66 name: ${{ steps.baseline.outputs.pkg }}
67 path: ${{ matrix.changed }}/${{ steps.baseline.outputs.pkg }}
68 retention-days: 1
69 - uses: actions/checkout@v6
70 - name: Download baseline package data
71 uses: actions/download-artifact@v8
72 with:
73 name: ${{ steps.baseline.outputs.pkg }}
74 path: ${{ matrix.changed }}
75 - name: Compare regenerated code to baseline
76 # Only ignore Go interface additions when the PR is from OwlBot as it is
77 # likely a new method added to the gRPC client stub interface, which is
78 # non-breaking.
79 run: |
80 cd ${{ matrix.changed }} && apidiff -m -incompatible ${{ steps.baseline.outputs.pkg }} . > diff.txt
81 if [[ $PR_HEAD_REF == owl-bot-copy ]]; then
82 sed -i '/: added/d' ./diff.txt
83 fi
84 cat diff.txt && ! [ -s diff.txt ]
85 - name: Add breaking change label
86 if: ${{ failure() && !github.event.pull_request.head.repo.fork }}
87 uses: actions/github-script@v9
88 with:
89 script: |
90 github.rest.issues.addLabels({
91 issue_number: ${{ github.event.number }},
92 owner: context.repo.owner,
93 repo: context.repo.repo,
94 labels: ['breaking change']
95 })