]>
Commit | Line | Data |
---|---|---|
57c96c19 EH |
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 | |
9f79450e | 8 | import time |
57c96c19 EH |
9 | import urllib.request |
10 | from urllib.error import HTTPError | |
11 | ||
12 | ||
13 | TO_PUBLISH = [ | |
14 | 'crates/cargo-platform', | |
88810035 | 15 | 'crates/cargo-util', |
57c96c19 EH |
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)) | |
9f79450e | 37 | return False |
57c96c19 | 38 | subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path) |
9f79450e | 39 | return True |
57c96c19 EH |
40 | |
41 | ||
42 | def main(): | |
57c96c19 | 43 | print('Starting publish...') |
9f79450e EH |
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) | |
57c96c19 EH |
51 | print('Publish complete!') |
52 | ||
53 | ||
54 | if __name__ == '__main__': | |
55 | main() |