]> git.proxmox.com Git - cargo.git/blame - publish.py
store jobs priorities in the pending queue
[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
9f79450e 8import time
57c96c19
EH
9import urllib.request
10from urllib.error import HTTPError
11
12
13TO_PUBLISH = [
14 'crates/cargo-platform',
88810035 15 'crates/cargo-util',
57c96c19
EH
16 'crates/crates-io',
17 '.',
18]
19
20
21def 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
31def 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
42def 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
54if __name__ == '__main__':
55 main()