Skip to content
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

Deprecate stack-yaml input #50

Merged
merged 4 commits into from
Feb 23, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ jobs:
- uses: ./
with:
working-directory: example
stack-yaml: ${{ matrix.stack-yaml }}
stack-arguments: --stack-yaml ${{ matrix.stack-yaml }}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ jobs:
| name | description | required | default |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------- |
| `working-directory` | <p>Working directory for run commands</p> | `false` | `""` |
| `stack-yaml` | <p>Override stack.yaml, relative to working-directory</p> | `false` | `stack.yaml` |
| `test` | <p>Whether to run tests</p> | `false` | `true` |
| `stack-arguments` | <p>Additional arguments for all top-level <code>stack</code> command invocations.</p> | `false` | `--no-terminal` |
| `stack-query-arguments` | <p>Additional arguments in <code>stack query</code> invocations.</p> | `false` | `""` |
Expand All @@ -81,6 +80,8 @@ jobs:
| `stack-build-arguments-test` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Test</em> step.</p> | `false` | `""` |
| `cache-prefix` | <p>Prefix applied to all cache keys. This can be any value you like, but teams often use <code>v{N}</code> and bump it to <code>v{N+1}</code> when/if they need to explicitly bust caches.</p> | `false` | `""` |
| `cache-save-always` | <p>Save artifacts to the cache even if the build fails. This may speed up builds in subsequent runs at the expense of slightly-longer builds when a full cache-hit occurs. Since <code>@v4.2.0</code></p> | `false` | `false` |
| `upgrade-stack` | <p>Upgrade stack</p> | `false` | `true` |
| `stack-yaml` | <p><strong>Deprecated</strong> use <code>env.STACK_YAML</code> or <code>stack-arguments</code> instead.</p> | `false` | `""` |

<!-- action-docs-inputs action="action.yml" -->

