Skip to content

Commit 146f0c4

Browse files
author
saville
committed
Remove deploy key usage and instead use temporary SSH key
1 parent 1b4c6f9 commit 146f0c4

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ jobs:
3535
- name: Pre-commit checks
3636
run: pre-commit run --all-files
3737
- name: Test with pytest
38+
# Create the ssh key file once for all testing
3839
run: |
40+
ssh-keygen -t ecdsa -m PEM -N '' -f /tmp/buildrunner-test-id_rsa
3941
pytest -v -m "not serial" --numprocesses=auto --junitxml=test-reports/non-serial-test-results.xml
4042
pytest -v -m "serial" --junitxml=test-reports/serial-test-results.xml
4143
python scripts/combine_xml.py test-reports/serial-test-results.xml test-reports/non-serial-test-results.xml > test-reports/test-result.xml

tests/test_buildrunner_files.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,32 @@
2626
@pytest.fixture(autouse=True, scope="session")
2727
def setup_buildrunner_test_ssh_key():
2828
key_file_path = Path(TEST_SSH_KEY_FILE)
29-
key_file_path.unlink(missing_ok=True)
30-
subprocess.run(
31-
[
32-
"ssh-keygen",
33-
"-t",
34-
"ecdsa",
35-
"-m",
36-
"PEM",
37-
"-N",
38-
"",
39-
"-f",
40-
TEST_SSH_KEY_FILE,
41-
],
42-
check=True,
43-
)
29+
cleanup_key_file = False
30+
pub_key_file_path = Path(f"{TEST_SSH_KEY_FILE}.pub")
31+
if not key_file_path.exists():
32+
subprocess.run(
33+
[
34+
"ssh-keygen",
35+
"-t",
36+
"ecdsa",
37+
"-m",
38+
"PEM",
39+
"-N",
40+
"",
41+
"-f",
42+
TEST_SSH_KEY_FILE,
43+
],
44+
check=True,
45+
)
46+
cleanup_key_file = True
4447
# Set the public key in an environment variable to use in the test buildrunner files
45-
os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"] = (
46-
Path(f"{TEST_SSH_KEY_FILE}.pub").read_text().strip()
47-
)
48+
os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"] = pub_key_file_path.read_text().strip()
4849
yield
4950
# Cleanup
5051
del os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"]
51-
key_file_path.unlink()
52+
if cleanup_key_file:
53+
key_file_path.unlink()
54+
pub_key_file_path.unlink()
5255

5356

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

0 commit comments

Comments
 (0)