fork/cargo

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

Ed Pagechore(release): Publish build-rs on release (#15708)aaeb634d9

0.92.0
2.2 KiB73 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    'crates/build-rs',
35    '.',
36]
37
38
39def already_published(name, version):
40    url = f'https://static.crates.io/crates/{name}/{version}/download'
41    try:
42        urllib.request.urlopen(url)
43    except HTTPError as e:
44        # 403 and 404 are common responses to assume it is not published
45        if 400 <= e.code < 500:
46            return False
47        print(f'error: failed to check if {name} {version} is already published')
48        print(f'    HTTP response error code {e.code} checking {url}')
49        raise
50    return True
51
52
53def maybe_publish(path):
54    content = open(os.path.join(path, 'Cargo.toml')).read()
55    name = re.search('^name = "([^"]+)"', content, re.M).group(1)
56    version = re.search('^version = "([^"]+)"', content, re.M).group(1)
57    if already_published(name, version):
58        print('%s %s is already published, skipping' % (name, version))
59        return False
60    subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
61    return True
62
63
64def main():
65    print('Starting publish...')
66    for path in TO_PUBLISH:
67        maybe_publish(path)
68
69    print('Publish complete!')
70
71
72if __name__ == '__main__':
73    main()