diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /src/tools/cargo/publish.py | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/publish.py')
-rwxr-xr-x | src/tools/cargo/publish.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tools/cargo/publish.py b/src/tools/cargo/publish.py new file mode 100755 index 000000000..5ace18f72 --- /dev/null +++ b/src/tools/cargo/publish.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# This script is used to publish Cargo to crates.io. + +import os +import re +import subprocess +import time +import urllib.request +from urllib.error import HTTPError + + +TO_PUBLISH = [ + 'crates/cargo-platform', + 'crates/cargo-util', + 'crates/crates-io', + '.', +] + + +def already_published(name, version): + try: + urllib.request.urlopen('https://crates.io/api/v1/crates/%s/%s/download' % (name, version)) + except HTTPError as e: + if e.code == 404: + return False + raise + return True + + +def maybe_publish(path): + content = open(os.path.join(path, 'Cargo.toml')).read() + name = re.search('^name = "([^"]+)"', content, re.M).group(1) + version = re.search('^version = "([^"]+)"', content, re.M).group(1) + if already_published(name, version): + print('%s %s is already published, skipping' % (name, version)) + return False + subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path) + return True + + +def main(): + print('Starting publish...') + for i, path in enumerate(TO_PUBLISH): + if maybe_publish(path): + if i < len(TO_PUBLISH)-1: + # Sleep to allow the index to update. This should probably + # check that the index is updated, or use a retry loop + # instead. + time.sleep(5) + print('Publish complete!') + + +if __name__ == '__main__': + main() |