Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Migrated away from unsupported actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasperson committed Mar 26, 2023
1 parent 5d8f0b5 commit 27fb35b
Showing 1 changed file with 57 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;

/** Contains a number of common steps shared between builders. */
/**
* Contains a number of common steps shared between builders.
*/
public class GitBuilder {
/** Builds the common top level comments for the workflow. */
/**
* Builds the common top level comments for the workflow.
*/
public String getInitialComments() {
return "# The following workflow provides an opinionated template you can customize for your own needs.\n"
+ "#\n"
Expand All @@ -26,15 +30,19 @@ public String getInitialComments() {
+ "# Get a trial Octopus instance from https://octopus.com/start\n";
}

/** Build the checkout step. */
/**
* Build the checkout step.
*/
public Step checkOutStep() {
return UsesWith.builder()
.uses("actions/checkout@v3")
.with(new ImmutableMap.Builder<String, String>().put("fetch-depth", "0").build())
.build();
}

/** Build the GitVersion installation step. */
/**
* Build the GitVersion installation step.
*/
public Step gitVersionInstallStep() {
return UsesWith.builder()
.name("Install GitVersion")
Expand All @@ -43,7 +51,9 @@ public Step gitVersionInstallStep() {
.build();
}

/** Build the step to calculate the versions from git. */
/**
* Build the step to calculate the versions from git.
*/
public Step getVersionCalculate() {
return UsesWith.builder()
.name("Determine Version")
Expand All @@ -53,7 +63,9 @@ public Step getVersionCalculate() {
.build();
}

/** Build the Octopus CLI installation step. */
/**
* Build the Octopus CLI installation step.
*/
public Step installOctopusCli() {
return UsesWith.builder()
.name("Install Octopus Deploy CLI")
Expand All @@ -62,7 +74,9 @@ public Step installOctopusCli() {
.build();
}

/** Build the test processing step. */
/**
* Build the test processing step.
*/
public Step buildJunitReport(@NonNull final String name, @NonNull final String path) {
return UsesWith.builder()
.name("Report")
Expand All @@ -89,22 +103,20 @@ public Step createGitHubRelease(@NonNull final RepoClient accessor) {
return UsesWith.builder()
.name("Create Release")
.id("create_release")
.uses("actions/create-release@v1")
.env(
new ImmutableMap.Builder<String, String>()
.put("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}")
.build())
.uses("softprops/action-gh-release@v1")
.with(
new ImmutableMap.Builder<String, String>()
.put("tag_name", "${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }}")
.put("release_name", "Release ${{ steps.determine_version.outputs.semVer }} Run ${{ github.run_number }} Attempt ${{ github.run_attempt }}")
.put("draft", "${{ github.ref == 'refs/heads/" + accessor.getDefaultBranches().get(0) + "' && 'false' || 'true' }}")
.put("prerelease", "${{ github.ref == 'refs/heads/" + accessor.getDefaultBranches().get(0) + "' && 'false' || 'true' }}")
.put("name", "${{ github.ref == 'refs/heads/" + accessor.getDefaultBranches().get(0) + "' && 'false' || 'true' }}")
.build())
.build();
}

/** Tag the repo with the release. */
/**
* Tag the repo with the release.
*/
public Step tagRepo() {
return UsesWith.builder()
.name("Tag Release")
Expand All @@ -117,26 +129,24 @@ public Step tagRepo() {
.build();
}

/** Build the step to upload file to the github release. */
/**
* Build the step to upload file to the github release.
*/
public Step uploadToGitHubRelease(@NonNull final String path, @NonNull final String name) {
return UsesWith.builder()
.name("Upload Release Asset")
.uses("actions/upload-release-asset@v1")
.env(
new ImmutableMap.Builder<String, String>()
.put("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}")
.build())
.uses("softprops/action-gh-release@v1")
.with(
new ImmutableMap.Builder<String, String>()
.put("upload_url", "${{ steps.create_release.outputs.upload_url }}")
.put("asset_path", path)
.put("asset_name", name)
.put("asset_content_type", "application/octet-stream")
.put("tag_name", "${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }}")
.put("files", path)
.build())
.build();
}

/** Build the step to push files to Octopus. */
/**
* Build the step to push files to Octopus.
*/
public Step pushToOctopus(@NonNull final String packages) {
return UsesWith.builder()
.name("Push packages to Octopus Deploy")
Expand All @@ -154,7 +164,9 @@ public Step pushToOctopus(@NonNull final String packages) {
.build();
}

/** Build the step to push Octopus build information. */
/**
* Build the step to push Octopus build information.
*/
public Step uploadOctopusBuildInfo(@NonNull final RepoClient accessor) {
return UsesWith.builder()
.name("Generate Octopus Deploy build information")
Expand All @@ -173,16 +185,18 @@ public Step uploadOctopusBuildInfo(@NonNull final RepoClient accessor) {
.build();
}

/** Build the step to create an Octopus release. */
/**
* Build the step to create an Octopus release.
*/
public Step createOctopusRelease(@NonNull final RepoClient accessor, @NonNull final String packages) {
return UsesWith.builder()
.name("Create Octopus Release")
.uses("OctopusDeploy/create-release-action@v3")
.env(new ImmutableMap.Builder<String, String>()
.put("OCTOPUS_API_KEY", "${{ secrets.OCTOPUS_API_TOKEN }}")
.put("OCTOPUS_URL", "${{ secrets.OCTOPUS_SERVER_URL }}")
.put("OCTOPUS_SPACE", "${{ secrets.OCTOPUS_SPACE }}")
.build())
.put("OCTOPUS_API_KEY", "${{ secrets.OCTOPUS_API_TOKEN }}")
.put("OCTOPUS_URL", "${{ secrets.OCTOPUS_SERVER_URL }}")
.put("OCTOPUS_SPACE", "${{ secrets.OCTOPUS_SPACE }}")
.build())
.with(
new ImmutableMap.Builder<String, String>()
.put("project", accessor.getRepoName().getOrElse("application"))
Expand All @@ -195,7 +209,9 @@ public Step collectDependencies() {
return collectDependencies(null);
}

/** Build the dependency collection step. */
/**
* Build the dependency collection step.
*/
public Step collectDependencies(final String workingDirectory) {
final String directory = StringUtils.isBlank(workingDirectory)
? "" : workingDirectory + "/";
Expand All @@ -214,7 +230,9 @@ public Step collectDependencyUpdates() {
return collectDependencyUpdates(null);
}

/** Build the dependency updates collection step. */
/**
* Build the dependency updates collection step.
*/
public Step collectDependencyUpdates(final String workingDirectory) {
final String directory = StringUtils.isBlank(workingDirectory)
? "" : workingDirectory + "/";
Expand All @@ -229,7 +247,9 @@ public Step collectDependencyUpdates(final String workingDirectory) {
.build();
}

/** Build the java installation step. */
/**
* Build the java installation step.
*/
public Step installJava() {
return UsesWith.builder()
.name("Set up JDK 1.17")
Expand All @@ -242,7 +262,9 @@ public Step installJava() {
.build();
}

/** Build the permissions object. */
/**
* Build the permissions object.
*/
public Permissions buildPermissions() {
return Permissions.builder()
.contents("write")
Expand Down

0 comments on commit 27fb35b

Please sign in to comment.