-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-workflow.py
executable file
·126 lines (112 loc) · 3.75 KB
/
generate-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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
from pathlib import Path
from typing import Any
import yaml
RUNNER_OS = 'ubuntu-24.04'
def main() -> None:
packages = [p.parent.name for p in sorted(Path.cwd().glob('*/PKGBUILD'))]
workflow = generate_workflow(packages)
text = yaml.safe_dump(workflow, indent=2, sort_keys=False)
Path.cwd().joinpath('.github/workflows/ci.yaml').write_text(text)
def generate_workflow(packages: list[str]) -> dict[str, Any]:
return {
'name': 'CI',
'permissions': {
'contents': 'write',
'packages': 'write',
},
'on': {
'push': {
'branches': [
'main',
],
},
'schedule': [
{'cron': '0 3 * * *'},
],
},
'jobs': {'build-container': generate_setup_job(), 'deploy-repo': generate_deploy_job(packages)} | {f'package-{package}': generate_package_job(package) for package in packages},
}
def generate_package_job(package: str) -> dict[str, Any]:
return {
'runs-on': RUNNER_OS,
'needs': ['build-container'],
'steps': [
{
'name': 'Checkout',
'uses': 'actions/checkout@v4',
},
{
'name': 'Build package',
'run': f'./build-package.sh {package}',
},
{
'name': 'Upload package',
'uses': 'actions/upload-artifact@v4',
'with': {
'name': f'package-{package}',
'path': f'./{package}/*.pkg.tar.zst',
'retention-days': 1,
'if-no-files-found': 'error',
}
}
],
}
def generate_setup_job() -> dict[str, Any]:
return {
'runs-on': RUNNER_OS,
'steps': [
{
'name': 'Checkout',
'uses': 'actions/checkout@v4',
},
{
'name': 'Build and push container',
'run': './build-container.sh',
'env': {
'GITHUB_USER': 'dadevel',
'GITHUB_TOKEN': '${{ secrets.GITHUB_TOKEN }}'
},
},
],
}
def generate_deploy_job(packages: list[str]) -> dict[str, Any]:
return {
'runs-on': RUNNER_OS,
'needs': [f'package-{name}' for name in packages],
'if': '${{ always() }}',
'concurrency': 'ci-${{ github.ref }}',
'steps': [
{
'name': 'Checkout',
'uses': 'actions/checkout@v4',
},
{
'name': 'Download artifacts',
'uses': 'actions/download-artifact@v4',
'with': {
'path': './artifacts',
}
},
{
'name': 'Create repository',
'run': './build-repo.sh',
'env': {
'SIGNING_KEY': '${{ secrets.SIGNING_KEY }}',
},
},
{
'name': 'Upload repository',
'run': 'sudo apt-get install --no-install-recommends -y rclone && rclone --copy-links sync ./public hetzner:',
'env': {
'RCLONE_CONFIG_HETZNER_TYPE': 'ftp',
'RCLONE_CONFIG_HETZNER_HOST': '${{ secrets.HETZNER_HOSTNAME }}',
'RCLONE_CONFIG_HETZNER_USER': '${{ secrets.HETZNER_USERNAME }}',
'RCLONE_CONFIG_HETZNER_PASS': '${{ secrets.HETZNER_PASSWORD }}', # echo password | rclone obscure
'RCLONE_CONFIG_HETZNER_EXPLICIT_TLS': 'true',
},
},
],
}
if __name__ == '__main__':
main()