Skip to content

Commit d0caba3

Browse files
authored
Merge pull request #2069 from tweag/cg/refactor_ci_workflow
chore: refactor CI workflow
2 parents 98f96b6 + afdac73 commit d0caba3

File tree

5 files changed

+96
-46
lines changed

5 files changed

+96
-46
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Authenticate with GitHub API
2+
description: |
3+
Authenticated GitHub API requests are not rate-limited like unauthenticated requests.
4+
5+
# For more details: https://github.com/tweag/rules_haskell/pull/1494
6+
7+
inputs:
8+
github_token:
9+
type: string
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- shell: bash
15+
env:
16+
GITHUB_TOKEN: ${{ inputs.github_token }}
17+
run: |
18+
cat >~/.netrc <<EOF
19+
machine api.github.com
20+
password ${GITHUB_TOKEN}
21+
EOF
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Free Disk Space on Linux
2+
description: Remove unneeded files from the Ubuntu GitHub runner.
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- shell: bash
8+
if: ${{ runner.os == 'Linux' }}
9+
run: |-
10+
sudo swapoff -a
11+
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
12+
docker rmi $(docker images -q) -f
13+
14+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Install Apt Packages
2+
description: Install packages via apt-get install.
3+
4+
inputs:
5+
packages:
6+
type: string
7+
description: A space-separated list of apt packages to install.
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- shell: bash
13+
if: ${{ runner.os == 'Linux' }}
14+
env:
15+
APT_PACKAGES: ${{ inputs.packages }}
16+
run: |-
17+
sudo apt-get update
18+
sudo apt-get install --no-install-recommends -yy "${APT_PACKAGES}"
19+
sudo apt clean
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Set the TCP keep-alive time
2+
description: Avoids deadline exceeded errors on Linux.
3+
4+
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
5+
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
6+
7+
inputs:
8+
tcp_keepalive_time:
9+
type: number
10+
description: The value to be set for the TCP keep-alive time.
11+
default: 60
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- shell: bash
17+
if: ${{ runner.os == 'Linux' }}
18+
env:
19+
TCP_KEEPALIVE_TIME: ${{ inputs.tcp_keepalive_time }}
20+
run: |-
21+
sudo sysctl -w "net.ipv4.tcp_keepalive_time=${TCP_KEEPALIVE_TIME}"

