Skip to content

Commit

Permalink
not quite, failed to update some stuff but fixed now
Browse files Browse the repository at this point in the history
  • Loading branch information
svecs132 committed May 13, 2024
1 parent 170ff0d commit efcb603
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 23 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ publish/
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
# *.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
Expand Down Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# built and packaged releases
*.zip
6 changes: 2 additions & 4 deletions Pro7ChordEditor/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
<startup />
</configuration>
6 changes: 3 additions & 3 deletions Pro7ChordEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public List<Pro7Presentation> Pro7Presentations
public MainWindow()
{
InitializeComponent();
LogPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
MainWindow_Window.Title = MainWindow_Window.Title + " (" + Assembly.GetExecutingAssembly().GetName().Version + ")";
LogPath = Path.GetDirectoryName(typeof(App).Assembly.Location);
MainWindow_Window.Title = $"{MainWindow_Window.Title} ({typeof(App).Assembly.GetName().Version})";
AddLog(MainWindow_Window.Title + " started");

// Quick and rough way to build combobox list of all keys/scale without proper data binding/MVVM....
Expand Down Expand Up @@ -127,7 +127,7 @@ public MainWindow()
private void AddLog(string logMessage)
{
if (!Directory.Exists(LogPath))
LogPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogPath = Path.GetDirectoryName(typeof(App).Assembly.Location);

string logFileName = LogPath + @"\Pro7ChordEditor.log";
try
Expand Down
14 changes: 0 additions & 14 deletions Pro7ChordEditor/Pro7ChordEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="Pro7LibIcon.png" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0-windows\_publish\FrameworkDependent\</PublishDir>
<PublishUrl>bin\Release\net8.0-windows\_publish\FrameworkDependent\</PublishUrl>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<ResourceLanguages>en</ResourceLanguages>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
18 changes: 18 additions & 0 deletions Pro7ChordEditor/Properties/PublishProfiles/SelfContained.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0-windows\_publish\SelfContained\</PublishDir>
<PublishUrl>bin\Release\net8.0-windows\_publish\SelfContained\</PublishUrl>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<ResourceLanguages>en</ResourceLanguages>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
98 changes: 98 additions & 0 deletions publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from os import chdir, system
import re

VERSION_RE = r'\d+(?:\.\d+){0,3}(?:-.+?)?'
ASSEMBLYINFO_PATH = r'PRo7ChordEditor\AssemblyInfo.cs'
PUBLISH_PATH = r'PRo7ChordEditor\bin\Release\net8.0-windows\_publish'

def get_curr_ver() -> str | None:
try:
with open(ASSEMBLYINFO_PATH) as file:
data = file.read()
ver = re.search(fr'\[assembly: AssemblyVersion\("({VERSION_RE})"\)\]', data).group(1)
return ver
except FileNotFoundError:
print('\x1b[33;1mWARNING\x1b[0m: AssemblyInfo.cs not found')
return None
except Exception as e:
print(f'\x1b[33;1mWARNING\x1b[0m: Unable to read the current version from AssemblyInfo.cs:\n {e}')
return None

def suggest_next_ver(curr_ver: str) -> str:
ver = curr_ver.split('-')[0].split('.')
suggestions = []
for i in range(len(ver)):
s = ver.copy()
s[i] = str(int(s[i]) + 1)
for j in range(i + 1, len(ver)):
s[j] = '0'
while len(s) < 3:
s.append('0')
if len(s) == 4 and s[3] == '0':
s.pop()
suggestions.append('.'.join(s))
suggestions.reverse()
return suggestions

def main():
print('==== \x1b[32mPro7 Chord Editor publish tool\x1b[0m ====')
curr_ver = get_curr_ver()

if curr_ver:
print(f'Current version of the program is \x1b[4m{curr_ver}\x1b[0m')
suggestions = suggest_next_ver(curr_ver)
print('\x1b[2mSuggested new versions:\x1b[0m')
for s in suggestions:
print(f' \x1b[2m{s}\x1b[0m')

new_ver: str = input('New version: ')

if new_ver not in suggestions:
print('\x1b[33;1mWARNING\x1b[0m: Not a sequential version')
print('Do you want to continue? (y/N) ', end='')
c = input().strip().lower()
if c != 'y':
print('Aborted')
return

with open(ASSEMBLYINFO_PATH) as file:
data = file.read()
data = re.sub(fr'(\[assembly: AssemblyVersion\()"{VERSION_RE}"(\)\])', fr'\1"{new_ver}"\2', data)

with open(ASSEMBLYINFO_PATH, 'w') as file:
file.write(data)

print(f'Version updated to \x1b[4m{new_ver}\x1b[0m')

print('Are you sure you want to continue? (y/N) ', end='')
c = input().strip().lower()
if c != 'y':
print('Aborted')
return

print('==== \x1b[32mCommitting...\x1b[0m ====')

system(r'git add PRo7ChordEditor\AssemblyInfo.cs')
system(f'git commit -m "Version {new_ver}"')
system('git push')
system(f'git tag -a v{new_ver} -m "Version {new_ver}"')
system('git push --tags')

print('==== \x1b[32mPublishing...\x1b[0m ====')

system('dotnet clean')

system('dotnet publish -p:PublishProfile=FrameworkDependent')
system('dotnet publish -p:PublishProfile=SelfContained')

print('==== \x1b[32mCompressing...\x1b[0m ====')

chdir(fr'{PUBLISH_PATH}\FrameworkDependent')
system(fr'tar -acvf ..\PRo7ChordEditor-{new_ver}-FD.zip *')
chdir(fr'..\SelfContained')
system(fr'tar -acvf ..\PRo7ChordEditor-{new_ver}-SC.zip *')

print('==== \x1b[32mDone\x1b[0m ====')

if __name__ == '__main__':
main()

0 comments on commit efcb603

Please sign in to comment.