-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_workflow.py
executable file
·95 lines (77 loc) · 2.34 KB
/
update_workflow.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python3
#
# update_workflow.py
#
# Modifies github actions workflows to use self-hosted runners.
#
# python3 update_workflow.py __path_to_ci_file__
#
quote_os=True
import sys
import re
import shutil
targetfile=sys.argv[1]
shutil.copyfile(targetfile, targetfile + '.orig')
with open(targetfile, 'r') as file:
data = file.read()
# Add single quotes around operating system names if they are missing. 'ubuntu-latest'
if quote_os:
data=re.sub(
pattern=r'([^"\'])(\S*)-latest([^"\'])',
repl='\\1\'\\2-latest\'\\3',
string=data
)
data=re.sub(
pattern=r'([^"\'])ubuntu-(\d\d)\.(\d\d)([^"\'])',
repl='\\1\'ubuntu-\\2.\\3\'\\4',
string=data
)
data=re.sub(
pattern=r'([^"\'])windows-(\d{4})([^"\'])',
repl='\\1\'windows-\\2\'\\3',
string=data
)
data=re.sub(
pattern=r'([^"\'])macos-(\d{2})([^"\'])',
repl='\\1\'macos-\\2\'\\3',
string=data
)
data=re.sub(
pattern=r'([^\S\r\n]*)runs-on: \${{\s*matrix.os\s*}}',
repl='\\1needs: [runner-selection]\n\\1runs-on: ${{ fromJSON(needs.runner-selection.outputs.labelmatrix)[matrix.os] }}',
string=data
)
data=re.sub(
pattern=r"([^\S\r\n]*)runs-on:(\s*)('ubuntu.*').*",
repl='\\1needs: [runner-selection]\n\\1runs-on: ${{ fromJSON(needs.runner-selection.outputs.labelmatrix)[\\3] }}',
string=data
)
data=re.sub(
pattern=r"([^\S\r\n]*)runs-on:(\s*)('windows.*').*",
repl='\\1needs: [runner-selection]\n\\1runs-on: ${{ fromJSON(needs.runner-selection.outputs.labelmatrix)[\\3] }}',
string=data
)
data=re.sub(
pattern=r"([^\S\r\n]*)runs-on:(\s*)('mac.*').*",
repl='\\1needs: [runner-selection]\n\\1runs-on: ${{ fromJSON(needs.runner-selection.outputs.labelmatrix)[\\3] }}',
string=data
)
job_to_include="""
runner-selection:
# runs-on: ubuntu-latest
runs-on: ${{ github.repository_owner == 'boostorg' && fromJSON('[ "self-hosted", "linux", "x64", "ubuntu-latest-aws" ]') || 'ubuntu-latest' }}
outputs:
labelmatrix: ${{ steps.aws_hosted_runners.outputs.labelmatrix }}
steps:
- name: AWS Hosted Runners
id: aws_hosted_runners
uses: cppalliance/[email protected]
"""
data=re.sub(
pattern=r'(jobs:)',
repl='\\1' + job_to_include,
string=data
)
f = open(targetfile, "w")
f.write(data)
f.close()