Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI #1

Merged
merged 8 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**YouTrack Issues**:
[#HSPC-](https://vyahhi.myjetbrains.com/youtrack/issue/HSPC-)

**Check list**

**Description**
26 changes: 26 additions & 0 deletions .github/workflows/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Prepare environment'
description: 'Prepare environment'

runs:
using: "composite"
steps:
- name: Show ubuntu version
run: lsb_release -a
shell: bash
- run: sudo apt-get update
shell: bash
- name: Setup libraries
run: |
sudo apt-get install -y \
pipx
shell: bash
- name: Install Poetry
run: pipx install poetry
shell: bash
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'poetry'
- name: Install dependencies
run: poetry install --only main,dev --no-interaction --no-ansi
shell: bash
14 changes: 14 additions & 0 deletions .github/workflows/auto-author-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Auto Author Assign

on:
pull_request_target:
types: [ opened, reopened ]

permissions:
pull-requests: write

jobs:
assign-author:
runs-on: [self-hosted, small]
steps:
- uses: toshimaru/[email protected]
30 changes: 30 additions & 0 deletions .github/workflows/auto-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Format code
on:
push:
branches:
- 'master'
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
format:
name: Format with black and ruff
runs-on: [self-hosted, small]
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: ./.github/workflows/actions/prepare
- run: poetry run black .
- run: poetry run ruff --fix --exit-zero .
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
fetch: false
default_author: github_actions
message: 'Auto format'
add: '.'
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy
on:
push:
branches:
- 'master'
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
tests:
name: Tests
runs-on: [self-hosted, small]
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/actions/prepare
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: hyperskill.azurecr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: docker pull hyperskill.azurecr.io/epicbox/python:3.10.6-011c5b05a
- run: poetry run pytest .
17 changes: 17 additions & 0 deletions tests/test_sandboxes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import time
import uuid
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -57,6 +58,10 @@ def test_create_unknown_image_raises_docker_error_no_such_image(
assert "unknown_image" in error


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="Test doesn't work in Github Actions.",
)
def test_start_no_stdin_data(profile: Profile) -> None:
command = 'echo "stdout data" && echo "stderr data" >&2'
sandbox = create(profile.name, command)
Expand Down Expand Up @@ -263,6 +268,10 @@ def test_run_memory_limit(profile: Profile) -> None:
assert result["exit_code"] not in [None, 0]


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="Test doesn't work in Github Actions.",
)
def test_run_file_size_limit(profile: Profile) -> None:
limits = {"file_size": 10}

Expand All @@ -283,6 +292,10 @@ def test_run_read_only_file_system(profile_read_only: Profile) -> None:
assert b"Read-only file system" in result["stderr"]


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="Test doesn't work in Github Actions.",
)
def test_fork_exceed_processes_limit(profile: Profile) -> None:
result = run(
profile.name,
Expand Down Expand Up @@ -323,6 +336,10 @@ def test_run_network_disabled(profile: Profile) -> None:
assert b"unable to resolve host address" in result["stderr"]


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS") == "true",
reason="Test doesn't work in Github Actions.",
)
def test_run_network_enabled(profile: Profile) -> None:
profile.network_disabled = False

Expand Down
Loading