-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.py
More file actions
48 lines (44 loc) · 1.28 KB
/
action.py
File metadata and controls
48 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""
Basic script that translates inputs from github and convert them to work
with the mender artifact creation tool.
"""
from pathlib import Path
import subprocess
import argparse
import tempfile
import sys
import os
# Intercept the signing-key and convert
parser = argparse.ArgumentParser()
parser.add_argument("--signing-key", required=True)
parser.add_argument("--variables", nargs="?", const=None)
parsed_args, passthrough_args = parser.parse_known_args()
# Private key file
private_key = tempfile.NamedTemporaryFile(mode="w", delete=False)
private_key.write(parsed_args.signing_key)
private_key.close()
# Extract env variables from argument
variables = []
for env in parsed_args.variables.split(" "):
variables.append("--env")
variables.append(env)
try:
subprocess.run(
[
os.environ["GITHUB_ACTION_PATH"] + "/docker-compose-artifact-gen",
*passthrough_args, "--signing-key", private_key.name,
*variables,
],
check=True
)
except subprocess.CalledProcessError as err:
if err.output:
print(err.output, file=sys.stdout)
if err.stderr:
print(err.stderr, file=sys.stderr)
sys.exit(err.returncode)
else:
sys.exit(0)
finally:
Path(private_key.name).unlink(missing_ok=True)