Skip to content

Commit

Permalink
Add channel input and package to release
Browse files Browse the repository at this point in the history
The previous version did not include the package version when building a release
This change pulls in the template in order to set the package version for the
release that is created. The channel name is needed in order to get the proper
deployment template, so the additional input was added as optional. The channel
defaults to 'Default' as created by Octopus Deploy
  • Loading branch information
burtonr committed Jul 25, 2020
1 parent 9ba2148 commit c8be260
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ActionsHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static ActionResult<Inputs> ReadInputValues()
ProjectName = Environment.GetEnvironmentVariable("INPUT_PROJECT_NAME"),
ReleaseVersion = Environment.GetEnvironmentVariable("INPUT_RELEASE_VERSION"),
ReleaseId = Environment.GetEnvironmentVariable("INPUT_RELEASE_ID"),
EnvironmentName = Environment.GetEnvironmentVariable("INPUT_ENVIRONMENT_NAME")
EnvironmentName = Environment.GetEnvironmentVariable("INPUT_ENVIRONMENT_NAME"),
ChannelName = Environment.GetEnvironmentVariable("INPUT_CHANNEL_NAME")
};

var space = Environment.GetEnvironmentVariable("INPUT_SPACE_NAME");
Expand Down
1 change: 1 addition & 0 deletions Models/Inputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Inputs
public string ReleaseVersion { get; set; }
public string ReleaseId { get; set; }
public string EnvironmentName { get; set; }
public string ChannelName { get; set; } = "Default";

public OctoClientErrors ValidateCommonInputs()
{
Expand Down
48 changes: 47 additions & 1 deletion OctoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,26 @@ public ActionResult<ReleaseResource> BuildNewRelease()
ProjectId = projectResult.Result.Id,
Version = _inputs.ReleaseVersion
};


var templateResult = GetTemplateResult(projectResult.Result);

if (templateResult.HasErrors())
{
releaseResult.Error.ErrorCount += templateResult.Error.ErrorCount;
releaseResult.Error.ErrorMessages.AddRange(templateResult.Error.ErrorMessages);
}

foreach (var package in templateResult.Result.Packages)
{
releaseResult.Result.SelectedPackages.Add(
new SelectedPackage
{
ActionName = package.ActionName,
PackageReferenceName = package.PackageReferenceName,
Version = _inputs.ReleaseVersion
}
);
}

return releaseResult;
}
Expand Down Expand Up @@ -156,6 +175,33 @@ private ActionResult<ProjectResource> GetProjectResult(string projectName)
return result;
}

private ActionResult<ReleaseTemplateResource> GetTemplateResult(Octopus.Client.Model.ProjectResource projectResource)
{
CreateClient();
var result = new ActionResult<ReleaseTemplateResource>();

var repo = new OctopusRepository(_client);
var process = repo.DeploymentProcesses.Get(projectResource.DeploymentProcessId);

if (process == null)
{
result.Error.ErrorCount++;
result.Error.ErrorMessages.Add($"No Deployment Process was not found");
}

var channel = repo.Channels.FindByName(projectResource, _inputs.ChannelName);
var template = repo.DeploymentProcesses.GetTemplate(process, channel);

if (template == null)
{
result.Error.ErrorCount++;
result.Error.ErrorMessages.Add($"Release Template for {_inputs.ChannelName} channel was not found");
}

result.Result = template;
return result;
}

private ActionResult<EnvironmentResource> GetEnvironmentResult(string envName)
{
CreateClient();
Expand Down
4 changes: 2 additions & 2 deletions OctoClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Octopus.Client" Version="8.0.0" />
<ItemGroup>
<PackageReference Include="Octopus.Client" Version="8.8.1" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ GitHub Actions pass user input from their `workflow.yml` file to the action hand
- `INPUT_PROJECT_NAME`
- RELEASE_VERSION
- `INPUT_RELEASE_VERSION`
- This is passed to Octopus Deploy as-is, so it must match their requirements:
- You can use standard version numbers with two, three or four components: (`2.3`, `2.3.16`, `2.3.16.384`)
- You can also include [semantic version](https://g.octopushq.com/SemVer) tags: (`2.3.16-beta`, `2.3.16.384-pre-release`)
- This version must exactly match the version of the package that will be released or deployed
- RELEASE_ID
- `INPUT_RELEASE_ID`
- _Used only for the "deploy" action_
Expand All @@ -21,6 +25,9 @@ GitHub Actions pass user input from their `workflow.yml` file to the action hand
- SPACE_NAME
- `INPUT_SPACE_NAME`
- _Optional: default value: `Default`_
- CHANNEL_NAME
- `INPUT_CHANNEL_NAME`
- _Optional: default value: `Default`_

# Run Locally
This action can be run and invoked locally by running the Docker container and passing the inputs as environment variable parameters and the desired action (in the example below, this is `release` to create a new Octopus Release)
Expand Down

0 comments on commit c8be260

Please sign in to comment.