|
4 | 4 | import gnupg
|
5 | 5 | import git
|
6 | 6 | import shutil
|
| 7 | +from key import detectPublicKey, importPrivateKey |
7 | 8 |
|
8 |
| -debug = os.environ.get('INPUT_DEBUG') |
| 9 | +debug = os.environ.get('INPUT_DEBUG', False) |
9 | 10 |
|
10 | 11 | if debug:
|
11 | 12 | logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
|
|
43 | 44 | logging.error('File version target is not listed in repo supported version list')
|
44 | 45 | sys.exit(1)
|
45 | 46 |
|
46 |
| - pub_key = os.environ.get('INPUT_PUBLIC_KEY') |
47 |
| - sign_key = os.environ.get('INPUT_PRIVATE_KEY') |
48 |
| - secret = os.environ.get('INPUT_KEY_SECRET') |
| 47 | + key_public = os.environ.get('INPUT_PUBLIC_KEY') |
| 48 | + key_private = os.environ.get('INPUT_PRIVATE_KEY') |
| 49 | + key_passphrase = os.environ.get('INPUT_KEY_PASSPHRASE') |
49 | 50 |
|
50 | 51 | logging.debug(github_token)
|
51 | 52 | logging.debug(arch_list)
|
52 | 53 | logging.debug(version_list)
|
53 | 54 |
|
54 | 55 | logging.info('-- Done parsing input --')
|
55 | 56 |
|
56 |
| - logging.info('-- Cloning current repo --') |
| 57 | + # Clone repo |
| 58 | + |
| 59 | + logging.info('-- Cloning current Github page --') |
57 | 60 |
|
58 | 61 | github_user = github_repo.split('/')[0]
|
59 | 62 | github_slug = github_repo.split('/')[1]
|
|
73 | 76 |
|
74 | 77 | logging.info('-- Done cloning current Github page --')
|
75 | 78 |
|
76 |
| - logging.info('-- Importing key --') |
77 |
| - |
78 |
| - logging.info('Detecting public key') |
| 79 | + # Prepare key |
79 | 80 |
|
80 |
| - logging.debug('Detecting existing public key') |
| 81 | + logging.info('-- Importing key --') |
81 | 82 |
|
82 | 83 | key_dir = os.path.join(github_slug, 'public.key')
|
83 |
| - key_exists = os.path.isfile(key_dir) |
84 |
| - |
85 |
| - logging.debug('Existing public key file exists? {}'.format(key_exists)) |
86 |
| - |
87 | 84 | gpg = gnupg.GPG()
|
88 | 85 |
|
89 |
| - if not key_exists: |
90 |
| - logging.info('Directory doesn\'t contain public.key trying to import') |
91 |
| - if pub_key is None: |
92 |
| - logging.error('Please specify public key for setup') |
93 |
| - sys.exit(1) |
94 |
| - |
95 |
| - logging.debug('Trying to import key') |
96 |
| - |
97 |
| - public_import_result = gpg.import_keys(pub_key) |
98 |
| - public_import_result.ok_reason |
99 |
| - |
100 |
| - logging.debug(public_import_result) |
101 |
| - |
102 |
| - if public_import_result.count != 1: |
103 |
| - logging.error('Invalid public key provided, please provide 1 valid key') |
104 |
| - sys.exit(1) |
105 |
| - |
106 |
| - with open(key_dir, 'w') as key_file: |
107 |
| - key_file.write(pub_key) |
108 |
| - |
109 |
| - logging.info('Public key valid') |
110 |
| - |
111 |
| - logging.info('Importing private key') |
112 |
| - |
113 |
| - private_import_result = gpg.import_keys(sign_key) |
114 |
| - |
115 |
| - if private_import_result.count != 1: |
116 |
| - logging.error('Invalid private key provided, please provide 1 valid key') |
117 |
| - sys.exit(1) |
118 |
| - |
119 |
| - logging.debug(private_import_result) |
120 |
| - |
121 |
| - if not any(data['ok'] >= '16' for data in private_import_result.results): |
122 |
| - logging.error('Key provided is not a secret key') |
123 |
| - sys.exit(1) |
124 |
| - |
125 |
| - private_key_id = private_import_result.results[0]['fingerprint'] |
126 |
| - |
127 |
| - logging.info('Private key valid') |
128 |
| - |
129 |
| - logging.debug('Key id: {}'.format(private_key_id)) |
| 86 | + detectPublicKey(gpg, key_dir, key_public) |
| 87 | + private_key_id = importPrivateKey(gpg, key_private) |
130 | 88 |
|
131 | 89 | logging.info('-- Done importing key --')
|
132 | 90 |
|
| 91 | + # Prepare repo |
| 92 | + |
133 | 93 | logging.info('-- Preparing repo directory --')
|
134 | 94 |
|
135 | 95 | apt_dir = os.path.join(github_slug, apt_folder)
|
136 |
| - |
137 | 96 | apt_conf_dir = os.path.join(apt_dir, 'conf')
|
138 | 97 |
|
139 | 98 | if not os.path.isdir(apt_folder):
|
140 |
| - logging.debug('Existing repo not detected, creating new repo') |
| 99 | + logging.info('Existing repo not detected, creating new repo') |
141 | 100 | os.mkdir(apt_dir)
|
142 | 101 | os.mkdir(apt_conf_dir)
|
143 | 102 |
|
|
154 | 113 |
|
155 | 114 | logging.info('-- Done preparing repo directory --')
|
156 | 115 |
|
| 116 | + # Fill repo |
| 117 | + |
157 | 118 | logging.info('-- Adding package to repo --')
|
158 | 119 |
|
159 | 120 | for deb, target in zip(deb_file_list, deb_file_version_list):
|
| 121 | + logging.info('Adding {}'.format(deb)) |
160 | 122 | os.system(
|
161 | 123 | 'reprepro -b {} --export=silent-never includedeb {} {}'.format(
|
162 | 124 | apt_dir,
|
|
165 | 127 | )
|
166 | 128 | )
|
167 | 129 |
|
168 |
| - gpg.sign('test', keyid=private_key_id, passphrase=secret) |
| 130 | + logging.debug('Signing to unlock key on gpg agent') |
| 131 | + gpg.sign('test', keyid=private_key_id, passphrase=key_passphrase) |
169 | 132 |
|
| 133 | + logging.debug('Export and sign repo') |
170 | 134 | os.system('reprepro -b {} export'.format(apt_dir))
|
171 | 135 |
|
172 | 136 | logging.info('-- Done adding package to repo --')
|
173 | 137 |
|
| 138 | + # Commiting and push changes |
| 139 | + |
174 | 140 | logging.info('-- Saving changes --')
|
175 | 141 |
|
176 | 142 | git_repo.config_writer().set_value(
|
|
0 commit comments