-
Notifications
You must be signed in to change notification settings - Fork 19
/
pip3_build_and_deploy
executable file
·64 lines (58 loc) · 1.9 KB
/
pip3_build_and_deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
use warnings;
# We use this as a simple bool, to dictate whether we use the
# pypi test url, or we are publishing live
my $test;
($test = "NULL") unless ($test = shift);
if ($test =~ m/test/i) {
print("Publishing to test environment\n");
$test = 1;
} elsif ($test =~ m/prod/i) {
print("Publishing to prod environment\n");
$test = 0;
} else {
print("Usage: $0 test|prod\n");
exit(1);
}
my $repo_extra = " --verbose ";
my $base;
# Add the test repo url if we are in test mode
if ($test == 1) {
$repo_extra = "--repository-url https://test.pypi.org/legacy/";
$base = "test.v5";
} else {
$base="v5"; # This is the base version, version5 in this case
}
my @tags = `git tag -l`;
my $version = "$base.0";
foreach (reverse(@tags)) {
if (m/$base.*/) {
s/\n//g;
$version = $_;
last;
}
}
my @tmp;
@tmp = split(/$base\./, $version);
$tmp[1] = int($tmp[1]) + 1;
my $new_version = "$base.$tmp[1]";
print "Last tag is $version. Proposed new tag is $new_version. Proceed? (y/n): ";
my $answer = <STDIN>;
if ($answer =~ '(y|Y)') {
print("OK, continuing\n");
} else {
print("Aborting\n");
exit(1);
}
sleep(1); # give user a moment to panic CTRL-C if needs be
# Write version into file for setup.py
die("Could not write version\n") unless (0 == system("echo $new_version > flac2all_pkg/version"));
# Create the git tag
die("Could not create git tag\n") unless (0 == system("git tag -a '$new_version' -m \"Auto-Release Version $new_version\""));
# And we remove the build and dist folder, to make sure fresh files are used
system("rm -rf ./build ./dist");
# Now run the code to push to pip
die("Could not build and deploy to pypi\n") unless (0 == system("python3 ./setup.py sdist bdist_wheel && twine upload $repo_extra dist/*"));
# Finally, we push the tag to git
system("git push origin $new_version");
print("Complete! To do a test upgrade, run \"pip install -U --index-url https://test.pypi.org/simple/ flac2all\"");