fork/cargo

git clone https://git.julia.blue/fork/cargo

borsAuto merge of #14202 - pietroalbini:pa-publish, r=weihanglo916c5a4f3

0.88.0
2.1 KiB72 linesraw
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
11import os
12import re
13import subprocess
14import urllib.request
15from urllib.error import HTTPError
16
17
18# Whenever you add a new crate to this list that does NOT start with "cargo-"
19# you must reach out to the infra team to add the crate to the list of crates
20# allowed to be published from the "cargo CI" crates.io token.
21TO_PUBLISH = [
22    'credential/cargo-credential',
23    'credential/cargo-credential-libsecret',
24    'credential/cargo-credential-wincred',
25    'credential/cargo-credential-1password',
26    'credential/cargo-credential-macos-keychain',
27    'crates/rustfix',
28    'crates/cargo-platform',
29    'crates/cargo-util',
30    'crates/crates-io',
31    'crates/cargo-util-schemas',
32    'crates/cargo-test-macro',
33    'crates/cargo-test-support',
34    '.',
35]
36
37
38def already_published(name, version):
39    url = f'https://static.crates.io/crates/{name}/{version}/download'
40    try:
41        urllib.request.urlopen(url)
42    except HTTPError as e:
43        # 403 and 404 are common responses to assume it is not published
44        if 400 <= e.code < 500:
45            return False
46        print(f'error: failed to check if {name} {version} is already published')
47        print(f'    HTTP response error code {e.code} checking {url}')
48        raise
49    return True
50
51
52def maybe_publish(path):
53    content = open(os.path.join(path, 'Cargo.toml')).read()
54    name = re.search('^name = "([^"]+)"', content, re.M).group(1)
55    version = re.search('^version = "([^"]+)"', content, re.M).group(1)
56    if already_published(name, version):
57        print('%s %s is already published, skipping' % (name, version))
58        return False
59    subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
60    return True
61
62
63def main():
64    print('Starting publish...')
65    for path in TO_PUBLISH:
66        maybe_publish(path)
67
68    print('Publish complete!')
69
70
71if __name__ == '__main__':
72    main()