Skip to content

Commit 5dd9179

Browse files
authored
feat: initial implementation (#1)
- The initial implementation for the action. - `/tools/run_nix_shell.sh`: The core logic for the action. - `/action.yaml`: The GitHub action definition. - Nix configuration files to support the testing of the action (`/flake.nix`, `/flake.lock`, `/nixpkgs.nix`). - Unit tests (`/tests/tools_tests`) that can be exercised using Bazel. - Files used in the integration tests (`/tests/integration_tests`). The actual integration tests are defined in the CI workflow file. - A CI workflow to test PRs and run a daily build. - `README.md` with usage information. Related to https://github.com/tweag/scalable-builds-group/issues/97. Related to https://github.com/tweag/scalable-builds-group/issues/138.
1 parent 5daa940 commit 5dd9179

30 files changed

+760
-2
lines changed

.bazelrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
build --enable_bzlmod
2+
3+
# CI Configuration
4+
# ----------------
5+
common:ci --announce_rc
6+
test:ci --test_output=errors --test_summary=terse
7+
8+
# MacOS CI Configuration
9+
# ----------------------
10+
# The unit tests have a tendency to timeout when executed on the GH macos
11+
# runners. So, we reduce the number of parallel jobs and increase the timeout
12+
# for the tests.
13+
common:macos_ci --jobs=2
14+
common:macos_ci --test_timeout=600
15+
16+
# Remote Cache Authentication
17+
# ---------------------------
18+
try-import %workspace%/.bazelrc.auth
19+
20+
# User Configuration
21+
# ------------------
22+
try-import %workspace%/.bazelrc.local

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Set up GitHub runner
2+
3+
inputs:
4+
github_token:
5+
type: string
6+
7+
runs:
8+
using: composite
9+
steps:
10+
- uses: DeterminateSystems/nix-installer-action@v9
11+
with:
12+
github-token: ${{ inputs.github_token }}
13+
- uses: DeterminateSystems/magic-nix-cache-action@v2
14+
- name: Configure
15+
shell: bash
16+
run: |
17+
cat >>.bazelrc.local <<EOF
18+
common --config=ci
19+
EOF
20+
- name: Configure MacOS
21+
if: ${{ runner.os == 'macOS' }}
22+
shell: bash
23+
run: |
24+
cat >>.bazelrc.local <<EOF
25+
common --config=macos_ci
26+
EOF

.github/workflows/ci.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Continuous integration
2+
on:
3+
push:
4+
branches: main
5+
pull_request:
6+
branches: main
7+
workflow_dispatch: # allows manual triggering
8+
schedule:
9+
- cron: '1 11 * * *'
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
14+
15+
jobs:
16+
unit_tests:
17+
name: Unit Tests
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, macos-latest]
22+
runs-on: ${{ matrix.os }}
23+
steps:
24+
- name: Checkout the repository
25+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
26+
- uses: ./.github/actions/set_up_runner
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Execute Bazel tests
30+
shell: bash
31+
run: bazel test //...
32+
33+
integration_tests:
34+
name: Integration Tests
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os: [ubuntu-latest, macos-latest]
39+
runs-on: ${{ matrix.os }}
40+
steps:
41+
- name: Checkout the repository
42+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
43+
- uses: ./.github/actions/set_up_runner
44+
with:
45+
github_token: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Execute simple
47+
uses: ./
48+
with:
49+
verbose: true
50+
working-directory: ./tests/integration_tests
51+
options: |
52+
--arg customVarBool true
53+
--argstr customVarStr "Hello, World!"
54+
run: |
55+
echo "FIRST" > integration_test.out
56+
echo "${CUSTOM_VAR_BOOL}" >> integration_test.out
57+
echo "${CUSTOM_VAR_STR}" >> integration_test.out
58+
- name: Confirm output
59+
shell: bash
60+
run: |
61+
output="$(<./tests/integration_tests/integration_test.out)"
62+
expected="$(cat <<-EOF
63+
FIRST
64+
true
65+
Hello, World!
66+
EOF
67+
)"
68+
[[ "${output}" == "${expected}" ]] || \
69+
(echo >&2 "Ouptput from integration test does not match:" "${output}"; exit 1)
70+
71+
all_ci_tests:
72+
runs-on: ubuntu-latest
73+
needs:
74+
- unit_tests
75+
- integration_tests
76+
if: ${{ always() }}
77+
steps:
78+
- uses: cgrindel/gha_join_jobs@794a2d117251f22607f1aab937d3fd3eaaf9a2f5 # v1
79+
with:
80+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bazel-*
2+
3+
.direnv

BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# exports_files(["flake.lock"])
2+
3+
filegroup(
4+
name = "flake_files",
5+
srcs = [
6+
"flake.lock",
7+
"flake.nix",
8+
],
9+
visibility = ["//:__subpackages__"],
10+
)

MODULE.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module(
2+
name = "run_nix_shell",
3+
version = "0.0.0",
4+
)
5+
6+
bazel_dep(
7+
name = "rules_nixpkgs_core",
8+
version = "0.10.0",
9+
)
10+
11+
bazel_dep(
12+
name = "cgrindel_bazel_starlib",
13+
version = "0.18.1",
14+
dev_dependency = True,
15+
)

README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
1-
# run-nix-shell
2-
GitHub action for executing scripts via nix-shell.
1+
# Execute scripts using `nix-shell`
2+
3+
[![Continuous Integration](https://github.com/tweag/run-nix-shell/actions/workflows/ci.yaml/badge.svg?event=schedule)](https://github.com/tweag/run-nix-shell/actions/workflows/ci.yaml)
4+
5+
Executes a script or script file using `nix-shell`.
6+
7+
## Usage
8+
9+
To use this action, install Nix on your runner and start executing scripts.
10+
11+
```yaml
12+
name: Example
13+
on:
14+
workflow_dispatch: # allows manual triggering
15+
16+
jobs:
17+
run_under_nix:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout the repository
21+
uses: actions/checkout@v4
22+
- uses: DeterminateSystems/nix-installer-action@v9
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Execute script in Nix shell
27+
uses: tweag/run-nix-shell@v0
28+
with:
29+
run: |
30+
set -o errexit -o nounset -o pipefail
31+
echo "Hello"
32+
33+
- name: Execute script file
34+
uses: tweag/run-nix-shell@v0
35+
with:
36+
run: path/to/my/script
37+
38+
- name: Configure Nix shell before executing script
39+
uses: tweag/run-nix-shell@v0
40+
with:
41+
options: |
42+
--arg myNixArg true
43+
--argstr anotherNixArg "Hello, World!"
44+
run: |
45+
set -o errexit -o nounset -o pipefail
46+
echo "Hello"
47+
48+
- name: Execute script in a specific directory
49+
uses: tweag/run-nix-shell@v0
50+
with:
51+
working-directory: my/working/directory
52+
run: |
53+
set -o errexit -o nounset -o pipefail
54+
echo "${PWD}"
55+
```
56+
57+
## Inputs
58+
59+
| Input | Description |
60+
| ----- | ----------- |
61+
| `run` | The script to be executed using `nix-shell`. This can be the actual script or a path to as cript file. |
62+
| `options` | Any options that you want to pass to `nix-shell`. |
63+
| `working-directory` | This will be the current working direcotry when the script is executed. |
64+
| `verbose` | Enables additional output for debugging this action. |

WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Intentionally blank; using bzlmod

WORKSPACE.bzlmod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Intentionally blank
2+
# This file exists to force bzlmod into a strict mode.

0 commit comments

Comments
 (0)