Expand Down Expand Up @@ -141,7 +142,7 @@ jobs:
- uses: actions/checkout@v4
- uses: freckle/stack-action@v5
with:
stack-yaml: ${{ matrix.stack-yaml }}
stack-arguments: --stack-yaml ${{ matrix.stack-yaml }}
```

See [generate-matrix/action.yml](./generate-matrix/action.yml) for more details.
Expand Down
7 changes: 3 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ inputs:
working-directory:
description: |
Working directory for run commands
stack-yaml:
description: |
Override stack.yaml, relative to working-directory
default: "stack.yaml"
test:
description: |
Whether to run tests
Expand Down Expand Up @@ -56,6 +52,9 @@ inputs:
description: |
Upgrade stack
default: true
stack-yaml:
description: |
**Deprecated** use `env.STACK_YAML` or `stack-arguments` instead.
runs:
using: "node20"
main: "dist/index.js"
33 changes: 19 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ function getInputs() {
};
return {
workingDirectory: getInputDefault("working-directory", null),
stackYaml: getInputDefault("stack-yaml", "stack.yaml"),
test: core.getBooleanInput("test"),
stackArguments: getShellWordsInput("stack-arguments"),
stackSetupArguments: getShellWordsInput("stack-setup-arguments"),
Expand All @@ -138,6 +137,7 @@ function getInputs() {
cachePrefix: core.getInput("cache-prefix"),
cacheSaveAlways: core.getBooleanInput("cache-save-always"),
upgradeStack: core.getBooleanInput("upgrade-stack"),
stackYaml: getInputDefault("stack-yaml", null),
};
}
exports.getInputs = getInputs;
Expand Down Expand Up @@ -196,21 +196,26 @@ async function run() {
core.debug(`Change directory: ${inputs.workingDirectory}`);
process.chdir(inputs.workingDirectory);
}
if (inputs.stackYaml) {
core.warning("inputs.stack-yaml is deprecated. Set env.STACK_YAML or use inputs.stack-arguments instead.");
inputs.stackArguments.unshift(inputs.stackYaml);
inputs.stackArguments.unshift("--stack-yaml");
}
const stack = new stack_cli_1.StackCLI(inputs.stackArguments, core.isDebug());
const hashes = await core.group("Calculate hashes", async () => {
const hashes = await (0, hash_project_1.hashProject)(inputs.stackYaml);
const hashes = await (0, hash_project_1.hashProject)(stack.config);
core.info(`Snapshot: ${hashes.snapshot}`);
core.info(`Packages: ${hashes.package}`);
core.info(`Sources: ${hashes.sources}`);
return hashes;
});
const stack = new stack_cli_1.StackCLI(inputs.stackYaml, inputs.stackArguments, core.isDebug());
if (inputs.upgradeStack) {
await core.group("Upgrade stack", async () => {
await stack.upgrade();
});
}
const { stackYaml, stackDirectories } = await core.group("Determine stack directories", async () => {
const stackYaml = (0, stack_yaml_1.readStackYamlSync)(inputs.stackYaml);
const stackYaml = (0, stack_yaml_1.readStackYamlSync)(stack.config);
const stackDirectories = await (0, stack_yaml_1.getStackDirectories)(stackYaml, stack);
core.info([
`Stack root: ${stackDirectories.stackRoot}`,
Expand Down Expand Up @@ -400,23 +405,23 @@ const exec = __importStar(__nccwpck_require__(1514));
const parse_stack_path_1 = __nccwpck_require__(1895);
const parse_stack_query_1 = __nccwpck_require__(6445);
class StackCLI {
config;
resolver;
debug;
globalArgs;
resolver;
constructor(stackYaml, args, debug) {
constructor(args, debug) {
this.debug = debug ?? false;
const stackYamlArgs = !args.includes("--stack-yaml")
? ["--stack-yaml", stackYaml]
: [];
this.globalArgs = args;
const stackYamlIdx = args.indexOf("--stack-yaml");
const stackYamlArg = stackYamlIdx >= 0 ? args[stackYamlIdx + 1] : null;
this.config = stackYamlArg ?? process.env.STACK_YAML ?? "stack.yaml";
const resolverIdx = args.indexOf("--resolver");
const resolverArg = resolverIdx >= 0 ? args[resolverIdx + 1] : null;
this.resolver = resolverArg;
this.globalArgs = stackYamlArgs.concat(args);
if (!resolverArg && path.basename(stackYaml) === "stack-nightly.yaml") {
if (!this.resolver && path.basename(this.config) === "stack-nightly.yaml") {
this.resolver = "nightly";
this.globalArgs = stackYamlArgs
.concat(["--resolver", "nightly"])
.concat(args);
this.globalArgs.push("--resolver");
this.globalArgs.push("nightly");
}
}
async upgrade() {
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ module.exports = {
preset: "ts-jest",
testEnvironment: "node",
resetMocks: true,
globals: {
"ts-jest": {
isolatedModules: true,
},
},
};
6 changes: 4 additions & 2 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { envsubst } from "./envsubst";

export type Inputs = {
workingDirectory: string | null;
stackYaml: string;
test: boolean;
stackArguments: string[];
stackSetupArguments: string[];
Expand All @@ -15,6 +14,9 @@ export type Inputs = {
cachePrefix: string;
cacheSaveAlways: boolean;
upgradeStack: boolean;

// Deprecated
stackYaml: string | null;
};

export function getInputs(): Inputs {
Expand All @@ -26,7 +28,6 @@ export function getInputs(): Inputs {

return {
workingDirectory: getInputDefault("working-directory", null),
stackYaml: getInputDefault("stack-yaml", "stack.yaml"),
test: core.getBooleanInput("test"),
stackArguments: getShellWordsInput("stack-arguments"),
stackSetupArguments: getShellWordsInput("stack-setup-arguments"),
Expand All @@ -37,6 +38,7 @@ export function getInputs(): Inputs {
cachePrefix: core.getInput("cache-prefix"),
cacheSaveAlways: core.getBooleanInput("cache-save-always"),
upgradeStack: core.getBooleanInput("upgrade-stack"),
stackYaml: getInputDefault("stack-yaml", null),
};
}

Expand Down
22 changes: 14 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ async function run() {
process.chdir(inputs.workingDirectory);
}

if (inputs.stackYaml) {
core.warning(
"inputs.stack-yaml is deprecated. Set env.STACK_YAML or use inputs.stack-arguments instead.",
);

// Maintain original behavior for now
inputs.stackArguments.unshift(inputs.stackYaml);
inputs.stackArguments.unshift("--stack-yaml");
}

const stack = new StackCLI(inputs.stackArguments, core.isDebug());

const hashes = await core.group("Calculate hashes", async () => {
const hashes = await hashProject(inputs.stackYaml);
const hashes = await hashProject(stack.config);
core.info(`Snapshot: ${hashes.snapshot}`);
core.info(`Packages: ${hashes.package}`);
core.info(`Sources: ${hashes.sources}`);
return hashes;
});

const stack = new StackCLI(
inputs.stackYaml,
inputs.stackArguments,
core.isDebug(),
);

if (inputs.upgradeStack) {
await core.group("Upgrade stack", async () => {
await stack.upgrade();
Expand All @@ -39,7 +45,7 @@ async function run() {
const { stackYaml, stackDirectories } = await core.group(
"Determine stack directories",
async () => {
const stackYaml = readStackYamlSync(inputs.stackYaml);
const stackYaml = readStackYamlSync(stack.config);
const stackDirectories = await getStackDirectories(stackYaml, stack);

core.info(
Expand Down
54 changes: 18 additions & 36 deletions src/stack-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,26 @@ import { StackCLI } from "./stack-cli";
jest.spyOn(exec, "exec");

describe("StackCLI", () => {
test("Adds --stack-yaml", async () => {
const stackCLI = new StackCLI("my-stack.yaml", [], false);
test("Respects --resolver given", async () => {
const stackCLI = new StackCLI(["--resolver", "lts"], false);

await stackCLI.setup([]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
["--stack-yaml", "my-stack.yaml", "setup"],
["--resolver", "lts", "setup"],
undefined, // ExecOptions
);
});

test("Respects --resolver given", async () => {
test("Adds --resolver nightly", async () => {
const stackCLI = new StackCLI(
"my-stack.yaml",
["--resolver", "lts"],
["--stack-yaml", "sub/stack-nightly.yaml"],
false,
);

await stackCLI.setup([]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
["--stack-yaml", "my-stack.yaml", "--resolver", "lts", "setup"],
undefined, // ExecOptions
);
});

test("Adds --resolver nightly", async () => {
const stackCLI = new StackCLI("sub/stack-nightly.yaml", [], false);

await stackCLI.setup([]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
[
Expand All @@ -53,8 +40,12 @@ describe("StackCLI", () => {

test("Doesn't add --resolver nightly if given", async () => {
const stackCLI = new StackCLI(
"sub/stack-nightly.yaml",
["--resolver", "nightly-20240201"],
[
"--stack-yaml",
"sub/stack-nightly.yaml",
"--resolver",
"nightly-20240201",
],
false,
);

Expand All @@ -74,15 +65,13 @@ describe("StackCLI", () => {
});

test("buildDependencies", async () => {
const stackCLI = new StackCLI("stack.yaml", [], false);
const stackCLI = new StackCLI([], false);

await stackCLI.buildDependencies(["--coverage"]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
[
"--stack-yaml",
"stack.yaml",
"build",
"--test",
"--no-run-tests",
Expand All @@ -94,44 +83,37 @@ describe("StackCLI", () => {
});

test("buildNoTest", async () => {
const stackCLI = new StackCLI("stack.yaml", [], false);
const stackCLI = new StackCLI([], false);

await stackCLI.buildNoTest(["--coverage"]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
[
"--stack-yaml",
"stack.yaml",
"build",
"--test",
"--no-run-tests",
"--coverage",
],
["build", "--test", "--no-run-tests", "--coverage"],
undefined,
);
});

test("buildTest", async () => {
const stackCLI = new StackCLI("stack.yaml", [], false);
const stackCLI = new StackCLI([], false);

await stackCLI.buildTest(["--coverage"]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
["--stack-yaml", "stack.yaml", "build", "--test", "--coverage"],
["build", "--test", "--coverage"],
undefined,
);
});

test("build", async () => {
const stackCLI = new StackCLI("stack.yaml", [], false);
const stackCLI = new StackCLI([], false);

await stackCLI.build(["--coverage"]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
["--stack-yaml", "stack.yaml", "build", "--coverage"],
["build", "--coverage"],
undefined,
);
});
Expand Down
24 changes: 13 additions & 11 deletions src/stack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ export interface ExecDelegate {
}

export class StackCLI {
public config: string;
public resolver: string | null;

private debug: boolean;
private globalArgs: string[];

public resolver: string | null;

constructor(stackYaml: string, args: string[], debug?: boolean) {
constructor(args: string[], debug?: boolean) {
this.debug = debug ?? false;
this.globalArgs = args;

// Capture --stack-yaml if given
const stackYamlIdx = args.indexOf("--stack-yaml");
const stackYamlArg = stackYamlIdx >= 0 ? args[stackYamlIdx + 1] : null;

const stackYamlArgs = !args.includes("--stack-yaml")
? ["--stack-yaml", stackYaml]
: [];
this.config = stackYamlArg ?? process.env.STACK_YAML ?? "stack.yaml";

// Capture --resolver if given
const resolverIdx = args.indexOf("--resolver");
const resolverArg = resolverIdx >= 0 ? args[resolverIdx + 1] : null;

this.resolver = resolverArg;
this.globalArgs = stackYamlArgs.concat(args);

// Infer nightly if not given
if (!resolverArg && path.basename(stackYaml) === "stack-nightly.yaml") {
if (!this.resolver && path.basename(this.config) === "stack-nightly.yaml") {
this.resolver = "nightly";
this.globalArgs = stackYamlArgs
.concat(["--resolver", "nightly"])
.concat(args);
this.globalArgs.push("--resolver");
this.globalArgs.push("nightly");
}
}

Expand Down
Loading