-
Notifications
You must be signed in to change notification settings - Fork 5
152 lines (147 loc) · 6.64 KB
/
workflow.yaml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Continuous integration
on:
push:
branches: main
pull_request:
branches: main
workflow_dispatch: # allows manual triggering
schedule:
- cron: '1 11 * * *'
env:
# Bump this number to invalidate the GH actions cache
cache-version: 0
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
jobs:
test-nixpkgs:
name: Build & Test - Nixpkgs
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: [ghc_8_10_7, ghc_9_0_2, ghc_9_2_7, ghc_9_4_5]
enable-bzlmod: [false]
include:
- os: ubuntu-latest
ghc-version: ghc_9_2_7
enable-bzlmod: true
- os: ubuntu-latest
ghc-version: ghc_9_4_5
enable-bzlmod: true
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Mount Bazel cache
uses: actions/cache@v3
with:
path: ~/repo-cache
key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=./nixpkgs.nix
- uses: tweag/configure-bazel-remote-cache-auth@v0
with:
buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }}
bazelrc_path: .bazelrc.auth
- name: Configure
run: |
# Convert "ghc_X_Y_Z" to "X.Y.Z".
GHC_VERSION="$(sed 's/^ghc_//;s/_/./g' <<<"${{ matrix.ghc-version }}")"
bzlmod_setting=
if [[ ${{ matrix.enable-bzlmod }} = true ]]; then
bzlmod_setting="common --config=bzlmod"
# Update the GHC_VERSION in MODULE.bazel
sed -i.bak 's/^GHC_VERSION = .*$/GHC_VERSION = "'"$GHC_VERSION"'"/g' example/MODULE.bazel
fi
cat >>.bazelrc.local <<EOF
build --host_platform=@rules_nixpkgs_core//platforms:host
build --config=remote-cache
build --repository_cache=~/repo-cache/
$bzlmod_setting
EOF
ln -s ../.bazelrc.local example/.bazelrc.local
ln -s ../../.bazelrc.local tests/alternative-deps/.bazelrc.local
- name: Build & test
if: ${{ !matrix.enable-bzlmod }}
uses: tweag/run-nix-shell@v0
with:
run: bazel test --config=${{ matrix.ghc-version }} --test_output=all //...
- name: Test the example
run: |
cd example
nix-shell --pure --run 'bazel run //:gazelle --config=${{ matrix.ghc-version }}'
# Gazelle doesn't remove rules by default
grep -q another-haskell-binary package-a/BUILD.bazel
nix-shell --pure --run 'bazel run //:gazelle --config=${{ matrix.ghc-version }} -- fix -mode diff' || true
nix-shell --pure --run 'bazel run //:gazelle --config=${{ matrix.ghc-version }} -- fix'
# Test that fix kept and removed the expected rules
echo "! grep -q another-haskell-binary package-a/BUILD.bazel"
bash -c "! grep -q another-haskell-binary package-a/BUILD.bazel"
echo grep -q a-haskell-binary package-a/BUILD.bazel
grep -q a-haskell-binary package-a/BUILD.bazel
echo grep -q haskell_toolchain_library package-a/BUILD.bazel
grep -q haskell_toolchain_library package-a/BUILD.bazel
# Test main_file attribute (taken from cabal's main_is)
# Simple scenario: main-is: Main.hs & hs-source-dirs: app
bash -cx 'grep -q "main_file = \"app/Main.hs\"" package-a/BUILD.bazel'
# Check concatenation when main-is: prank/Main.B and hs-source-dirs: app
bash -cx 'grep -q "main_file = \"app/prank/MainB.hs\"" package-a/BUILD.bazel'
# Test sublibrary generation
bash -cx "grep -q \"sublibPub\" package-b/BUILD.bazel"
bash -cx "grep -q \"mtl\" package-b/BUILD.bazel"
# Test sublibrary shadowing
bash -cx "grep -q \":sublibPub\" package-b/BUILD.bazel"
bash -cx "grep -q \":mtl\" package-b/BUILD.bazel"
# Test public internal library feature
bash -cx "grep -q \"//package-b:sublibPub\" package-a/BUILD.bazel"
# Test dependency on local libraries (the same name)
bash -cx "grep -q \":sublibPub\" package-a/BUILD.bazel"
bash -cx "grep -q \":sublibPriv\" package-a/BUILD.bazel"
# Test dependency on local libraries (the same name)
# with experimental colon syntax
bash -cx "grep -q \":colonPub\" package-a/BUILD.bazel"
bash -cx "grep -q \":colonPriv\" package-a/BUILD.bazel"
# Test existence of package-b main lib dependency
# referenced with colon syntax: package-b:package-b
bash -cx "grep -q \"//package-b\" package-a/BUILD.bazel"
# Test existence of package-c main library
# referenced without colon syntax: package-c
bash -cx "grep -q \"//package-c\" package-a/BUILD.bazel"
# Test that unknown libraries referenced with colon syntax
# are resolved from repository
bash -cx "grep -q \"@stackage//:tasty\" package-a/BUILD.bazel"
# Test sublibrary local dependency resolution
# mtl must be taken from repo not from package-b
bash -cx "grep -q \"@stackage//:mtl\" package-a/BUILD.bazel"
bash -cx "! grep -q \"//package-b:mtl\" package-a/BUILD.bazel"
# Test that colon syntax allows to reference both
# local and other package dependency
bash -cx "grep -q \":mtl\" package-b/BUILD.bazel"
bash -cx "grep -q \"//package-c:mtl\" package-b/BUILD.bazel"
# Test gazelle-update-repos
nix-shell --pure --run 'bazel run //:gazelle-update-repos --config=${{ matrix.ghc-version }}'
nix-shell --pure --run 'bazel test //... --config=${{ matrix.ghc-version }}'
- name: Test alternative dependencies
if: ${{ !matrix.enable-bzlmod }}
uses: tweag/run-nix-shell@v0
with:
working-directory: tests/alternative-deps
run: |
bazel run //:gazelle --config=${{ matrix.ghc-version }}
bazel run //:gazelle-update-repos --config=${{ matrix.ghc-version }}
bazel test //... --config=${{ matrix.ghc-version }}
- name: Test for buildifier suggestions
if: ${{ !matrix.enable-bzlmod }}
uses: tweag/run-nix-shell@v0
with:
run: bazel run //:buildifier-diff
all_ci_tests:
runs-on: ubuntu-latest
needs:
- test-nixpkgs
if: ${{ always() }}
steps:
- uses: cgrindel/gha_join_jobs@794a2d117251f22607f1aab937d3fd3eaaf9a2f5 # v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}