private static void ChangeTxtFileVersion() { string versionFile = Path.Combine(BuildConfig.GetGitRepoLocalPath(), "version.txt"); FileUtils.DeleteIfExist(versionFile); File.WriteAllText(versionFile, BuildConfig.GetAppVersionString()); }
internal static async Task CreateRelease() { try { string version = BuildConfig.GetAppVersionString(); var newRelease = new NewRelease(version); newRelease.Name = $"New Update {version}"; newRelease.Body = $"Update for version {version}"; newRelease.Draft = false; newRelease.Prerelease = false; var gitHub = new GitHubClient(new ProductHeaderValue(BuildConfig.GetGitAppName())); gitHub.Credentials = new Credentials(BuildConfig.GetGitToken()); bool success = false; int maxTries = 2; int current = 0; Release release = null; while (!success && current++ < maxTries) { release = await gitHub.Repository.Release.Create("clauderoy790", BuildConfig.GetGitAppName(), newRelease); success = release != null && !string.IsNullOrEmpty(release.UploadUrl); } if (!success) { throw new Exception($"Failed to create new releaes, tried {current} times."); } var files = Directory.GetFiles(BuildConfig.GetGitRepoLocalPath()); foreach (var file in files) { if (!BuildConfig.ShouldIncludeFileInReleaseAsset(file)) { continue; } using (var fs = File.OpenRead(file)) { FileInfo info = new FileInfo(file); var assetUpload = new ReleaseAssetUpload() { FileName = info.Name, ContentType = MimeMapping.GetMimeMapping(info.Name), RawData = fs }; var asset = await gitHub.Repository.Release.UploadAsset(release, assetUpload); Console.WriteLine($"Uploaded asset {info.Name} to release {version} successfully"); }; } } catch (Exception ex) { Console.WriteLine($"Failed to create release: {ex.Message}"); } Console.WriteLine("Release creation done"); }
private static void RemoveOlderVerisons(string squirrelRealseDir) { var files = Directory.GetFiles(squirrelRealseDir); SemVersion curIntVer = new SemVersion(new Version(BuildConfig.GetAppVersionString())); List <string> nugetPackages = new List <string>(); //List all previous versions foreach (var file in files) { if (!file.EndsWith(".nupkg")) { continue; } SemVersion intVer = GetPackageVersion(file); if (curIntVer != intVer) { nugetPackages.Add(file); } } //file the previous version SemVersion previousVer = new SemVersion(0); foreach (var fileName in nugetPackages) { SemVersion ver = GetPackageVersion(fileName); if (ver < curIntVer && ver > previousVer) { previousVer = ver; } } //delete every other version and invalid named verison foreach (var file in nugetPackages) { SemVersion ver = GetPackageVersion(file); bool containsSquirrelNaming = file.Contains("-delta") || file.Contains("-full"); if (ver == previousVer) { if (!containsSquirrelNaming || file.Contains("-delta")) { File.Delete(file); } } if (ver != curIntVer && ver != previousVer) { File.Delete(file); } if (ver == curIntVer && !containsSquirrelNaming) { File.Delete(file); } } }
static async Task Main(string[] args) { //test args //args = new string[] { @"Organic-Wizard|C:\Git\Organic-Wizard\src\Organic-Wizard| C:\Git\Organic-Wizard\src\| C:\Git\Organic-Wizard\src\Organic-Wizard\| Release"}; BuildData.Init(args); if (!BuildConfig.ShouldExecuteBuildEvent()) { return; } CopyReleaseFolderToPostBuildFolder(BuildData.TargetDir, BuildData.SolutionDir); var version = BuildConfig.GetAppVersionString(); NugetHelper.PackageInfo info = new NugetHelper.PackageInfo() { Id = BuildData.ProjectName, Version = version, Author = "Claude", Description = BuildData.ProjectName, Title = BuildData.ProjectName, FilesFolder = BuildData.TargetDir }; string packageName = NugetHelper.CreatePackage(info, BuildData.SolutionDir); string squirrelReleaseFolder = Path.Combine(BuildData.SolutionDir, "Releases"); string squirrelPackageName = GetSquirrelPackageName(packageName); DeleteSetupFiles(squirrelReleaseFolder, squirrelPackageName); RemoveOlderVerisons(squirrelReleaseFolder); CopyReleaseDirToTempAndCopyBack(squirrelReleaseFolder); bool succes = await Releasify(squirrelReleaseFolder, packageName, squirrelPackageName, 5000); if (succes) { File.Delete(Path.Combine(BuildData.SolutionDir, packageName)); CopyReleaseFilesToGitFolder(squirrelReleaseFolder); GitHelper.AddCommitPush(); await GitHelper.CreateRelease(); ChangeTxtFileVersion(); BuildConfig.SetTxtFileVersion(BuildData.SettingsVersion); File.Copy(BuildConfig.GetTxtVersionFilePath(), Path.Combine(BuildConfig.GetGitRepoLocalPath(), BuildConfig.GetVerionTxtFileName()), true); GitHelper.AddCommitPush(); Console.WriteLine($"Version {version} released successfully!"); } else { Console.WriteLine($"Failed to release package {packageName}"); } }
public static void AddCommitPush() { using (PowerShell powershell = PowerShell.Create()) { //powershell.AddScript(@"Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force"); //powershell.AddScript(@"Start-Service sshd"); powershell.AddScript($"cd '{BuildConfig.GetGitRepoLocalPath()}'"); powershell.AddScript(@"Start-Service ssh-agent"); powershell.AddScript($"ssh-add \"{BuildConfig.GetSSHKeyLocation()}\""); powershell.AddScript(@"git pull"); powershell.AddScript(@"git add *"); powershell.AddScript($"git commit -m 'Commit version {BuildConfig.GetAppVersionString()}'"); powershell.AddScript(@"git push"); Collection <PSObject> results = powershell.Invoke(); } }