]> git.proxmox.com Git - cargo.git/blob - publish.py
bump version to 0.66.0+pve1-1~bpo11+pve1
[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 time
9 import urllib.request
10 from urllib.error import HTTPError
11
12
13 TO_PUBLISH = [
14 'crates/cargo-platform',
15 'crates/cargo-util',
16 'crates/crates-io',
17 '.',
18 ]
19
20
21 def already_published(name, version):
22 try:
23 urllib.request.urlopen('https://crates.io/api/v1/crates/%s/%s/download' % (name, version))
24 except HTTPError as e:
25 if e.code == 404:
26 return False
27 raise
28 return True
29
30
31 def maybe_publish(path):
32 content = open(os.path.join(path, 'Cargo.toml')).read()
33 name = re.search('^name = "([^"]+)"', content, re.M).group(1)
34 version = re.search('^version = "([^"]+)"', content, re.M).group(1)
35 if already_published(name, version):
36 print('%s %s is already published, skipping' % (name, version))
37 return False
38 subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
39 return True
40
41
42 def main():
43 print('Starting publish...')
44 for i, path in enumerate(TO_PUBLISH):
45 if maybe_publish(path):
46 if i < len(TO_PUBLISH)-1:
47 # Sleep to allow the index to update. This should probably
48 # check that the index is updated, or use a retry loop
49 # instead.
50 time.sleep(5)
51 print('Publish complete!')
52
53
54 if __name__ == '__main__':
55 main()