Skip to content

Commit

Permalink
fix: redirect output, update glob, and fix tests
Browse files Browse the repository at this point in the history
This commit redirects standard and error output to the "@actions/core"
logging functions, updates the glob function calls to include a wildcard
to pick up files under the taskcat_outputs directory, and updates
integration test workflow files to include the new 'aws-account-id'
action parameters.

The --minimal-output flag has also been added to taskcat calls to
eliminate out-of-order log messages when dynamically printing status
with reprint.
  • Loading branch information
ShahradR committed Jan 30, 2021
1 parent b3fa6d9 commit 9111ae4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
9 changes: 6 additions & 3 deletions __tests__/taskcat-artifact-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe("the maskAccountId() function", () => {
const fileContents = "abcd1234";
const awsAccountId = "1234567890";

process.env.GITHUB_WORKSPACE = "/github/workspace";

mockedGlobSync.mockReturnValue(["taskcat_outputs/test.txt"]);
mockedReadFileSync.mockReturnValue(fileContents);

Expand Down Expand Up @@ -76,9 +78,7 @@ describe("the maskAccountId() function", () => {

describe("the publishTaskcatOutputs function", () => {
const taskcatArtifactManager: TaskcatArtifactManager = new TaskcatArtifactManager();

const mockedGlobSync = (sync as unknown) as jest.MockedFunction<typeof sync>;

const uploadArtifact = artifact.create();

it("should retrieve all files from the taskcat_output directory", () => {
Expand Down Expand Up @@ -169,6 +169,9 @@ describe("the maskAndPublishTaskcatArtifacts function", () => {
new MockedArtifactClient()
);

expect(spy).toHaveBeenCalledWith(expect.anything(), "taskcat_outputs/");
expect(spy).toHaveBeenCalledWith(
expect.anything(),
"/github/workspace/taskcat_outputs/"
);
});
});
26 changes: 21 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10089,7 +10089,7 @@ var TaskcatArtifactManager = /** @class */ (function () {
TaskcatArtifactManager.prototype.maskAndPublishTaskcatArtifacts = function (awsAccountId, artifactClient) {
core.info("Entered the maskAndPublishTaskcatArtifacts function");
this.maskAccountId(awsAccountId, "taskcat_outputs/");
this.publishTaskcatOutputs(artifactClient, "taskcat_outputs/");
this.publishTaskcatOutputs(artifactClient, process.env.GITHUB_WORKSPACE + "/taskcat_outputs/");
};
/**
* Masks the AWS account ID from the taskcat_output logs.
Expand All @@ -10116,7 +10116,7 @@ var TaskcatArtifactManager = /** @class */ (function () {
* @param filePath - the file path to the `taskcat_outputs` directory
*/
TaskcatArtifactManager.prototype.publishTaskcatOutputs = function (artifactClient, filePath) {
var taskcatLogs = glob_1.glob.sync(filePath);
var taskcatLogs = glob_1.glob.sync(filePath + "*");
artifactClient.uploadArtifact("taskcat_outputs", taskcatLogs, filePath);
};
return TaskcatArtifactManager;
Expand Down Expand Up @@ -10162,9 +10162,25 @@ function run() {
var artifactClient = artifact.create();
var awsAccountId = core.getInput("aws-account-id");
var taskcatCommands = core.getInput("commands");
child_process_1.default.execSync("taskcat " + taskcatCommands);
var taskcatArtifactManager = new taskcat_artifact_manager_1.TaskcatArtifactManager();
taskcatArtifactManager.maskAndPublishTaskcatArtifacts(awsAccountId, artifactClient);
core.info("Received commands: " + taskcatCommands);
var newList = taskcatCommands.split(" ");
newList.push("--minimal-output");
var child = child_process_1.default.spawn("taskcat", newList, {
stdio: ["ignore", "pipe", "pipe"],
});
child.stdout.setEncoding("utf-8");
child.stderr.setEncoding("utf-8");
child.stderr.pipe(process.stdout);
child.stdout.on("data", function (data) {
core.info(data);
});
child.on("exit", function (exitCode) {
var taskcatArtifactManager = new taskcat_artifact_manager_1.TaskcatArtifactManager();
taskcatArtifactManager.maskAndPublishTaskcatArtifacts(awsAccountId, artifactClient);
if (exitCode !== 0) {
core.setFailed("The taskcat test did not complete successfully.");
}
});
}
run();

Expand Down
8 changes: 5 additions & 3 deletions e2e/resources/action-taskcat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ describe("integration tests", () => {
let actOutput = "";

try {
cp.execSync(
`act \
actOutput = cp
.execSync(
`act \
--job taskcat \
--directory ./e2e/resources/default/`
);
)
.toString();
} catch (error) {
actOutput = error.stdout.toString();
exitCode = error.status;
Expand Down
1 change: 1 addition & 0 deletions e2e/resources/default/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
uses: ./../../../
with:
commands: test run
aws-account-id: "123456789"
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
Expand Down
1 change: 1 addition & 0 deletions e2e/resources/help/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
uses: ./../../../
with:
commands: "--help"
aws-account-id: "123456789"
32 changes: 26 additions & 6 deletions src/post-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,34 @@ function run() {
const artifactClient = artifact.create();
const awsAccountId = core.getInput("aws-account-id");
const taskcatCommands = core.getInput("commands");
core.info("Received commands: " + taskcatCommands);

cp.execSync("taskcat " + taskcatCommands);
const newList = taskcatCommands.split(" ");
newList.push("--minimal-output");

const taskcatArtifactManager = new TaskcatArtifactManager();
taskcatArtifactManager.maskAndPublishTaskcatArtifacts(
awsAccountId,
artifactClient
);
const child = cp.spawn("taskcat", newList, {
stdio: ["ignore", "pipe", "pipe"],
});

child.stdout.setEncoding("utf-8");
child.stderr.setEncoding("utf-8");
child.stderr.pipe(process.stdout);

child.stdout.on("data", (data) => {
core.info(data);
});

child.on("exit", (exitCode) => {
const taskcatArtifactManager = new TaskcatArtifactManager();
taskcatArtifactManager.maskAndPublishTaskcatArtifacts(
awsAccountId,
artifactClient
);

if (exitCode !== 0) {
core.setFailed("The taskcat test did not complete successfully.");
}
});
}

run();
7 changes: 5 additions & 2 deletions src/taskcat-artifact-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class TaskcatArtifactManager {
): void {
core.info("Entered the maskAndPublishTaskcatArtifacts function");
this.maskAccountId(awsAccountId, "taskcat_outputs/");
this.publishTaskcatOutputs(artifactClient, "taskcat_outputs/");
this.publishTaskcatOutputs(
artifactClient,
process.env.GITHUB_WORKSPACE + "/taskcat_outputs/"
);
}

/**
Expand Down Expand Up @@ -51,7 +54,7 @@ class TaskcatArtifactManager {
artifactClient: artifact.ArtifactClient,
filePath: string
): void {
const taskcatLogs: string[] = glob.sync(filePath);
const taskcatLogs: string[] = glob.sync(filePath + "*");

artifactClient.uploadArtifact("taskcat_outputs", taskcatLogs, filePath);
}
Expand Down

0 comments on commit 9111ae4

Please sign in to comment.