Skip to content

Rewrite the action as a javascript action #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ lint:
- trufflehog@3.86.0
- trunk-toolbox@0.5.4
- yamllint@1.35.1
ignore:
- linters: [ALL]
paths:
- dist
actions:
definitions:
- id: test-pre-push
Expand Down
9 changes: 9 additions & 0 deletions __fixtures__/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { jest } from "@jest/globals";

export const debug = jest.fn();
export const error = jest.fn();
export const info = jest.fn();
export const getInput = jest.fn();
export const setOutput = jest.fn();
export const setFailed = jest.fn();
export const warning = jest.fn();
77 changes: 77 additions & 0 deletions __tests__/arguments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { jest } from "@jest/globals";

import * as core from "../__fixtures__/core.js";
jest.unstable_mockModule("@actions/core", () => core);

const { main } = await import("../src/lib.js");

const createEchoCli = async (tmpdir: string) => {
await fs.writeFile(
path.resolve(tmpdir, "trunk-analytics-cli"),
`#!/bin/bash
echo -n $@`,
);
};

describe("Arguments", () => {
afterEach(() => {
jest.resetAllMocks();
});

it("Forwards inputs - upload", async () => {
core.getInput.mockImplementation((name) => {
switch (name) {
case "junit-paths":
return "junit.xml";
case "org-slug":
return "org";
case "token":
return "token";
case "cli-version":
return "0.0.0";
default:
return "";
}
});
const tmpdir = await fs.mkdtemp(
path.resolve(os.tmpdir(), "trunk-analytics-uploader-test-"),
);
await createEchoCli(tmpdir);
const command = await main(tmpdir);
expect(command).toMatch(
`${tmpdir}/trunk-analytics-cli upload --junit-paths "junit.xml" --org-url-slug "org" --token "token"`,
);
await fs.rm(tmpdir, { recursive: true, force: true });
});

it("Forwards inputs - test", async () => {
core.getInput.mockImplementation((name) => {
switch (name) {
case "junit-paths":
return "junit.xml";
case "org-slug":
return "org";
case "token":
return "token";
case "cli-version":
return "0.0.0";
case "run":
return "exit 0";
default:
return "";
}
});
const tmpdir = await fs.mkdtemp(
path.resolve(os.tmpdir(), "trunk-analytics-uploader-test-"),
);
await createEchoCli(tmpdir);
const command = await main(tmpdir);
expect(command).toMatch(
`${tmpdir}/trunk-analytics-cli test --junit-paths "junit.xml" --org-url-slug "org" --token "token" -- exit 0`,
);
await fs.rm(tmpdir, { recursive: true, force: true });
});
});
26 changes: 5 additions & 21 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,13 @@ inputs:
hide-banner:
description: Whether to hide the top level flaky tests banner
required: false
github-token:
description: The GitHub token used to create an authenticated client
default: ${{ github.token }}
Comment on lines +50 to +52
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is automatic, but also necessary since it can't be extracted below.

variant:
description: User specified variant of a set of tests being uploaded.
required: false

runs:
using: composite
steps:
- name: Upload test results
run: ${GITHUB_ACTION_PATH}/script.sh ${{ inputs.run }}
shell: bash
env:
JUNIT_PATHS: ${{ inputs.junit-paths }}
ORG_URL_SLUG: ${{ inputs.org-slug }}
INPUT_TOKEN: ${{ inputs.token }}
REPO_HEAD_BRANCH: ${{ inputs.repo-head-branch }}
REPO_ROOT: ${{ inputs.repo-root }}
TAGS: ${{ inputs.tags }}
CLI_VERSION: ${{ inputs.cli-version }}
TEAM: ${{ inputs.team }}
QUARANTINE: ${{ inputs.quarantine }}
XCRESULT_PATH: ${{ inputs.xcresult-path }}
ALLOW_MISSING_JUNIT_FILES: ${{ inputs.allow-missing-junit-files }}
BAZEL_BEP_PATH: ${{ inputs.bazel-bep-path }}
PR_TITLE: ${{ github.event.pull_request.title }}
HIDE_BANNER: ${{ inputs.hide-banner }}
VARIANT: ${{ inputs.variant }}
using: node20
main: dist/index.js
Loading