-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ps1
65 lines (59 loc) · 1.99 KB
/
publish.ps1
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
65
param ($Version, $CommitMessage, $DryRun)
# setup the env to stop everything on error
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
if ($null -eq $Version) {
Write-Output "[ERROR] Version is required."
exit -1
}
# Phase 1: bump version
Write-Output "[$(Get-Date)] - Dry Run => [$($null -ne $DryRun)]"
Write-Output "[$(Get-Date)] - bump version to $Version"
if ($null -eq $CommitMessage) {
$message = "Release $Version"
} else {
$message = $CommitMessage
}
# read the content
if ($null -eq $DryRun) {
# not dry run, modify and commit
Write-Output "[$(Get-Date)] - update file VERSION"
$Version | Set-Content -NoNewline VERSION
Write-Output "[$(Get-Date)] - commit version update $Version with message '$message'"
git reset
git add VERSION
git commit -m "$message"
} else {
# output to console
Write-Output "[$(Get-Date)] - update file VERSION"
Write-Output "[$(Get-Date)] - DryRun modify: $Version"
}
## Pre-phase 2 - Ensure Environment
if (!(Test-Path -Path "publish_env")) {
# no publish_env found, let's create one
Write-Output "[$(Get-Date)] - create publish_env"
python -m virtualenv publish_env
}
# activate publish env and update 3rd party dependencies
Write-Output "[$(Get-Date)] - activate publish_env"
& "publish_env/Scripts/activate.ps1"
Write-Output "[$(Get-Date)] - ensure 3rd party dependencies"
pip install -r "scripts/publish/requirements.txt"
## Phase 2 - test
Write-Output "[$(Get-Date)] - test"
& "scripts/test.ps1"
## Phase 3 - build
Write-Output "[$(Get-Date)] - build"
python -m build --outdir "dist/$Version"
twine check "dist/$Version/*"
if ($null -eq $DryRun) {
## Phase 4 publish to pypi
Write-Output "[$( Get-Date )] - publish"
twine upload --verbose "dist/$Version/*"
# add the tag
Write-Output "[$( Get-Date )] - add tag $Version"
git tag -a "v$Version" -m "$message"
} else {
Write-Output "[$( Get-Date )] - DryRun - publish and add tag"
}