Skip to content

Commit 9513513

Browse files
committed
ci: replace docker-based tests with native nix-shell pytest action
1 parent db6d903 commit 9513513

6 files changed

Lines changed: 6 additions & 185 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,100 +10,17 @@ on:
1010
- main
1111

1212
jobs:
13-
build-docker-image:
14-
if: |
15-
github.event_name == 'push' || github.event_name == 'pull_request'
16-
runs-on: ubuntu-latest
17-
permissions:
18-
contents: read
19-
packages: write
20-
outputs:
21-
image_name: ${{ steps.build.outputs.image_name }}
22-
build_ran: "true"
23-
steps:
24-
- name: Check out repository
25-
uses: actions/checkout@v4
26-
with:
27-
fetch-depth: 0
28-
29-
- name: Check for file changes
30-
id: check_files
31-
run: |
32-
MODIFIED_FILES=$(git diff --name-only HEAD^ HEAD | \
33-
grep -E 'nix_test_env/Dockerfile')
34-
if [ -n "$MODIFIED_FILES" ]; then
35-
echo "build_ran=true" >> $GITHUB_OUTPUT
36-
else
37-
echo "build_ran=false" >> $GITHUB_OUTPUT
38-
fi
39-
40-
- name: Build docker image
41-
if: steps.check_files.outputs.build_ran == 'true'
42-
id: build
43-
run: |
44-
IMAGE_NAME="nix-test-env:$(git rev-parse --short HEAD)"
45-
docker build -t ${IMAGE_NAME} -f ./nix_test_env/Dockerfile .
46-
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
47-
48-
- name: Log in and push Docker image to GHCR
49-
if: steps.check_files.outputs.build_ran == 'true'
50-
run: |
51-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u \
52-
${{ github.actor }} --password-stdin
53-
IMAGE_ID="ghcr.io/${{ github.repository }}/nix-test-env"
54-
COMMIT_TAG="${IMAGE_ID}:$(git rev-parse --short HEAD)"
55-
docker tag ${{ steps.build.outputs.image_name }} $COMMIT_TAG
56-
LATEST_TAG="${IMAGE_ID}:latest"
57-
docker tag ${{ steps.build.outputs.image_name }} $LATEST_TAG
58-
docker push $COMMIT_TAG
59-
docker push $LATEST_TAG
60-
6113
tests:
6214
runs-on: ubuntu-latest
63-
if: |
64-
(github.event_name == 'push' || github.event_name == 'pull_request') &&
65-
(needs.build-docker-image.outputs.build_ran == 'true' ||
66-
needs.build-docker-image.outputs.build_ran == '')
6715
steps:
6816
- name: Check out repository
6917
uses: actions/checkout@v4
7018

71-
- name: Pull image with fallback in GHCR
72-
id: docker_pull
73-
run: |
74-
IMAGE_ID="ghcr.io/${{ github.repository }}/nix-test-env"
75-
COMMIT_TAG="${IMAGE_ID}:$(git rev-parse --short HEAD)"
76-
LATEST_TAG="${IMAGE_ID}:latest"
77-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u \
78-
${{ github.actor }} --password-stdin
79-
if docker pull $COMMIT_TAG; then
80-
echo "Successfully pulled commit-specific image: $COMMIT_TAG"
81-
echo "image_to_test=$COMMIT_TAG" >> $GITHUB_OUTPUT
82-
else
83-
echo "Commit-specific image not found. Falling back to latest."
84-
docker pull $LATEST_TAG
85-
echo "image_to_test=$LATEST_TAG" >> $GITHUB_OUTPUT
86-
fi
87-
88-
- name: Run container
89-
id: container
90-
run: |
91-
CONTAINER_NAME="nix-test-container"
92-
IMAGE_TO_TEST="${{ steps.docker_pull.outputs.image_to_test }}"
93-
echo "Running tests on image: $IMAGE_TO_TEST"
94-
docker run --name $CONTAINER_NAME \
95-
-v ./nix_tests:/app/tests -d \
96-
$IMAGE_TO_TEST tail -f /dev/null
97-
echo "container_name=$CONTAINER_NAME" >> $GITHUB_OUTPUT
19+
- name: Install Nix
20+
uses: cachix/install-nix-action@v27
21+
with:
22+
nix_path: nixpkgs=channel:nixos-unstable
9823

99-
- name: Run all tests in container
24+
- name: Run Tests (Pytest)
10025
run: |
101-
docker exec ${{ steps.container.outputs.container_name }} bash -c \
102-
". /root/.nix-profile/etc/profile.d/nix.sh;
103-
home-manager switch;
104-
. /root/.nix-profile/etc/profile.d/hm-session-vars.sh;
105-
/root/.config/home-manager/nix_tests/run_all.sh"
106-
107-
- name: Clean up container
108-
if: always()
109-
run: docker rm -f ${{ steps.container.outputs.container_name }}
26+
nix-shell -p python3Packages.pytest --run "pytest tests/"

tests/env/nix_test_env/Dockerfile

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/env/nix_test_env/docker-compose.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/env/test_editor.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/env/test_load_nix_env.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/programs/test_zoxide.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ def test_zoxide_config(home_manager_build):
55
bashrc = home_manager_build / "home-files/.bashrc"
66
content = bashrc.read_text()
77
assert "zoxide init bash" in content
8-
# zoxide manages the 'cd' alias internally or via the module, check if 'z' alias is common
9-
assert "cd=z" in content

0 commit comments

Comments
 (0)