Skip to content

Commit

Permalink
Merge pull request #23 from niklasstoffers/test-pipeline
Browse files Browse the repository at this point in the history
Add tests and test pipeline
  • Loading branch information
mergify[bot] authored Dec 26, 2023
2 parents 958e19f + 5e032fc commit f69a725
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__pycache__
**/*.log
**/.pytest_cache
autoapprove/config.yaml
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: BUILD

on: [push, pull_request]
on: [push]

jobs:
build:
Expand All @@ -15,7 +15,7 @@ jobs:
with:
context: .
file: ./Dockerfile
labels: gitlab-auto-approve
tags: gitlab-auto-approve:latest
outputs: type=docker,dest=/tmp/image.tar
- name: Save artifacts
id: save-artifacts
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: TEST

on: [push]

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Wait for build
uses: lewagon/wait-on-check-action@v1.3.1
with:
ref: ${{ github.ref }}
check-name: 'build'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 5
- name: Download build artifacts
uses: dawidd6/action-download-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: build.yml
workflow_conclusion: success
name: ${{ github.head_ref }}.${{ github.sha }}
path: /tmp/
if_no_artifact_found: fail
- name: Run tests
run: |
docker load --input /tmp/image.tar
./ci_run_tests.sh
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ rebuild-dev: ## Build dev application without cache
run-dev: ## Run dev application
@docker-compose --env-file $(ENV_FILE) up gitlab-auto-approve-dev

test: ## Run tests
@docker-compose --env-file $(ENV_FILE) run --entrypoint "pytest /tests" gitlab-auto-approve-dev

publish: ## Publish application
@./publish.sh
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<a href="https://github.com/niklasstoffers/gitlab-auto-approve/blob/main/LICENSE"><img src="https://img.shields.io/github/license/niklasstoffers/gitlab-auto-approve?color=informational" alt="license"></a>
<a href="https://hub.docker.com/repository/docker/niklasstoffers/gitlab-auto-approve/general"><img src="https://img.shields.io/docker/v/niklasstoffers/gitlab-auto-approve" alt="version"></a>
<img src="https://img.shields.io/github/actions/workflow/status/niklasstoffers/gitlab-auto-approve/build.yml" alt="build status">
<img src="https://img.shields.io/github/actions/workflow/status/niklasstoffers/gitlab-auto-approve/test.yml" alt="test status">
<a href="https://github.com/niklasstoffers/gitlab-auto-approve/issues"><img src="https://img.shields.io/github/issues/niklasstoffers/gitlab-auto-approve" alt="open issues" /></a>
<br>
<img src="https://img.shields.io/github/languages/top/niklasstoffers/gitlab-auto-approve?color=blueviolet" alt="top language">
Expand Down
3 changes: 3 additions & 0 deletions ci_run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker run --entrypoint /bin/sh -v "./tests:/tests" gitlab-auto-approve -c \
"pip install -r /tests/requirements.txt && \
pytest /tests"
2 changes: 2 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ FROM python:3.12
WORKDIR /autoapprove
COPY ./autoapprove/requirements.txt /app/requirements.txt
COPY ./default_config.yaml /config/config.yaml
COPY ./tests/requirements.txt /tests/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
RUN pip install --no-cache-dir -r /tests/requirements.txt
ENTRYPOINT ["python", "main.py", "--startup-log-level", "DEBUG", "-c", "/config/config.yaml"]
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
dockerfile: dev.Dockerfile
volumes:
- ./autoapprove:/autoapprove
- ./tests:/tests
ports:
- '${APP_PORT}:8000'
environment:
Expand Down
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==7.4.3
4 changes: 4 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from autoapprove.helpers.type import is_optional

def test():
assert is_optional(str | None)

0 comments on commit f69a725

Please sign in to comment.