Skip to content

Commit

Permalink
feat: move pipeline to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimamisa committed Feb 20, 2024
1 parent d6163c4 commit 8eeeca5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 18 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: check
on:
workflow_dispatch:
push:
branches: ["main"]
tags-ignore: ["**"]
pull_request:

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: test with ${{ matrix.py }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py:
# - "3.8"
- "3.11"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- name: test shell
run: echo $UID
- name: test shell 1
run: alias
- name: test shell 2
run: ls -latr test/files/path1/templates/dockerfiles/backend/
- name: test shell 3
run: cp test/files/path1/templates/dockerfiles/backend/start.sh /tmp
- name: test shell 4
run: ls -latr /tmp
- name: Install self
run: python -m pip install tox tox-gh
- name: Setup test suite
run: tox -vv --notest
- name: Run test suite
run: tox --skip-pkg-install
6 changes: 3 additions & 3 deletions test/test_buildx_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_docker_multiple_contexts(self):
self.assertRegex(
stderr.decode("utf-8"),
r"docker buildx build --progress plain --builder testpkrbuilder --load "
r"--file /tmp/.*/file1.dockerfile --cache-from type=registry,ref=dummy/cache "
r"--cache-to type=registry,mode=max,ref=dummy/cache --tag container1:123 "
r"/tmp/.*/context1",
r"--file " + str(self.env_test.kard_folder) + "/.*/file1.dockerfile --cache-from "
r"type=registry,ref=dummy/cache --cache-to type=registry,mode=max,ref=dummy/cache "
r"--tag container1:123 " + str(self.env_test.kard_folder) + r"/.*/context1",
)
42 changes: 28 additions & 14 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def test_kard_create_with_meta(self):
dump = yaml.safe_load(prc.stdout)
self.assertEqual(dump.get("features", []), ["h", "g", "f", "e", "b", "a", "d", "c"])
self.assertEqual(dump.get("env_meta"), "dummy")
self.assertEqual(dump.get("src_path"), "/tmp")
self.assertEqual(
dump.get("src_path"), os.environ.get("RUNNER_TEMP", str(self.env_test.kard_folder))
)
self.assertEqual(dump.get("templated_meta"), "MTIz")
self.assertEqual(dump.get("templated_hash").get("key"), "dHV0dQ==")
self.assertEqual(dump.get("templated_list"), ["tutu", "dHV0dQ=="])
Expand Down Expand Up @@ -281,8 +283,8 @@ def test_image_push(self):

expected_cmd_output = b"Pushing backend:foo to testrepo.io/backend:foo\n"
expected_cmd_output_2 = re.compile(
b"ERROR: \(ImageNotFound\) 404 Client Error for http\+docker://.*: "
b'Not Found \("No such image: backend:foo"\)'
rb"ERROR: \(ImageNotFound\) 404 Client Error for http\+docker://.*: "
rb'Not Found \("No such image: backend:foo"\)'
)

error_outputs = stderr.split(b"\n")[:-1]
Expand All @@ -298,7 +300,6 @@ def test_explicit_kard_option(self):
cmd = "{} kard create test2 --do-not-set-current --extra tag=test2".format(self.PKR)
prc = self._run_cmd(cmd)
stdout = prc.stdout.read()
stderr = prc.stderr.read()
self.assertEqual(0, prc.returncode, stdout)

cmd = "{} kard list".format(self.PKR)
Expand Down Expand Up @@ -348,7 +349,9 @@ def test_encrypt_kard(self):
stderr = prc.stderr.read()
self.assertEqual(1, prc.returncode, msg_hlp(stdout, stderr))
expected = re.compile(
b"ERROR: \(FileNotFoundError\) \[Errno 2\] No such file or directory: '/tmp/.*/kard/test/docker-compose.yml'"
b"ERROR: \(FileNotFoundError\) \[Errno 2\] No such file or directory: '"
+ bytes(self.env_test.tmp_kard)
+ b"/kard/test/docker-compose.yml'"
)
assert re.match(expected, stderr.split(b"\n")[-2])

Expand Down Expand Up @@ -377,15 +380,15 @@ def test_encrypt_kard(self):
stderr = prc.stderr.read()
self.assertEqual(1, prc.returncode, msg_hlp(stdout, stderr))
expected = re.compile(
b"ERROR: \(FileNotFoundError\) \[Errno 2\] No such file or directory: '/tmp/.*/kard/test/docker-compose.enc'"
rb"ERROR: \(FileNotFoundError\) \[Errno 2\] No such file or directory: '"
+ bytes(self.env_test.tmp_kard)
+ rb"/kard/test/docker-compose.enc'"
)
assert re.match(expected, stderr.split(b"\n")[-2])

# succeed in some regular operations
cmd = "{} kard dump".format(self.PKR)
prc = self._run_cmd(cmd)
stdout = prc.stdout.read()
stderr = prc.stderr.read()
self.assertEqual(0, prc.returncode)

cmd = "{} kard list".format(self.PKR)
Expand Down Expand Up @@ -439,7 +442,7 @@ def test_docker_compose_present(self):
"services": {},
"paths": [
str(self.context_path.resolve() / "test"),
str("/tmp/test"),
str(self.env_test.kard_folder / "test"),
],
}

