Skip to content

Commit

Permalink
chore(ci): move apidiff to GitHub Action (#6901)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Oct 20, 2022
1 parent bd8eea3 commit aacddfd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 318 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/apidiff.yml
@@ -0,0 +1,83 @@
---
name: apidiff
on:
pull_request:

jobs:
scan_changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: main
- name: Get main commit
id: main
run: echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- name: Get changed directories
id: changed_dirs
# Ignore changes to the internal and root directories.
run: |
tree=$(git diff-tree --no-commit-id --name-only --diff-filter=DMR -r ${{ steps.main.outputs.hash }}..HEAD)
uniques=$(echo $tree | xargs -r -L1 dirname | uniq)
dirs=$(echo $uniques | grep -v -e 'internal' -e '\.' | cat)
if [ -z "$dirs" ]
then
echo "changed={\"changed\":[]}" >> $GITHUB_OUTPUT
echo "No changes worth diffing!"
else
for d in $dirs; do list=${list},\"${d}\"; done
echo "changed={\"changed\":[${list#,}]}" >> $GITHUB_OUTPUT
fi
outputs:
changed_dirs: ${{ steps.changed_dirs.outputs.changed }}
apidiff:
needs: scan_changes
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'breaking change allowed')"
continue-on-error: true
strategy:
matrix: ${{ fromJson(needs.scan_changes.outputs.changed_dirs) }}
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.18.3'
- name: Install latest apidiff
run: go install golang.org/x/exp/cmd/apidiff@latest
- uses: actions/checkout@v3
with:
ref: main
- name: Baseline name
id: baseline
run: |
export CHANGED=${{ matrix.changed }}
echo pkg="${CHANGED//\//_}_pkg.main" >> $GITHUB_OUTPUT
- name: Create Go package baseline
run: cd ${{ matrix.changed }} && apidiff -w ${{ steps.baseline.outputs.pkg }} .
- name: Upload baseline package data
uses: actions/upload-artifact@v3
with:
name: ${{ steps.baseline.outputs.pkg }}
path: ${{ matrix.changed }}/${{ steps.baseline.outputs.pkg }}
retention-days: 1
- uses: actions/checkout@v3
- name: Download baseline package data
uses: actions/download-artifact@v3
with:
name: ${{ steps.baseline.outputs.pkg }}
path: ${{ matrix.changed }}
- name: Compare regenerated code to baseline
run: |
cd ${{ matrix.changed }} && apidiff -incompatible ${{ steps.baseline.outputs.pkg }} . > diff.txt
cat diff.txt && ! [ -s diff.txt ]
- name: Add breaking change label
if: ${{ failure() && !github.event.pull_request.head.repo.fork }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: ${{ github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['breaking change']
})
227 changes: 0 additions & 227 deletions internal/apidiff/apidiff.go

This file was deleted.

66 changes: 0 additions & 66 deletions internal/apidiff/apidiff_test.go

This file was deleted.

0 comments on commit aacddfd

Please sign in to comment.