Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
github-up: Remove 'body' parameter, delay release publish until all a…
Browse files Browse the repository at this point in the history
…ssets are uploaded
  • Loading branch information
caesay committed Aug 22, 2022
1 parent ad538b2 commit 1289317
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
24 changes: 16 additions & 8 deletions src/Squirrel.CommandLine/Sync/GitHubRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,26 @@ public async Task UploadMissingPackages()
throw new Exception("There are no nupkg's in the releases directory to upload");

var ver = Enumerable.MaxBy(releases, x => x.Version);
if(ver == null)
if (ver == null)
throw new Exception("There are no nupkg's in the releases directory to upload");
var semVer = ver.Version;

Log.Info($"Preparing to upload latest local release to GitHub");


var newReleaseReq = new NewRelease(semVer.ToString()) {
Body = _options.body + "\r\n" + ver.GetReleaseNotes(releaseDirectoryInfo.FullName),
Draft = _options.draft,
Body = "", // ver.GetReleaseNotes(releaseDirectoryInfo.FullName),
Draft = true,
Prerelease = semVer.HasMetadata || semVer.IsPrerelease,
Name = string.IsNullOrWhiteSpace(_options.name)
? semVer.ToString()
: _options.name,
Name = string.IsNullOrWhiteSpace(_options.releaseName)
? semVer.ToString()
: _options.releaseName,
};

Log.Info($"Creating draft release titled '{semVer.ToString()}'");

var existingReleases = await client.Repository.Release.GetAll(repoOwner, repoName);
if (existingReleases.Any(r => r.TagName == semVer.ToString())) {
throw new Exception($"There is already an existing release titled '{semVer}'. Please delete this release or choose a new version number.");
throw new Exception($"There is already an existing release tagged '{semVer}'. Please delete this release or choose a new version number.");
}

var release = await client.Repository.Release.Create(repoOwner, repoName, newReleaseReq);
Expand Down Expand Up @@ -142,6 +141,15 @@ public async Task UploadMissingPackages()
await client.Repository.Release.UploadAsset(release, data, CancellationToken.None);

Log.Info($"Done creating draft GitHub release.");

// convert draft to full release
if (_options.publish) {
Log.Info("Converting draft to full published release.");
var upd = release.ToUpdate();
upd.Draft = false;
release = await client.Repository.Release.Edit(repoOwner, repoName, release.Id, upd);
}

Log.Info("Release URL: " + release.HtmlUrl);
}

Expand Down
16 changes: 7 additions & 9 deletions src/Squirrel.CommandLine/SyncOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public SyncS3Options()
Add("endpoint=", "Custom service {URL} (backblaze, digital ocean, etc)", v => endpoint = v);
Add("bucket=", "{NAME} of the S3 bucket", v => bucket = v);
Add("pathPrefix=", "A sub-folder {PATH} used for files in the bucket, for creating release channels (eg. 'stable' or 'dev')", v => pathPrefix = v);
Add("overwrite", "Replace existing files if source has changed", v => overwrite = true);
Add("keepMaxReleases=", "Applies a retention policy during upload which keeps only the specified {NUMBER} of old versions",
Add("overwrite", "(up only) Replace existing files if source has changed", v => overwrite = true);
Add("keepMaxReleases=", "(up only) Applies a retention policy during upload which keeps only the specified {NUMBER} of old versions",
v => keepMaxReleases = ParseIntArg(nameof(keepMaxReleases), v));
}

Expand Down Expand Up @@ -85,18 +85,16 @@ internal class SyncGithubOptions : BaseOptions
public string repoUrl { get; private set; }
public string token { get; private set; }
public bool pre { get; private set; }
public bool draft { get; private set; }
public string name { get; private set; }
public string body { get; private set; }
public bool publish { get; private set; }
public string releaseName { get; private set; }

public SyncGithubOptions()
{
Add("repoUrl=", "Full url to the github repository\nexample: 'https://github.com/myname/myrepo'", v => repoUrl = v);
Add("token=", "OAuth token to use as login credentials", v => token = v);
Add("pre", "Download pre-release instead of stable", _ => pre = true);
Add("draft", "(up only) Mark release as draft", _ => draft = true);
Add("name=", "(up only) Name of the release", v => name = v);
Add("body=", "(up only) Body of the release, will be written before the release notes.", v => body = v);
Add("pre", "(down only) Get latest pre-release instead of stable", v => pre = true);
Add("publish", "(up only) Publish release instead of creating draft", v => publish = true);
Add("releaseName=", "(up only) A custom {NAME} for created release", v => releaseName = v);
}

public override void Validate()
Expand Down

0 comments on commit 1289317

Please sign in to comment.