Expand Down Expand Up @@ -505,16 +508,24 @@ def test_start_script_present_with_proper_mod(self):

gen_file = self.context_path / "backend" / "start.sh"
expected_content = "#!/bin/bash\n\nsleep 1\n"
# We only check permissions for user, to be compatible with Travis CI environment
# We only check permissions for user, to be compatible with Travis CI environment
expected_user_mode = "5"
print(str(gen_file))
os.system("ls -altr " + str(gen_file.parent))

self.assertTrue(gen_file.exists())

content = gen_file.open("r").read()
self.assertEqual(expected_content, content)

mode = str(S_IMODE(gen_file.stat().st_mode))[:1]
self.assertEqual(expected_user_mode, mode)
print(gen_file.stat().st_mode)
print(S_IMODE(gen_file.stat().st_mode))

self.assertTrue(os.access(gen_file, os.R_OK))
self.assertTrue(os.access(gen_file, os.X_OK))

# mode = str(S_IMODE(gen_file.stat().st_mode))[:1]
# self.assertEqual(expected_user_mode, mode)

def test_exec_script_present_with_proper_mod(self):
self.generate_kard()
Expand All @@ -528,9 +539,12 @@ def test_exec_script_present_with_proper_mod(self):

content = gen_file.open("r").read()
self.assertEqual(expected_content, content)
#
# mode = str(S_IMODE(gen_file.stat().st_mode))[:1]
# self.assertEqual(expected_user_mode, mode)

mode = str(S_IMODE(gen_file.stat().st_mode))[:1]
self.assertEqual(expected_user_mode, mode)
self.assertTrue(os.access(gen_file, os.R_OK))
self.assertTrue(os.access(gen_file, os.X_OK))


class TestKardMakeWithExtensionDev(TestKardMake):
Expand Down
5 changes: 4 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class _EnvTest(object):

def __init__(self, path):
self.path = Path(__file__).parent / "files" / path
# GITHUB_WORKSPACE is a variable present in github.
# /tmp cannot be used there as it is mounted with the noexec flag
self.kard_folder = Path(os.environ.get("GITHUB_WORKSPACE", "/tmp"))
self.tmp_kard = None

def activate(self, override=None):
Expand All @@ -41,7 +44,7 @@ def enable(self):
Set PKR_PATH to created temporary directory and link
`env` and `templates` directories to new env.
"""
self.tmp_kard = Path(tempfile.mkdtemp())
self.tmp_kard = Path(tempfile.mkdtemp(dir=str(self.kard_folder)))
self.previous_path = os.environ.pop(PATH_ENV_VAR, None)
os.environ[PATH_ENV_VAR] = str(self.tmp_kard)
pkr.utils.ENV_FOLDER = pkr.environment.ENV_FOLDER = "env"
Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ whitelist_externals =
/usr/bin/bash
deps = -rrequirements-dev.txt
commands = pytest test --junit-xml pkr-test-report-{envname}.xml --junit-prefix {envname} {posargs}
;pass_env =
; GITHUB_WORKSPACE
;setenv =
; GITHUB_WORKSPACE = {env:RUNNER_TEMP}

[testenv:format]
deps = pylint==3.0.3
Expand All @@ -25,3 +29,8 @@ commands = black -t py38 -l 99 {toxinidir}

[travis:after]
travis = python: 3.8

[gh]
python =
3.8 = py38
3.11 = py311

0 comments on commit 8eeeca5

Please sign in to comment.