]> git.proxmox.com Git - cargo.git/blame - publish.py
Auto merge of #8491 - alexcrichton:fix-unstable-build-std-config, r=Eh2406
[cargo.git] / publish.py
CommitLineData
57c96c19
EH
1#!/usr/bin/env python3
2
3# This script is used to publish Cargo to crates.io.
4
5import os
6import re
7import subprocess
8import urllib.request
9from urllib.error import HTTPError
10
11
12TO_PUBLISH = [
13 'crates/cargo-platform',
14 'crates/crates-io',
15 '.',
16]
17
18
19def already_published(name, version):
20 try:
21 urllib.request.urlopen('https://crates.io/api/v1/crates/%s/%s/download' % (name, version))
22 except HTTPError as e:
23 if e.code == 404:
24 return False
25 raise
26 return True
27
28
29def maybe_publish(path):
30 content = open(os.path.join(path, 'Cargo.toml')).read()
31 name = re.search('^name = "([^"]+)"', content, re.M).group(1)
32 version = re.search('^version = "([^"]+)"', content, re.M).group(1)
33 if already_published(name, version):
34 print('%s %s is already published, skipping' % (name, version))
35 return
36 subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
37
38
39def main():
40 print('Doing dry run first...')
41 for path in TO_PUBLISH:
42 subprocess.check_call(['cargo', 'publish', '--no-verify', '--dry-run'], cwd=path)
43 print('Starting publish...')
44 for path in TO_PUBLISH:
45 maybe_publish(path)
46 print('Publish complete!')
47
48
49if __name__ == '__main__':
50 main()