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