-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbranch-info
executable file
·35 lines (30 loc) · 991 Bytes
/
branch-info
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
#!/usr/bin/env python3
# Copyright (C) 2021 Leandro Lisboa Penz <lpenz@lpenz.org>
# This file is subject to the terms and conditions defined in
# file 'LICENSE', which is part of this source code package.
import os
import re
import sys
def main():
ref = os.environ.get("GITHUB_REF")
info = {"isdistro": "false", "ref": ref}
m = re.match(
"^refs/heads/"
"(?P<image>"
"(?P<mirror>[^-]+)-(?P<dist>[^-]+)-(?P<arch>[^-]+)"
"(-(?P<variant>[^-]+))?)",
ref,
)
if ref and m:
info["isdistro"] = "true"
for k in ("image", "mirror", "dist", "arch", "variant"):
info[k] = m.group(k)
for k, v in info.items():
sys.stdout.write("{}={}\n".format(k, v))
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output:
with open(github_output, mode="a") as fd:
for k, v in info.items():
fd.write("{}={}\n".format(k, v))
if __name__ == "__main__":
main()