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