Skip to content

Commit

Permalink
Remove deploy key usage and instead use temporary SSH key
Browse files Browse the repository at this point in the history
  • Loading branch information
saville committed Oct 17, 2024
1 parent 1b4c6f9 commit 146f0c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ jobs:
- name: Pre-commit checks
run: pre-commit run --all-files
- name: Test with pytest
# Create the ssh key file once for all testing
run: |
ssh-keygen -t ecdsa -m PEM -N '' -f /tmp/buildrunner-test-id_rsa
pytest -v -m "not serial" --numprocesses=auto --junitxml=test-reports/non-serial-test-results.xml
pytest -v -m "serial" --junitxml=test-reports/serial-test-results.xml
python scripts/combine_xml.py test-reports/serial-test-results.xml test-reports/non-serial-test-results.xml > test-reports/test-result.xml
Expand Down
41 changes: 22 additions & 19 deletions tests/test_buildrunner_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,32 @@
@pytest.fixture(autouse=True, scope="session")
def setup_buildrunner_test_ssh_key():
key_file_path = Path(TEST_SSH_KEY_FILE)
key_file_path.unlink(missing_ok=True)
subprocess.run(
[
"ssh-keygen",
"-t",
"ecdsa",
"-m",
"PEM",
"-N",
"",
"-f",
TEST_SSH_KEY_FILE,
],
check=True,
)
cleanup_key_file = False
pub_key_file_path = Path(f"{TEST_SSH_KEY_FILE}.pub")
if not key_file_path.exists():
subprocess.run(
[
"ssh-keygen",
"-t",
"ecdsa",
"-m",
"PEM",
"-N",
"",
"-f",
TEST_SSH_KEY_FILE,
],
check=True,
)
cleanup_key_file = True
# Set the public key in an environment variable to use in the test buildrunner files
os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"] = (
Path(f"{TEST_SSH_KEY_FILE}.pub").read_text().strip()
)
os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"] = pub_key_file_path.read_text().strip()
yield
# Cleanup
del os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"]
key_file_path.unlink()
if cleanup_key_file:
key_file_path.unlink()
pub_key_file_path.unlink()


def _get_test_args(file_name: str) -> Optional[List[str]]:
Expand Down

0 comments on commit 146f0c4

Please sign in to comment.