]> git.proxmox.com Git - rustc.git/blob - src/tools/cargo/publish.py
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / cargo / publish.py
1 #!/usr/bin/env python3
2
3 # This script is used to publish Cargo to crates.io.
4 #
5 # This is run automatically every 6 weeks by the Release team's automation
6 # whose source is at https://github.com/rust-lang/simpleinfra/.
7 #
8 # See https://doc.crates.io/contrib/process/release.html for more about
9 # Cargo's release process.
10
11 import os
12 import re
13 import subprocess
14 import urllib.request
15 from urllib.error import HTTPError
16
17
18 TO_PUBLISH = [
19 'credential/cargo-credential',
20 'credential/cargo-credential-libsecret',
21 'credential/cargo-credential-wincred',
22 'credential/cargo-credential-1password',
23 'credential/cargo-credential-macos-keychain',
24 'crates/cargo-platform',
25 'crates/cargo-util',
26 'crates/crates-io',
27 '.',
28 ]
29
30
31 def already_published(name, version):
32 try:
33 urllib.request.urlopen('https://crates.io/api/v1/crates/%s/%s/download' % (name, version))
34 except HTTPError as e:
35 if e.code == 404:
36 return False
37 raise
38 return True
39
40
41 def maybe_publish(path):
42 content = open(os.path.join(path, 'Cargo.toml')).read()
43 name = re.search('^name = "([^"]+)"', content, re.M).group(1)
44 version = re.search('^version = "([^"]+)"', content, re.M).group(1)
45 if already_published(name, version):
46 print('%s %s is already published, skipping' % (name, version))
47 return False
48 subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
49 return True
50
51
52 def main():
53 print('Starting publish...')
54 for path in TO_PUBLISH:
55 maybe_publish(path)
56
57 print('Publish complete!')
58
59
60 if __name__ == '__main__':
61 main()