-
Notifications
You must be signed in to change notification settings - Fork 14
/
action.yml
73 lines (72 loc) · 2.55 KB
/
action.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
name: 'go-apidiff'
description: 'Test API compatibility of changes in your Go library'
branding:
icon: 'code'
color: 'blue'
inputs:
base-ref:
description: 'Base reference for API compatibility comparison (default: base branch)'
required: false
default: "${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}"
version:
description: 'Version of go-apidiff to use'
required: false
default: "latest"
compare-imports:
description: 'Compare exported API differences in the imports of the repo.'
required: false
default: 'false'
print-compatible:
description: 'Print compatible API changes'
required: false
default: 'true'
repo-path:
description: 'Path to root of git repository to compare'
required: false
default: '.'
outputs:
semver-type:
description: "Returns the type (patch, minor, major) of the sementic version that would be required if producing a release."
value: ${{ steps.go-apidiff.outputs.semver-type }}
output:
description: "Contains diff output information"
value: ${{ steps.go-apidiff.outputs.output }}
runs:
using: 'composite'
steps:
- shell: bash
id: go-apidiff
run: |
if [[ "${{ github.repository }}" == "joelanford/go-apidiff" && "${{ inputs.version }}" == "latest" ]]; then
echo "*** Installing go-apidiff from source ***"
go install .
else
INSTALL_CMD="go install"
if [[ "$(go version | cut -d' ' -f3 | cut -d'.' -f2 | grep -o -E '[0-9]+' | head -1)" -lt "16" ]]; then
INSTALL_CMD="go get"
fi
DIR=$(mktemp -d)
(cd ${DIR} && GO111MODULE=on ${INSTALL_CMD} github.com/joelanford/go-apidiff@${{ inputs.version }}) && rmdir ${DIR}
fi
set -x
GOPATH=$(go env GOPATH)
set +e
OUTPUT=$($GOPATH/bin/go-apidiff ${{ inputs.base-ref }} --compare-imports=${{ inputs.compare-imports }} --print-compatible=${{ inputs.print-compatible }} --repo-path=${{ inputs.repo-path }})
GOAPIDIFF_RC=$?
set -e
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
{
echo "output<<$EOF"
echo "$OUTPUT"
echo "$EOF"
} >> $GITHUB_OUTPUT
if [ $GOAPIDIFF_RC -eq 0 ]; then
if [ -z "$OUTPUT" ]; then
echo "semver-type=patch" >> $GITHUB_OUTPUT
exit 0
fi
echo "semver-type=minor" >> $GITHUB_OUTPUT
exit 0
fi
echo "semver-type=major" >> $GITHUB_OUTPUT
exit $GOAPIDIFF_RC