]> git.proxmox.com Git - cargo.git/blob - publish.py
drop patches applied upstream or in debcargo-conf
[cargo.git] / publish.py
1 #!/usr/bin/env python3
2
3 # This script is used to publish Cargo to crates.io.
4
5 import os
6 import re
7 import subprocess
8 import urllib.request
9 from urllib.error import HTTPError
10
11
12 TO_PUBLISH = [
13 'crates/cargo-platform',
14 'crates/crates-io',
15 '.',
16 ]
17
18
19 def already_published(name, version):
20 try:
21 urllib.request.urlopen('https://crates.io/api/v1/crates/%s/%s/download' % (name, version))
22 except HTTPError as e:
23 if e.code == 404:
24 return False
25 raise
26 return True
27
28
29 def maybe_publish(path):
30 content = open(os.path.join(path, 'Cargo.toml')).read()
31 name = re.search('^name = "([^"]+)"', content, re.M).group(1)
32 version = re.search('^version = "([^"]+)"', content, re.M).group(1)
33 if already_published(name, version):
34 print('%s %s is already published, skipping' % (name, version))
35 return
36 subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
37
38
39 def main():
40 print('Doing dry run first...')
41 for path in TO_PUBLISH:
42 subprocess.check_call(['cargo', 'publish', '--no-verify', '--dry-run'], cwd=path)
43 print('Starting publish...')
44 for path in TO_PUBLISH:
45 maybe_publish(path)
46 print('Publish complete!')
47
48
49 if __name__ == '__main__':
50 main()