-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ecmwf/develop
Adding tests and GitHub actions
- Loading branch information
Showing
12 changed files
with
508 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: ci-tracksuite | ||
|
||
# Controls when the workflow will run | ||
on: | ||
push: | ||
branches: [ "master", "develop" ] | ||
pull_request: | ||
branches: [ "master", "develop" ] | ||
|
||
jobs: | ||
qa: | ||
name: qa | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v4 | ||
- run: pip install black flake8 isort | ||
- run: isort --check . | ||
- run: black --check . | ||
- run: flake8 . | ||
|
||
setup: | ||
name: setup | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: python -m pip install . | ||
|
||
test: | ||
name: pytest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: git config --global user.email "[email protected]" | ||
- run: git config --global user.name "Dummy User" | ||
- run: python -m pip install .[test] | ||
- run: python -m pytest . -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: on-push | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
|
||
jobs: | ||
setup: | ||
name: setup | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: python -m pip install . | ||
|
||
test: | ||
name: pytest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: git config --global user.email "[email protected]" | ||
- run: git config --global user.name "Dummy User" | ||
- run: python -m pip install .[test] | ||
- run: python -m pytest . -v | ||
|
||
distribution: | ||
runs-on: ubuntu-latest | ||
needs: [setup, test] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build distributions | ||
run: | | ||
$CONDA/bin/python -m pip install build | ||
$CONDA/bin/python -m build | ||
- name: Publish a Python distribution to PyPI | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
[build-system] | ||
# NOTE: `pip install build` to build with `python -m build` | ||
requires = [ | ||
"setuptools >= 40.9.0", | ||
"wheel" | ||
] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pytest.ini_options] | ||
addopts = "" | ||
doctest_optionflags = "" | ||
testpaths = "tests" | ||
markers = [] | ||
[project] | ||
name = "tracksuite" | ||
version = "0.3.1" | ||
description = "ecflow suite tracking and deploying toolkit" | ||
authors = [ | ||
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "[email protected]" }, | ||
{ name = "Corentin Carton de Wiart", email = "[email protected]" }, | ||
] | ||
license = { text = "Apache License Version 2.0" } | ||
requires-python = ">=3.8" | ||
readme = "README.md" | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: Unix", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Scientific/Engineering", | ||
] | ||
|
||
dependencies = [ | ||
"gitpython >= 3.1.25" | ||
] | ||
|
||
[project.optional-dependencies] | ||
test = ["pytest", "mocker", "pytest-mock"] | ||
|
||
[project.urls] | ||
"Source code" = "https://github.com/ecmwf/tracksuite" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["."] | ||
exclude = ["tests"] | ||
|
||
[project.scripts] | ||
tracksuite-init = "tracksuite.init:main" | ||
tracksuite-deploy = "tracksuite.deploy:main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
gitpython >= 3.1.25 | ||
paramiko |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import os | ||
import tempfile | ||
|
||
import git | ||
import pytest | ||
|
||
from tracksuite.deploy import GitDeployment | ||
from tracksuite.init import setup_remote | ||
|
||
|
||
@pytest.fixture | ||
def git_deployment(): | ||
|
||
temp_dir = tempfile.TemporaryDirectory().name | ||
staging_dir = os.path.join(temp_dir, "staging") | ||
target_repo = os.path.join(temp_dir, "target") | ||
current_user = os.getenv("USER") | ||
setup_remote( | ||
host="localhost", | ||
user=current_user, | ||
target_dir=target_repo, | ||
) | ||
|
||
deployer = GitDeployment( | ||
host="localhost", | ||
user=current_user, | ||
staging_dir=staging_dir, | ||
target_repo=target_repo, | ||
) | ||
|
||
return deployer | ||
|
||
|
||
@pytest.fixture | ||
def git_deployment_with_backup(): | ||
|
||
temp_dir = tempfile.TemporaryDirectory().name | ||
staging_dir = os.path.join(temp_dir, "staging") | ||
target_repo = os.path.join(temp_dir, "target") | ||
backup_path = os.path.join(temp_dir, "backup.git") | ||
git.Repo.init(backup_path, bare=True) | ||
current_user = os.getenv("USER") | ||
setup_remote( | ||
host="localhost", | ||
user=current_user, | ||
target_dir=target_repo, | ||
remote=backup_path, | ||
) | ||
|
||
deployer = GitDeployment( | ||
host="localhost", | ||
user=current_user, | ||
staging_dir=staging_dir, | ||
target_repo=target_repo, | ||
backup_repo=backup_path, | ||
) | ||
|
||
return deployer | ||
|
||
|
||
def test_git_deployment_constructor(git_deployment): | ||
|
||
assert git_deployment.host == "localhost" | ||
assert git_deployment.user == os.getenv("USER") | ||
print(git_deployment.target_dir) | ||
assert os.path.exists(git_deployment.target_dir) | ||
|
||
|
||
def test_git_deployment_constructor_with_backup(git_deployment_with_backup): | ||
|
||
assert git_deployment_with_backup.host == "localhost" | ||
assert git_deployment_with_backup.user == os.getenv("USER") | ||
print(git_deployment_with_backup.target_dir) | ||
assert os.path.exists(git_deployment_with_backup.target_dir) | ||
assert os.path.exists(git_deployment_with_backup.backup_repo) | ||
|
||
|
||
def test_deploy_default(git_deployment): | ||
|
||
deployer = git_deployment | ||
staging_dir = deployer.staging_dir | ||
|
||
os.mkdir(staging_dir) | ||
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f: | ||
f.write("dummy content") | ||
|
||
deployer.pull_remotes() | ||
deployer.diff_staging() | ||
deployer.deploy() | ||
|
||
with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f: | ||
assert f.read() == "dummy content" | ||
|
||
repo = git.Repo(deployer.target_dir) | ||
commit_history = repo.iter_commits() | ||
all_commits = [commit for commit in commit_history] | ||
assert f"deployed by {deployer.user}" in all_commits[0].message | ||
|
||
|
||
def test_deploy_message(git_deployment): | ||
|
||
deployer = git_deployment | ||
staging_dir = deployer.staging_dir | ||
|
||
os.mkdir(staging_dir) | ||
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f: | ||
f.write("dummy content") | ||
|
||
deployer.pull_remotes() | ||
deployer.diff_staging() | ||
deployer.deploy("This is my change") | ||
|
||
with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f: | ||
assert f.read() == "dummy content" | ||
|
||
repo = git.Repo(deployer.target_dir) | ||
commit_history = repo.iter_commits() | ||
all_commits = [commit for commit in commit_history] | ||
assert "This is my change" in all_commits[0].message | ||
|
||
|
||
def test_deploy_with_backup(git_deployment_with_backup): | ||
|
||
deployer = git_deployment_with_backup | ||
staging_dir = deployer.staging_dir | ||
|
||
os.mkdir(staging_dir) | ||
with open(os.path.join(staging_dir, "dummy.txt"), "w") as f: | ||
f.write("dummy content") | ||
|
||
deployer.pull_remotes() | ||
deployer.diff_staging() | ||
deployer.deploy("This is my change") | ||
|
||
with open(os.path.join(deployer.target_dir, "dummy.txt"), "r") as f: | ||
assert f.read() == "dummy content" | ||
|
||
repo = git.Repo(deployer.target_repo) | ||
commit_history = repo.iter_commits() | ||
all_commits = [commit for commit in commit_history] | ||
assert "This is my change" in all_commits[0].message | ||
|
||
|
||
def test_deploy_files(git_deployment): | ||
|
||
deployer = git_deployment | ||
staging_dir = deployer.staging_dir | ||
|
||
os.mkdir(staging_dir) | ||
for file in ["file1.txt", "file2.txt", "file3.txt"]: | ||
with open(os.path.join(deployer.staging_dir, file), "w") as f: | ||
f.write("dummy content") | ||
|
||
deployer.pull_remotes() | ||
deployer.diff_staging() | ||
deployer.deploy(files=["file1.txt", "file2.txt"]) | ||
|
||
assert os.path.exists(os.path.join(deployer.target_dir, "file1.txt")) | ||
assert os.path.exists(os.path.join(deployer.target_dir, "file2.txt")) | ||
assert not os.path.exists(os.path.join(deployer.target_dir, "file3.txt")) |
Oops, something went wrong.