-
Notifications
You must be signed in to change notification settings - Fork 208
/
publish.cmd
216 lines (168 loc) · 6.39 KB
/
publish.cmd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@echo off
SETLOCAL EnableDelayedExpansion
cd %~dp0
SET ROOT=%~dp0
set WINGET_SRC=%ROOT%..\winget-pkgs
for /f "usebackq" %%i in (`%ROOT%\tools\xsl -e -s %ROOT%\src\Version\version.xsl %ROOT%\src\Version\version.props`) do (
set VERSION=%%i
)
if "%VERSION%" == "" goto :noversion
echo ### Publishing version %VERSION%...
set WINGET=1
set GITRELEASE=1
set UPLOAD=1
set PUBLISH=%ROOT%\src\Application\bin\Release\app.publish
set WIXBIN=%ProgramFiles% (x86)\WiX Toolset v3.14\bin
:parse
if "%1"=="/nowinget" set WINGET=0
if "%1"=="/norelease" set GITRELEASE=0
if "%1"=="/noupload" set UPLOAD=0
if "%1"=="" goto :done
shift
goto :parse
:done
where sed > nul 2>&1
if ERRORLEVEL 1 goto :nosed
if EXIST "%ROOT%\publish" rd /s /q "%ROOT%\publish"
if EXIST "%PUBLISH%" rd /s /q "%PUBLISH%"
git clean -dfx
call .\build.cmd
msbuild /target:publish src\xmlnotepad.sln /p:Configuration=Release "/p:Platform=Any CPU"
if ERRORLEVEL 1 goto :nobits
if not EXIST %PUBLISH%\XmlNotepad.application goto :nobits
move "%PUBLISH%" "%ROOT%\publish"
if not EXIST "%WIXBIN%\WixUtilExtension.dll" goto :nowix
echo Building XmlNotepadSetup.msi...
msbuild src\xmlnotepadsetup.sln /p:Configuration=Release /target:XmlNotepadSetup /p:OutDir=bin\Release\
if ERRORLEVEL 1 goto :err_setup
if not EXIST src\XmlNotepadSetup\bin\Release\XmlNotepadSetup.msi goto :nomsi
echo Building XmlNotepadPackage and Bundle...
msbuild /target:build src\xmlnotepadsetup.sln /p:Configuration=Release "/p:Platform=Any CPU"
if ERRORLEVEL 1 goto :noappx
if EXIST src\XmlNotepadSetup\bin\Release\XmlNotepadSetup.zip del src\XmlNotepadSetup\bin\Release\XmlNotepadSetup.zip
if "%LOVETTSOFTWARE_STORAGE_CONNECTION_STRING%" == "" goto :nokey
copy /y src\Updates\Updates.xml publish\
if ERRORLEVEL 1 goto :eof
copy /y src\Updates\Updates.xslt publish\
if ERRORLEVEL 1 goto :eof
copy /y src\Updates\Updates.xsd publish\
if ERRORLEVEL 1 goto :eofn
copy /y src\Updates\Updates.xml src\XmlNotepadSetup\bin\Release\
if ERRORLEVEL 1 goto :eof
copy /y src\Updates\Updates.xslt src\XmlNotepadSetup\bin\Release\
if ERRORLEVEL 1 goto :eof
copy /y src\Updates\Updates.xsd src\XmlNotepadSetup\bin\Release\
if ERRORLEVEL 1 goto :eof
if exist publish\XmlNotepadSetup.zip del publish\XmlNotepadSetup.zip
pwsh -command "Compress-Archive -Path src\XmlNotepadSetup\bin\Release\* -DestinationPath publish\XmlNotepadSetup.zip"
set bundle=%ROOT%\src\XmlNotepadPackage\AppPackages\%VERSION%\XmlNotepadPackage_%VERSION%_Test\XmlNotepadPackage_%VERSION%_AnyCPU.msixbundle
if not EXIST %bundle% goto :noappx
set zipfile=publish\XmlNotepadSetup.zip
if "%GITRELEASE%" == "0" goto :upload
echo Creating new release for version %VERSION%
%ROOT%\tools\xsl -e -s src\Updates\LatestVersion.xslt src\Updates\Updates.xml > notes.txt
gh release create %VERSION% "%bundle%" "%zipfile%" --notes-file notes.txt --title "Xml Notepad %VERSION%"
if ERRORLEVEL 1 goto :nogh
del notes.txt
:upload
if "%UPLOAD%" == "0" goto :winget
echo Uploading ClickOnce installer to XmlNotepad
call AzurePublishClickOnce.cmd publish downloads/XmlNotepad "%LOVETTSOFTWARE_STORAGE_CONNECTION_STRING%"
if ERRORLEVEL 1 goto :uploadfailed
echo ============ Done publishing ClickOnce installer to XmlNotepad ==============
:winget
where wingetcreate > nul 2>&1
if ERRORLEVEL 1 winget install wingetcreate
winget upgrade wingetcreate
if "%WINGET%"=="0" goto :skipwinget
if not exist %WINGET_SRC% goto :nowinget
echo Syncing winget master branch
pushd %WINGET_SRC%\manifests\m\Microsoft\XMLNotepad
git checkout master
if ERRORLEVEL 1 goto :eof
git pull
if ERRORLEVEL 1 goto :eof
git fetch upstream master
if ERRORLEVEL 1 goto :eof
git merge upstream/master
if ERRORLEVEL 1 goto :eof
git push
if ERRORLEVEL 1 goto :eof
set OLDEST=
for /f "usebackq" %%i in (`dir /b`) do (
if "!OLDEST!" == "" set OLDEST=%%i
)
if "!OLDEST!" == "" goto :prepare
echo ======================== Replacing "!OLDEST!" version...
git mv "!OLDEST!" %VERSION%
if ERRORLEVEL 1 goto :gitError "git mv !OLDEST! %VERSION%"
:prepare
popd
echo Preparing winget package
set TARGET=%WINGET_SRC%\manifests\m\Microsoft\XMLNotepad\%VERSION%\
if not exist %TARGET% mkdir %TARGET%
copy /y tools\Microsoft.XMLNotepad*.yaml %TARGET%
winget update wingetcreate
wingetcreate update Microsoft.XMLNotepad --version %VERSION% -o %WINGET_SRC% -u https://github.com/microsoft/XmlNotepad/releases/download/%VERSION%/XmlNotepadPackage_%VERSION%_AnyCPU.msixbundle
if ERRORLEVEL 1 goto :eof
pushd %TARGET%
winget validate .
if ERRORLEVEL 1 goto :installfailed
winget install -m .
if ERRORLEVEL 1 goto :installfailed
git checkout -b "clovett/xmlnotepad_%VERSION%"
if ERRORLEVEL 1 call :gitError "git checkout -b clovett/xmlnotepad_%VERSION%"
git add *
if ERRORLEVEL 1 call :gitError "git add *"
git commit -a -m "XML Notepad version %VERSION%"
if ERRORLEVEL 1 call :gitError "git commit -a -m 'XML Notepad version %VERSION%'"
git push -u origin "clovett/xmlnotepad_%VERSION%"
if ERRORLEVEL 1 call :gitError "git push -u origin clovett/xmlnotepad_%VERSION%
echo =============================================================================================================
echo Please create Pull Request for the new "clovett/xmlnotepad_%VERSION%" branch.
call gitweb
:skipwinget
goto :eof
:noversion
echo Failed to find the VERSION in src\Version\version.props
exit /b 1
:nobits
echo '%PUBLISH%' folder not found, so the build failed, please manually run release build and publish first.
exit /b 1
:nomsi
echo 'XmlNotepadSetup\bin\Release\XmlNotepadSetup.msi' not found, please use src\XmlNotepadSetup.sln to build the msi.
exit /b 1
:nokey
echo Please set your LOVETTSOFTWARE_STORAGE_CONNECTION_STRING
exit /b 1
:noappx
echo Please build the .msixbundle using src\XmlNotepadSetup.sln XmlNotepadPackage project, publish/create appx packages.
exit /b 1
:nosed
echo Missing sed.exe tool, please add c:\Program Files\Git\usr\bin to your PATH
exit /b 1
:installfailed
echo winget install failed
exit /b 1
:nowinget
echo Please clone [email protected]:lovettchris/winget-pkgs.git into %WINGET_SRC%
exit /b 1
:nowix
echo Please install the wixtoolset to %WIXBIN%, and add this to your PATH
exit /b 1
:err_setup
popd
echo src\XmlNotepadSetup build failed, try building inside XmlNotepadSetup.sln and ensure candle.exe command line matches this script
exit /b 1
:skipwinget
echo Skipping winget setup
exit /b 1
:uploadfailed
echo Upload to Azure failed.
exit /b 1
:gitError
echo ### error : %1
exit /b 1
:nogh
echo ### gh release failed, do you need to run gh auth login?
exit /b 1