Skip to content

Commit ad55b8c

Browse files
committed
first cut at API checking
Cabal-syntax and Cabal only; I assume cabal-install-solver is not a public API.
1 parent 969343a commit ad55b8c

File tree

4 files changed

+19141
-0
lines changed

4 files changed

+19141
-0
lines changed

.github/workflows/check-api.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Check API
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "doc/**"
7+
- "**/README.md"
8+
- "CONTRIBUTING.md"
9+
branches:
10+
- master
11+
pull_request:
12+
paths-ignore:
13+
- "doc/**"
14+
- "**/README.md"
15+
- "CONTRIBUTING.md"
16+
release:
17+
types:
18+
- created
19+
workflow_call:
20+
21+
jobs:
22+
check-api:
23+
name: Check API using ${{ matrix.sys.os }} ghc-${{ matrix.ghc }}
24+
runs-on: ${{ matrix.sys.os }}
25+
strategy:
26+
matrix:
27+
# we check API only on one platform and ghc release, since it shouldn't
28+
# vary elsewhere and the API tracer is sensitive to both
29+
sys:
30+
- { os: ubuntu-latest }
31+
ghc:
32+
[
33+
# print-api only supports a small subset of ghc versions
34+
"9.10.1",
35+
]
36+
37+
steps:
38+
39+
- uses: actions/checkout@v4
40+
41+
- uses: haskell-actions/setup@v2
42+
id: setup-haskell
43+
with:
44+
ghc-version: ${{ matrix.ghc }}
45+
cabal-version: 3.12.1.0 # see https://github.com/haskell/cabal/pull/10251
46+
ghcup-release-channel: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml
47+
48+
# I was going to use the canned action, but it only supports a single package and reinstalls the same binary each time
49+
- name: Install print-api
50+
run: |
51+
wget -q https://github.com/Kleidukos/print-api/releases/download/v0.1.0.1/print-api-0.1.0.1-Linux-static-${{ matrix.ghc }}-x86_64.tar.gz
52+
tar -xzvf print-api-0.1.0.1-Linux-static-${{ matrix.ghc }}-x86_64.tar.gz
53+
chmod +x print-api
54+
55+
# print-api needs environment files. It also doesn't make a lot of sense to use the cached builds, sadly,
56+
# since they're special in different ways (bootstrap and validate) and we want a vanilla build. And there
57+
# isn't enough cache space to make a third cache, even though this is a very limited build.
58+
- name: Build Cabal with environment files
59+
run: cabal build Cabal-syntax Cabal --write-ghc-environment-files=always
60+
61+
- name: Generate Cabal-syntax and Cabal APIs
62+
run: |
63+
./print-api --package-name Cabal-syntax > Cabal-syntax-${{ matrix.ghc }}-${{ matrix.sys.os }}.api
64+
./print-api --package-name Cabal > Cabal-${{ matrix.ghc }}-${{ matrix.sys.os }}.api
65+
66+
# for convenience, since large changes would be a pain to reconstruct from diffs and
67+
# contributors aren't guaranteed to have ubuntu-latest handy
68+
# run this _before_ checking the API, so hopefully they're available on failure
69+
# because that's the point of making them artifacts!
70+
- uses: actions/upload-artifact@v4
71+
with:
72+
name: Cabal-api
73+
path: '*.api'
74+
75+
- name: Check Cabal-syntax and Cabal APIs
76+
run: |
77+
echo "Cabal-syntax API changes:"
78+
diff Cabal-syntax/Cabal-syntax-${{ matrix.ghc }}-${{ matrix.sys.os }}.api Cabal-syntax-${{ matrix.ghc }}-${{ matrix.sys.os }}.api
79+
echo
80+
echo "Cabal API changes:"
81+
diff Cabal/Cabal-${{ matrix.ghc }}-${{ matrix.sys.os }}.api Cabal-${{ matrix.ghc }}-${{ matrix.sys.os }}.api

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ We use automated whitespace convention checking. Violations can be fixed by
193193
running [fix-whitespace](https://hackage.haskell.org/package/fix-whitespace). If
194194
you push a fix of a whitespace violation, please do so in a _separate commit_.
195195

196+
API Changes
197+
-----------
198+
199+
The `Check API` job tests the `Cabal` and `Cabal-syntax` packages for API changes.
200+
It's still something of a work in progress, but even in its current state it is
201+
useful to indicate when a changelog is needed and which PRs aren't appropriate
202+
for backports.
203+
204+
If the `Check API` job fails, you will find in its build artifacts (at the bottom
205+
of the job report page) a ZIP file containing the new API records. You can download
206+
this and replace the existing API descriptions, which can be found in the package
207+
top level directories, with `.api` suffixes.
208+
196209
Other Conventions
197210
-----------------
198211

0 commit comments

Comments
 (0)