.github/workflows/workflow.yaml

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ jobs:
2424
with:
2525
buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }}
2626
bazelrc_path: .bazelrc.auth
27+
- uses: ./.github/actions/set_tcp_keepalive_time
28+
- uses: ./.github/actions/authenticate_github_api
29+
with:
30+
github_token: ${{ secrets.GITHUB_TOKEN }}
2731
- name: Configure
2832
run: |
29-
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
30-
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
31-
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
3233
cat >>.bazelrc.local <<EOF
3334
common --config=ci
3435
EOF
35-
cat >~/.netrc <<EOF
36-
machine api.github.com
37-
password ${{ secrets.GITHUB_TOKEN }}
38-
EOF
3936
- run: |
4037
bazelisk test buildifier:buildifier_test
4138
@@ -64,12 +61,8 @@ jobs:
6461
bzlmod: true
6562
runs-on: ${{ matrix.os }}
6663
steps:
67-
- if: ${{ matrix.os == 'ubuntu-latest' }}
68-
run: |-
69-
sudo swapoff -a
70-
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
71-
docker rmi $(docker images -q) -f
7264
- uses: actions/checkout@v4
65+
- uses: ./.github/actions/free_disk_space_on_linux
7366
- name: Mount Bazel cache
7467
uses: actions/cache@v3
7568
with:
@@ -85,11 +78,12 @@ jobs:
8578
with:
8679
buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }}
8780
bazelrc_path: .bazelrc.auth
81+
- uses: ./.github/actions/set_tcp_keepalive_time
82+
- uses: ./.github/actions/authenticate_github_api
83+
with:
84+
github_token: ${{ secrets.GITHUB_TOKEN }}
8885
- name: Configure
8986
run: |
90-
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
91-
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
92-
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
9387
case ${{ runner.os }} in
9488
macOS) BUILD_CONFIG=ci-macos-nixpkgs;;
9589
Linux) BUILD_CONFIG=ci-linux-nixpkgs;;
@@ -101,10 +95,6 @@ jobs:
10195
EOF
10296
cp .bazelrc.local rules_haskell_nix
10397
cp .bazelrc.local rules_haskell_tests
104-
cat >~/.netrc <<EOF
105-
machine api.github.com
106-
password ${{ secrets.GITHUB_TOKEN }}
107-
EOF
10898
- name: Check Bazel version
10999
run: |
110100
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run .ci/check-bazel-version
@@ -175,15 +165,11 @@ jobs:
175165
GHC_VERSION: ${{ matrix.ghc }}
176166
runs-on: ${{ matrix.os }}
177167
steps:
178-
- if: ${{ matrix.os == 'ubuntu-latest' }}
179-
run: |-
180-
sudo swapoff -a
181-
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
182-
sudo apt-get update
183-
sudo apt-get install --no-install-recommends -yy libtinfo5
184-
sudo apt clean
185-
docker rmi $(docker images -q) -f
186168
- uses: actions/checkout@v4
169+
- uses: ./.github/actions/free_disk_space_on_linux
170+
- uses: ./.github/actions/install_apt_pkgs
171+
with:
172+
packages: libtinfo5
187173
- name: Mount Bazel cache
188174
uses: actions/cache@v3
189175
with:
@@ -199,12 +185,13 @@ jobs:
199185
with:
200186
buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }}
201187
bazelrc_path: .bazelrc.auth
188+
- uses: ./.github/actions/set_tcp_keepalive_time
189+
- uses: ./.github/actions/authenticate_github_api
190+
with:
191+
github_token: ${{ secrets.GITHUB_TOKEN }}
202192
- name: Configure
203193
shell: bash
204194
run: |
205-
# Avoid failures of the form `deadline exceeded after 14999958197ns DEADLINE_EXCEEDED`.
206-
# See https://github.com/tweag/rules_haskell/issues/1498 and https://github.com/tweag/rules_haskell/pull/1692.
207-
[[ ${{ runner.os }} == Linux ]] && sudo sysctl -w net.ipv4.tcp_keepalive_time=60
208195
case "${{ runner.os }},${{ matrix.module }}" in
209196
macOS,*) BUILD_CONFIG=ci-macos-bindist;;
210197
Linux,*) BUILD_CONFIG=ci-linux-bindist;;
@@ -232,33 +219,21 @@ jobs:
232219
common --enable_bzlmod=${{ matrix.bzlmod }}
233220
EOF
234221
cp .bazelrc.local rules_haskell_tests
235-
cat >~/.netrc <<EOF
236-
machine api.github.com
237-
password ${{ secrets.GITHUB_TOKEN }}
238-
EOF
239222
- name: Build & test - rules_haskell
240223
if: matrix.module == 'rules_haskell'
241224
shell: bash
242225
run: |
243-
if [[ ${{ runner.os }} == Windows ]]; then
244-
# On Windows `//...` expands to `/...`.
245-
bazel test ///...
246-
else
247-
bazel test //...
248-
fi
226+
# Quote the package specifier so that it works on Windows
227+
bazel test "//..."
249228
250229
- name: Build & test - rules_haskell_tests
251230
if: matrix.module == 'rules_haskell_tests'
252231
shell: bash
253232
run: |
254233
cd rules_haskell_tests
255234
./tests/run-start-script.sh --use-bindists --with-bzlmod=${{ matrix.bzlmod }}
256-
if [[ ${{ runner.os }} == Windows ]]; then
257-
# On Windows `//...` expands to `/...`.
258-
bazel test ///...
259-
else
260-
bazel test //...
261-
fi
235+
# Quote the package specifier so that it works on Windows
236+
bazel test "//..."
262237
# Test stack_snapshot pinning
263238
# NOTE keep in sync with tests/RunTests.hs
264239
bazel run @stackage-pinning-test-unpinned//:pin

0 commit comments

Comments
 (0)