From f64b4472b5eda01fda8dae1a0e8d8650fd47360a Mon Sep 17 00:00:00 2001 From: somaz Date: Thu, 11 Jun 2026 16:38:10 +0900 Subject: [PATCH 1/9] feat: add atmos-version-file input to read the version from a file --- README.md | 17 +++++++ README.yaml | 16 +++++++ action.yml | 6 +++ src/__tests__/setup-atmos.test.ts | 3 ++ src/__tests__/version-file.test.ts | 61 +++++++++++++++++++++++++ src/main.ts | 71 +++++++++++++++++++++++++++++- 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/version-file.test.ts diff --git a/README.md b/README.md index 99a42b8..d447c20 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,22 @@ steps: atmos-version: 0.15.0 ```` +The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise +`.tool-versions` format (an `atmos ` line) as well as a plain version file whose contents are the version +(e.g. `.atmos-version`): + +```yaml +steps: + - uses: hashicorp/setup-terraform@v2 + + - name: Setup atmos + uses: cloudposse/github-action-setup-atmos@v2 + with: + atmos-version-file: .tool-versions +```` + +When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. + The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: ```yaml @@ -118,6 +134,7 @@ steps: | Name | Description | Default | Required | |------|-------------|---------|----------| | atmos-version | Version Spec of the version to use. Examples: 1.x, 10.15.1, >=10.15.0. | latest | false | +| atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | | install-wrapper | Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | true | false | | token | Used to pull atmos distributions from Cloud Posse's GitHub repository. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ${{ github.server\_url == 'https://github.com' && github.token \|\| '' }} | false | diff --git a/README.yaml b/README.yaml index e02313d..e109215 100644 --- a/README.yaml +++ b/README.yaml @@ -73,6 +73,22 @@ usage: |- atmos-version: 0.15.0 ```` + The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise + `.tool-versions` format (an `atmos ` line) as well as a plain version file whose contents are the version + (e.g. `.atmos-version`): + + ```yaml + steps: + - uses: hashicorp/setup-terraform@v2 + + - name: Setup atmos + uses: cloudposse/github-action-setup-atmos@v2 + with: + atmos-version-file: .tool-versions + ```` + + When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. + The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: ```yaml diff --git a/action.yml b/action.yml index 8453848..bee9e87 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,12 @@ inputs: atmos-version: description: "Version Spec of the version to use. Examples: 1.x, 10.15.1, >=10.15.0." default: "latest" + atmos-version-file: + description: + Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos + ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both + `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. + required: false install-wrapper: description: Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose diff --git a/src/__tests__/setup-atmos.test.ts b/src/__tests__/setup-atmos.test.ts index 2ad9835..6e6d41c 100644 --- a/src/__tests__/setup-atmos.test.ts +++ b/src/__tests__/setup-atmos.test.ts @@ -544,6 +544,7 @@ describe("Setup Atmos", () => { .spyOn(core, "getInput") .mockReturnValueOnce("latest") .mockReturnValueOnce("") + .mockReturnValueOnce("") .mockReturnValueOnce("false") .mockReturnValueOnce(""); jest.spyOn(os, "arch").mockReturnValue("x64"); @@ -562,6 +563,7 @@ describe("Setup Atmos", () => { .spyOn(core, "getInput") .mockReturnValueOnce("latest") .mockReturnValueOnce("") + .mockReturnValueOnce("") .mockReturnValueOnce("true") .mockReturnValueOnce(""); jest.spyOn(os, "arch").mockReturnValue("x64"); @@ -576,6 +578,7 @@ describe("Setup Atmos", () => { jest .spyOn(core, "getInput") .mockReturnValueOnce("latest") + .mockReturnValueOnce("") .mockReturnValueOnce("arm64") .mockReturnValueOnce("true") .mockReturnValueOnce("enforce") diff --git a/src/__tests__/version-file.test.ts b/src/__tests__/version-file.test.ts new file mode 100644 index 0000000..4a833d0 --- /dev/null +++ b/src/__tests__/version-file.test.ts @@ -0,0 +1,61 @@ +import fs from "fs"; +import os from "os"; +import path from "path"; + +import { getVersionFromFile, parseToolVersions } from "../main"; + +describe("parseToolVersions", () => { + it("returns the atmos version from a .tool-versions file", () => { + expect(parseToolVersions("terraform 1.7.0\natmos 1.15.0\n")).toBe("1.15.0"); + }); + + it("ignores comments and blank lines", () => { + expect(parseToolVersions("# pinned tools\n\n atmos 1.13.0 \n")).toBe("1.13.0"); + }); + + it("returns an empty string when atmos is not declared", () => { + expect(parseToolVersions("terraform 1.7.0\nhelm 3.14.0\n")).toBe(""); + }); + + it("does not match a tool whose name only contains 'atmos'", () => { + expect(parseToolVersions("atmos-pro 2.0.0\n")).toBe(""); + }); +}); + +describe("getVersionFromFile", () => { + let dir: string; + + beforeEach(() => { + dir = fs.mkdtempSync(path.join(os.tmpdir(), "atmos-version-file-")); + }); + + afterEach(() => { + fs.rmSync(dir, { force: true, recursive: true }); + }); + + const write = (name: string, content: string): string => { + const filePath = path.join(dir, name); + fs.writeFileSync(filePath, content); + + return filePath; + }; + + it("reads the atmos version from a .tool-versions file", () => { + const filePath = write(".tool-versions", "atmos 1.15.0\n"); + expect(getVersionFromFile(filePath)).toBe("1.15.0"); + }); + + it("reads a plain version file as the version", () => { + const filePath = write(".atmos-version", "1.14.0\n"); + expect(getVersionFromFile(filePath)).toBe("1.14.0"); + }); + + it("throws when the file does not exist", () => { + expect(() => getVersionFromFile(path.join(dir, "missing"))).toThrow("does not exist"); + }); + + it("throws when the file is empty", () => { + const filePath = write(".tool-versions", "# only comments\n"); + expect(() => getVersionFromFile(filePath)).toThrow("No atmos version found"); + }); +}); diff --git a/src/main.ts b/src/main.ts index ce6615e..1bf8df0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,81 @@ +import fs from "fs"; import os from "os"; import * as core from "@actions/core"; import * as installer from "./installer"; +const ATMOS_TOOL_NAME = "atmos"; + +// Parses `.tool-versions` content (asdf/mise format) and returns the atmos +// version, or an empty string when none is declared. Lines look like +// `atmos 1.15.0`; comments (`#`) and blank lines are ignored. +export const parseToolVersions = (content: string): string => { + for (const line of content.split(/\r?\n/)) { + const trimmed = line.trim(); + + if (!trimmed || trimmed.startsWith("#")) { + continue; + } + + const [tool, version] = trimmed.split(/\s+/); + + if (tool === ATMOS_TOOL_NAME && version) { + return version; + } + } + + return ""; +}; + +// Returns the first non-empty, non-comment line of a plain version file +// (e.g. `.atmos-version`), or an empty string when there is none. +const parsePlainVersion = (content: string): string => { + for (const line of content.split(/\r?\n/)) { + const trimmed = line.trim(); + + if (trimmed && !trimmed.startsWith("#")) { + return trimmed; + } + } + + return ""; +}; + +// Reads an atmos version from a version file. Supports the asdf/mise +// `.tool-versions` format (an `atmos ` line) and a plain version file +// whose contents are the version string (e.g. `.atmos-version`). +export const getVersionFromFile = (filePath: string): string => { + if (!fs.existsSync(filePath)) { + throw new Error(`The atmos-version-file '${filePath}' does not exist`); + } + + const content = fs.readFileSync(filePath, "utf8"); + const version = parseToolVersions(content) || parsePlainVersion(content); + + if (!version) { + throw new Error(`No atmos version found in '${filePath}'`); + } + + return version; +}; + export const run = async () => { try { - const versionSpec = core.getInput("atmos-version"); + let versionSpec = core.getInput("atmos-version"); + const versionFile = core.getInput("atmos-version-file"); + + if (versionFile) { + if (versionSpec && versionSpec !== "latest") { + core.warning( + "Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used." + ); + } else { + versionSpec = getVersionFromFile(versionFile); + core.info(`Resolved atmos version '${versionSpec}' from '${versionFile}'`); + } + } + core.info(`Setup atmos version spec ${versionSpec}`); const arch = core.getInput("architecture") || os.arch(); From 9b9be13375952f1e82c17492f47eda96f6fe12f1 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 11:46:44 -0600 Subject: [PATCH 2/9] Address version file review and verify input precedence --- README.md | 8 ++-- README.yaml | 6 +-- action.yml | 3 +- dist/index.js | 74 +++++++++++++++++++++++++++--- src/__tests__/setup-atmos.test.ts | 21 +++++++++ src/__tests__/version-file.test.ts | 11 +++-- src/main.ts | 21 ++++++--- 7 files changed, 118 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d447c20..521508d 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,13 @@ The version can also be read from a file with the `atmos-version-file` input. Th ```yaml steps: - - uses: hashicorp/setup-terraform@v2 + - uses: actions/checkout@v4 - name: Setup atmos - uses: cloudposse/github-action-setup-atmos@v2 + uses: cloudposse/github-action-setup-atmos@v3 with: atmos-version-file: .tool-versions -```` +``` When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. @@ -133,7 +133,7 @@ steps: | Name | Description | Default | Required | |------|-------------|---------|----------| -| atmos-version | Version Spec of the version to use. Examples: 1.x, 10.15.1, >=10.15.0. | latest | false | +| atmos-version | Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0. | | false | | atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | | install-wrapper | Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | true | false | diff --git a/README.yaml b/README.yaml index e109215..3994a28 100644 --- a/README.yaml +++ b/README.yaml @@ -79,13 +79,13 @@ usage: |- ```yaml steps: - - uses: hashicorp/setup-terraform@v2 + - uses: actions/checkout@v4 - name: Setup atmos - uses: cloudposse/github-action-setup-atmos@v2 + uses: cloudposse/github-action-setup-atmos@v3 with: atmos-version-file: .tool-versions - ```` + ``` When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. diff --git a/action.yml b/action.yml index bee9e87..f40cf0b 100644 --- a/action.yml +++ b/action.yml @@ -6,8 +6,7 @@ branding: color: "blue" inputs: atmos-version: - description: "Version Spec of the version to use. Examples: 1.x, 10.15.1, >=10.15.0." - default: "latest" + description: "Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0." atmos-version-file: description: Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos diff --git a/dist/index.js b/dist/index.js index befee12..fec3526 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49015,19 +49015,20 @@ var __webpack_exports__ = {}; // ESM COMPAT FLAG __nccwpck_require__.r(__webpack_exports__); +// EXTERNAL MODULE: external "fs" +var external_fs_ = __nccwpck_require__(7147); +var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_); // EXTERNAL MODULE: external "os" var external_os_ = __nccwpck_require__(2037); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); +// EXTERNAL MODULE: external "path" +var external_path_ = __nccwpck_require__(1017); +var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js var core = __nccwpck_require__(2186); // EXTERNAL MODULE: external "crypto" var external_crypto_ = __nccwpck_require__(6113); var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto_); -// EXTERNAL MODULE: external "fs" -var external_fs_ = __nccwpck_require__(7147); -var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_); -// EXTERNAL MODULE: external "path" -var external_path_ = __nccwpck_require__(1017); // EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js var io = __nccwpck_require__(7436); // EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js @@ -49401,9 +49402,70 @@ const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), + + +const ATMOS_TOOL_NAME = "atmos"; +// Parses `.tool-versions` content (asdf/mise format) and returns the atmos +// version, or an empty string when none is declared. Lines look like +// `atmos 1.15.0`; comments (`#`) and blank lines are ignored. +const parseToolVersions = (content) => { + for (const line of content.split(/\r?\n/)) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith("#")) { + continue; + } + const [tool, version] = trimmed.split("#", 1)[0].trim().split(/\s+/); + if (tool === ATMOS_TOOL_NAME && version) { + return version; + } + } + return ""; +}; +// Returns the first non-empty, non-comment line of a plain version file +// (e.g. `.atmos-version`), or an empty string when there is none. +const parsePlainVersion = (content) => { + for (const line of content.split(/\r?\n/)) { + const trimmed = line.trim(); + if (trimmed && !trimmed.startsWith("#")) { + return trimmed; + } + } + return ""; +}; +// Reads an atmos version from a version file. Supports the asdf/mise +// `.tool-versions` format (an `atmos ` line) and a plain version file +// whose contents are the version string (e.g. `.atmos-version`). +const getVersionFromFile = (filePath) => { + let content; + try { + content = external_fs_default().readFileSync(filePath, "utf8"); + } + catch (error) { + if (error.code === "ENOENT") { + throw new Error(`The atmos-version-file '${filePath}' does not exist`); + } + throw error; + } + const version = external_path_default().basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); + if (!version) { + throw new Error(`No atmos version found in '${filePath}'`); + } + return version; +}; const run = async () => { try { - const versionSpec = core.getInput("atmos-version"); + let versionSpec = core.getInput("atmos-version"); + const versionFile = core.getInput("atmos-version-file"); + if (versionFile) { + if (versionSpec) { + core.warning("Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used."); + } + else { + versionSpec = getVersionFromFile(versionFile); + core.info(`Resolved atmos version '${versionSpec}' from '${versionFile}'`); + } + } + versionSpec ||= "latest"; core.info(`Setup atmos version spec ${versionSpec}`); const arch = core.getInput("architecture") || external_os_default().arch(); const installWrapper = core.getInput("install-wrapper") === "true"; diff --git a/src/__tests__/setup-atmos.test.ts b/src/__tests__/setup-atmos.test.ts index 6e6d41c..e1a04e9 100644 --- a/src/__tests__/setup-atmos.test.ts +++ b/src/__tests__/setup-atmos.test.ts @@ -539,6 +539,27 @@ describe("Setup Atmos", () => { }); describe("run", () => { + it.each([ + ["", ".tool-versions", "1.2.3"], + ["latest", ".tool-versions", "latest"], + ["", "", "latest"] + ])("resolves version %j with file %j to %j", async (explicit, file, expected) => { + jest.spyOn(core, "getInput").mockImplementation((name) => { + if (name === "atmos-version") return explicit; + if (name === "atmos-version-file") return file; + return ""; + }); + mockReadFileSync(() => "atmos 1.2.3"); + const install = jest + .spyOn(installer, "getAtmos") + .mockResolvedValue({ toolPath: "/cache/atmos", info: versionInfo }); + + await run(); + + expect(install.mock.calls[0][0]).toBe(expected); + if (explicit || !file) expect(fs.readFileSync).not.toHaveBeenCalled(); + }); + it("sets the resolved version output", async () => { jest .spyOn(core, "getInput") diff --git a/src/__tests__/version-file.test.ts b/src/__tests__/version-file.test.ts index 4a833d0..497a62b 100644 --- a/src/__tests__/version-file.test.ts +++ b/src/__tests__/version-file.test.ts @@ -54,8 +54,11 @@ describe("getVersionFromFile", () => { expect(() => getVersionFromFile(path.join(dir, "missing"))).toThrow("does not exist"); }); - it("throws when the file is empty", () => { - const filePath = write(".tool-versions", "# only comments\n"); - expect(() => getVersionFromFile(filePath)).toThrow("No atmos version found"); - }); + it.each(["# only comments\n", "terraform 1.7.0\n", "atmos # unpinned\n"])( + "throws when no Atmos version is declared in %j", + (content) => { + const filePath = write(".tool-versions", content); + expect(() => getVersionFromFile(filePath)).toThrow("No atmos version found"); + } + ); }); diff --git a/src/main.ts b/src/main.ts index 1bf8df0..61418b5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import fs from "fs"; import os from "os"; +import path from "path"; import * as core from "@actions/core"; @@ -18,7 +19,7 @@ export const parseToolVersions = (content: string): string => { continue; } - const [tool, version] = trimmed.split(/\s+/); + const [tool, version] = trimmed.split("#", 1)[0].trim().split(/\s+/); if (tool === ATMOS_TOOL_NAME && version) { return version; @@ -46,12 +47,17 @@ const parsePlainVersion = (content: string): string => { // `.tool-versions` format (an `atmos ` line) and a plain version file // whose contents are the version string (e.g. `.atmos-version`). export const getVersionFromFile = (filePath: string): string => { - if (!fs.existsSync(filePath)) { - throw new Error(`The atmos-version-file '${filePath}' does not exist`); + let content: string; + try { + content = fs.readFileSync(filePath, "utf8"); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === "ENOENT") { + throw new Error(`The atmos-version-file '${filePath}' does not exist`); + } + throw error; } - - const content = fs.readFileSync(filePath, "utf8"); - const version = parseToolVersions(content) || parsePlainVersion(content); + const version = + path.basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); if (!version) { throw new Error(`No atmos version found in '${filePath}'`); @@ -66,7 +72,7 @@ export const run = async () => { const versionFile = core.getInput("atmos-version-file"); if (versionFile) { - if (versionSpec && versionSpec !== "latest") { + if (versionSpec) { core.warning( "Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used." ); @@ -76,6 +82,7 @@ export const run = async () => { } } + versionSpec ||= "latest"; core.info(`Setup atmos version spec ${versionSpec}`); const arch = core.getInput("architecture") || os.arch(); From 496ede99cfe6e06118cf2c3f2263e0975f46921b Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 11:48:10 -0600 Subject: [PATCH 3/9] Add opt-in Atmos toolchain installation after setup --- README.md | 4 +++ README.yaml | 3 ++ action.yml | 4 +++ dist/index.js | 32 +++++++++++------- src/__tests__/setup-atmos.test.ts | 54 +++++++++++++++++++++++++------ src/main.ts | 9 ++++++ 6 files changed, 86 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 521508d..0297def 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,11 @@ steps: uses: cloudposse/github-action-setup-atmos@v3 with: atmos-version-file: .tool-versions + install-toolchain: true ``` +Set `install-toolchain: true` to run `atmos toolchain install` after setup. This option defaults to `false` and works independently of `atmos-version-file`. + When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: @@ -136,6 +139,7 @@ steps: | atmos-version | Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0. | | false | | atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | +| install-toolchain | Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file. | false | false | | install-wrapper | Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | true | false | | token | Used to pull atmos distributions from Cloud Posse's GitHub repository. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ${{ github.server\_url == 'https://github.com' && github.token \|\| '' }} | false | diff --git a/README.yaml b/README.yaml index 3994a28..27bf4df 100644 --- a/README.yaml +++ b/README.yaml @@ -85,8 +85,11 @@ usage: |- uses: cloudposse/github-action-setup-atmos@v3 with: atmos-version-file: .tool-versions + install-toolchain: true ``` + Set `install-toolchain: true` to run `atmos toolchain install` after setup. This option defaults to `false` and works independently of `atmos-version-file`. + When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: diff --git a/action.yml b/action.yml index f40cf0b..69861c8 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. required: false + install-toolchain: + description: "Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file." + required: false + default: "false" install-wrapper: description: Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose diff --git a/dist/index.js b/dist/index.js index fec3526..84cc87e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49015,6 +49015,8 @@ var __webpack_exports__ = {}; // ESM COMPAT FLAG __nccwpck_require__.r(__webpack_exports__); +// EXTERNAL MODULE: external "child_process" +var external_child_process_ = __nccwpck_require__(2081); // EXTERNAL MODULE: external "fs" var external_fs_ = __nccwpck_require__(7147); var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_); @@ -49026,17 +49028,6 @@ var external_path_ = __nccwpck_require__(1017); var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js var core = __nccwpck_require__(2186); -// EXTERNAL MODULE: external "crypto" -var external_crypto_ = __nccwpck_require__(6113); -var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto_); -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __nccwpck_require__(7436); -// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js -var tool_cache = __nccwpck_require__(7784); -// EXTERNAL MODULE: ./node_modules/octokit/dist-node/index.js -var dist_node = __nccwpck_require__(7467); -// EXTERNAL MODULE: ./node_modules/semver/index.js -var semver = __nccwpck_require__(1383); ;// CONCATENATED MODULE: ./src/system.ts const isWindowsPlatform = (platform) => platform.startsWith("win"); @@ -49069,6 +49060,17 @@ const getAtmosBinaryName = (wrapped = false) => { const getAtmosWrappedBinaryName = () => getAtmosBinaryName(true); const getAtmosWrappedPath = () => [process.env.ATMOS_CLI_PATH, getAtmosWrappedBinaryName()].join(sep); +// EXTERNAL MODULE: external "crypto" +var external_crypto_ = __nccwpck_require__(6113); +var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto_); +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __nccwpck_require__(7436); +// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js +var tool_cache = __nccwpck_require__(7784); +// EXTERNAL MODULE: ./node_modules/octokit/dist-node/index.js +var dist_node = __nccwpck_require__(7467); +// EXTERNAL MODULE: ./node_modules/semver/index.js +var semver = __nccwpck_require__(1383); ;// CONCATENATED MODULE: ./src/installer.ts @@ -49404,6 +49406,8 @@ const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), + + const ATMOS_TOOL_NAME = "atmos"; // Parses `.tool-versions` content (asdf/mise format) and returns the atmos // version, or an empty string when none is declared. Lines look like @@ -49474,6 +49478,12 @@ const run = async () => { const auth = !token ? undefined : `token ${token}`; const { toolPath, info } = await getAtmos(versionSpec, auth, arch, installWrapper, checksumValidation); core.info(`Successfully set up Atmos version ${versionSpec} in ${toolPath}`); + if (core.getBooleanInput("install-toolchain")) { + core.info("Running atmos toolchain install"); + (0,external_child_process_.execFileSync)(external_path_default().join(toolPath, getAtmosBinaryName(installWrapper)), ["toolchain", "install"], { + stdio: "inherit" + }); + } core.setOutput("atmos-version", info?.resolvedVersion); // eslint-disable-next-line @typescript-eslint/no-explicit-any } diff --git a/src/__tests__/setup-atmos.test.ts b/src/__tests__/setup-atmos.test.ts index e1a04e9..2b70a14 100644 --- a/src/__tests__/setup-atmos.test.ts +++ b/src/__tests__/setup-atmos.test.ts @@ -1,3 +1,4 @@ +import childProcess from "child_process"; import fs from "fs"; import os from "os"; import path from "path"; @@ -127,10 +128,10 @@ describe("Setup Atmos", () => { describe("release assets", () => { it.each` - version | expected - ${"1.10beta1"} | ${"1.10.0-beta.1"} - ${"1.10rc1"} | ${"1.10.0-rc.1"} - ${"v1.222.0-rc.1"} | ${"1.222.0-rc.1"} + version | expected + ${"1.10beta1"} | ${"1.10.0-beta.1"} + ${"1.10rc1"} | ${"1.10.0-rc.1"} + ${"v1.222.0-rc.1"} | ${"1.222.0-rc.1"} `("normalizes $version to semver", ({ version, expected }) => { expect(installer.makeSemver(version)).toEqual(expected); }); @@ -235,14 +236,13 @@ describe("Setup Atmos", () => { }); it("rejects missing checksum entries", () => { - expect(() => installer.getExpectedChecksum("", "atmos_1.222.0_linux_amd64")).toThrow( - "Unable to find checksum" - ); + expect(() => installer.getExpectedChecksum("", "atmos_1.222.0_linux_amd64")).toThrow("Unable to find checksum"); }); it("rejects invalid checksum entries", () => { - expect(() => installer.getExpectedChecksum("not-a-sha atmos_1.222.0_linux_amd64", "atmos_1.222.0_linux_amd64")) - .toThrow("Invalid SHA256 checksum"); + expect(() => + installer.getExpectedChecksum("not-a-sha atmos_1.222.0_linux_amd64", "atmos_1.222.0_linux_amd64") + ).toThrow("Invalid SHA256 checksum"); }); it("verifies a downloaded file against SHA256SUMS", () => { @@ -539,6 +539,10 @@ describe("Setup Atmos", () => { }); describe("run", () => { + beforeEach(() => { + jest.mocked(core.getBooleanInput).mockReturnValue(false); + }); + it.each([ ["", ".tool-versions", "1.2.3"], ["latest", ".tool-versions", "latest"], @@ -560,7 +564,38 @@ describe("Setup Atmos", () => { if (explicit || !file) expect(fs.readFileSync).not.toHaveBeenCalled(); }); + it.each([false, true])("runs toolchain install with wrapper=%s", async (wrapped) => { + jest.spyOn(core, "getInput").mockImplementation((name) => (name === "install-wrapper" ? String(wrapped) : "")); + jest.spyOn(core, "getBooleanInput").mockImplementation((name) => name === "install-toolchain"); + const toolPath = path.resolve("tool cache"); + jest.spyOn(installer, "getAtmos").mockResolvedValue({ toolPath, info: versionInfo }); + const execute = jest.spyOn(childProcess, "execFileSync").mockReturnValue(Buffer.alloc(0)); + + await run(); + + const name = wrapped ? "atmos-bin" : "atmos"; + expect(execute).toHaveBeenCalledWith( + path.join(toolPath, process.platform === "win32" ? name + ".exe" : name), + ["toolchain", "install"], + { stdio: "inherit" } + ); + }); + + it("fails setup if toolchain installation fails", async () => { + jest.mocked(core.getBooleanInput).mockReturnValue(true); + jest.spyOn(core, "getInput").mockReturnValue(""); + jest.spyOn(installer, "getAtmos").mockResolvedValue({ toolPath: "/cache/atmos", info: versionInfo }); + jest.spyOn(childProcess, "execFileSync").mockImplementation(() => { + throw new Error("toolchain install failed"); + }); + + await run(); + + expect(core.setFailed).toHaveBeenCalledWith("toolchain install failed"); + }); + it("sets the resolved version output", async () => { + const execute = jest.spyOn(childProcess, "execFileSync").mockReturnValue(Buffer.alloc(0)); jest .spyOn(core, "getInput") .mockReturnValueOnce("latest") @@ -576,6 +611,7 @@ describe("Setup Atmos", () => { await run(); + expect(execute).not.toHaveBeenCalled(); expect(core.setOutput).toHaveBeenCalledWith("atmos-version", "v1.222.0"); }); diff --git a/src/main.ts b/src/main.ts index 61418b5..9961163 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,11 @@ +import { execFileSync } from "child_process"; import fs from "fs"; import os from "os"; import path from "path"; import * as core from "@actions/core"; +import { getAtmosBinaryName } from "./atmos-bin"; import * as installer from "./installer"; const ATMOS_TOOL_NAME = "atmos"; @@ -96,6 +98,13 @@ export const run = async () => { core.info(`Successfully set up Atmos version ${versionSpec} in ${toolPath}`); + if (core.getBooleanInput("install-toolchain")) { + core.info("Running atmos toolchain install"); + execFileSync(path.join(toolPath, getAtmosBinaryName(installWrapper)), ["toolchain", "install"], { + stdio: "inherit" + }); + } + core.setOutput("atmos-version", info?.resolvedVersion); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { From 0447fe07ae224f7085d1f65363c861b8a22a12e9 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 11:56:27 -0600 Subject: [PATCH 4/9] Resolve the Atmos container image with install: false --- README.md | 29 ++++++++++++++++++++++++++++- README.yaml | 25 +++++++++++++++++++++++++ action.yml | 7 ++++++- dist/index.js | 23 ++++++++++++++++++----- src/__tests__/setup-atmos.test.ts | 21 +++++++++++++++++++-- src/installer.ts | 17 ++++++++++++----- src/main.ts | 13 ++++++++++++- 7 files changed, 120 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0297def..dc139ae 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,31 @@ Set `install-toolchain: true` to run `atmos toolchain install` after setup. This When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. +To select a job container from `.tool-versions`, resolve the image in a preceding job. +Setting `install: false` skips both Atmos and toolchain installation. + +```yaml +jobs: + setup: + runs-on: ubuntu-latest + outputs: + image: ${{ steps.atmos.outputs.atmos-image }} + steps: + - uses: actions/checkout@v6 + - id: atmos + uses: cloudposse/github-action-setup-atmos@v3 + with: + atmos-version-file: .tool-versions + install: false + plan: + needs: setup + runs-on: ubuntu-latest + container: + image: ${{ needs.setup.outputs.image }} + steps: + - run: atmos version +``` + The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: ```yaml @@ -139,6 +164,7 @@ steps: | atmos-version | Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0. | | false | | atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | +| install | Install Atmos on the runner. Set to false to return the version and container image and skip all installation. | true | false | | install-toolchain | Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file. | false | false | | install-wrapper | Flag to indicate if the wrapper script will be installed to wrap subsequent calls of the `atmos` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | true | false | | token | Used to pull atmos distributions from Cloud Posse's GitHub repository. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ${{ github.server\_url == 'https://github.com' && github.token \|\| '' }} | false | @@ -149,7 +175,8 @@ steps: | Name | Description | |------|-------------| -| atmos-version | The installed atmos version. | +| atmos-image | The official Atmos container image reference for the resolved version. | +| atmos-version | The resolved Atmos release version. | diff --git a/README.yaml b/README.yaml index 27bf4df..b8f579d 100644 --- a/README.yaml +++ b/README.yaml @@ -92,6 +92,31 @@ usage: |- When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. + To select a job container from `.tool-versions`, resolve the image in a preceding job. + Setting `install: false` skips both Atmos and toolchain installation. + + ```yaml + jobs: + setup: + runs-on: ubuntu-latest + outputs: + image: ${{ steps.atmos.outputs.atmos-image }} + steps: + - uses: actions/checkout@v6 + - id: atmos + uses: cloudposse/github-action-setup-atmos@v3 + with: + atmos-version-file: .tool-versions + install: false + plan: + needs: setup + runs-on: ubuntu-latest + container: + image: ${{ needs.setup.outputs.image }} + steps: + - run: atmos version + ``` + The wrapper script installation can be skipped by setting the `install-wrapper` input to `false`: ```yaml diff --git a/action.yml b/action.yml index 69861c8..c3ed691 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. required: false + install: + description: "Install Atmos on the runner. Set to false to return the version and container image and skip all installation." + default: "true" install-toolchain: description: "Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file." required: false @@ -38,8 +41,10 @@ inputs: GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. default: ${{ github.server_url == 'https://github.com' && github.token || '' }} outputs: + atmos-image: + description: "The official Atmos container image reference for the resolved version." atmos-version: - description: "The installed atmos version." + description: "The resolved Atmos release version." runs: using: "node24" main: "dist/index.js" diff --git a/dist/index.js b/dist/index.js index 84cc87e..b79c50e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49360,6 +49360,13 @@ const installAtmosVersion = async (info, auth, arch, installWrapper, checksumVal core.info(`Successfully installed atmos to ${atmosInstallPath}`); return atmosInstallPath; }; +const resolveAtmosVersion = async (versionSpec, auth, arch) => { + const info = await getMatchingVersion(versionSpec, auth, arch); + if (!info) { + throw new Error(`Unable to find atmos version '${versionSpec}' for platform ${external_os_default().platform()} and architecture ${arch}.`); + } + return info; +}; const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), installWrapper, checksumValidation = "warn") => { const osPlat = external_os_default().platform(); const toolCacheName = getToolCacheName(installWrapper); @@ -49379,10 +49386,7 @@ const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), }); } } - const info = await getMatchingVersion(versionSpec, auth, arch); - if (!info) { - throw new Error(`Unable to find atmos version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); - } + const info = await resolveAtmosVersion(versionSpec, auth, arch); const { resolvedVersion } = info; const cachedPath = tool_cache.find(toolCacheName, resolvedVersion, arch); if (cachedPath) { @@ -49456,6 +49460,10 @@ const getVersionFromFile = (filePath) => { } return version; }; +const setVersionOutputs = (version) => { + core.setOutput("atmos-version", version); + core.setOutput("atmos-image", `ghcr.io/cloudposse/atmos:${version.replace(/^v/, "")}`); +}; const run = async () => { try { let versionSpec = core.getInput("atmos-version"); @@ -49476,6 +49484,11 @@ const run = async () => { const checksumValidation = parseChecksumValidationMode(core.getInput("checksum-validation")); const token = core.getInput("token"); const auth = !token ? undefined : `token ${token}`; + if (!core.getBooleanInput("install")) { + const info = await resolveAtmosVersion(versionSpec, auth, arch); + setVersionOutputs(info.resolvedVersion); + return; + } const { toolPath, info } = await getAtmos(versionSpec, auth, arch, installWrapper, checksumValidation); core.info(`Successfully set up Atmos version ${versionSpec} in ${toolPath}`); if (core.getBooleanInput("install-toolchain")) { @@ -49484,7 +49497,7 @@ const run = async () => { stdio: "inherit" }); } - core.setOutput("atmos-version", info?.resolvedVersion); + setVersionOutputs(info.resolvedVersion); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error) { diff --git a/src/__tests__/setup-atmos.test.ts b/src/__tests__/setup-atmos.test.ts index 2b70a14..7f962a1 100644 --- a/src/__tests__/setup-atmos.test.ts +++ b/src/__tests__/setup-atmos.test.ts @@ -540,7 +540,7 @@ describe("Setup Atmos", () => { describe("run", () => { beforeEach(() => { - jest.mocked(core.getBooleanInput).mockReturnValue(false); + jest.mocked(core.getBooleanInput).mockImplementation((name) => name === "install"); }); it.each([ @@ -566,7 +566,7 @@ describe("Setup Atmos", () => { it.each([false, true])("runs toolchain install with wrapper=%s", async (wrapped) => { jest.spyOn(core, "getInput").mockImplementation((name) => (name === "install-wrapper" ? String(wrapped) : "")); - jest.spyOn(core, "getBooleanInput").mockImplementation((name) => name === "install-toolchain"); + jest.spyOn(core, "getBooleanInput").mockReturnValue(true); const toolPath = path.resolve("tool cache"); jest.spyOn(installer, "getAtmos").mockResolvedValue({ toolPath, info: versionInfo }); const execute = jest.spyOn(childProcess, "execFileSync").mockReturnValue(Buffer.alloc(0)); @@ -594,6 +594,23 @@ describe("Setup Atmos", () => { expect(core.setFailed).toHaveBeenCalledWith("toolchain install failed"); }); + it("resolves the image from .tool-versions without installing anything", async () => { + jest.mocked(core.getBooleanInput).mockImplementation((name) => name === "install-toolchain"); + jest.mocked(core.getInput).mockImplementation((name) => (name === "atmos-version-file" ? ".tool-versions" : "")); + mockReadFileSync(() => "atmos 1.222.0"); + const resolve = jest.spyOn(installer, "resolveAtmosVersion").mockResolvedValue(versionInfo); + const install = jest.spyOn(installer, "getAtmos"); + const execute = jest.spyOn(childProcess, "execFileSync"); + + await run(); + + expect(resolve).toHaveBeenCalledWith("1.222.0", undefined, os.arch()); + expect(core.setOutput).toHaveBeenCalledWith("atmos-version", "v1.222.0"); + expect(core.setOutput).toHaveBeenCalledWith("atmos-image", "ghcr.io/cloudposse/atmos:1.222.0"); + expect(install).not.toHaveBeenCalled(); + expect(execute).not.toHaveBeenCalled(); + }); + it("sets the resolved version output", async () => { const execute = jest.spyOn(childProcess, "execFileSync").mockReturnValue(Buffer.alloc(0)); jest diff --git a/src/installer.ts b/src/installer.ts index 582ae79..c535825 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -396,13 +396,23 @@ export const installAtmosVersion = async ( return atmosInstallPath; }; +export const resolveAtmosVersion = async (versionSpec: string, auth: string | undefined, arch: string) => { + const info = await getMatchingVersion(versionSpec, auth, arch); + if (!info) { + throw new Error( + `Unable to find atmos version '${versionSpec}' for platform ${os.platform()} and architecture ${arch}.` + ); + } + return info; +}; + export const getAtmos = async ( versionSpec: string, auth: string | undefined, arch: string = os.arch(), installWrapper: boolean, checksumValidation: ChecksumValidationMode = "warn" -): Promise<{ toolPath: string; info: IAtmosVersionInfo | null }> => { +): Promise<{ toolPath: string; info: IAtmosVersionInfo }> => { const osPlat: string = os.platform(); const toolCacheName = getToolCacheName(installWrapper); @@ -426,10 +436,7 @@ export const getAtmos = async ( } } - const info: IAtmosVersionInfo | null = await getMatchingVersion(versionSpec, auth, arch); - if (!info) { - throw new Error(`Unable to find atmos version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); - } + const info = await resolveAtmosVersion(versionSpec, auth, arch); const { resolvedVersion } = info; diff --git a/src/main.ts b/src/main.ts index 9961163..a322d61 100644 --- a/src/main.ts +++ b/src/main.ts @@ -68,6 +68,11 @@ export const getVersionFromFile = (filePath: string): string => { return version; }; +const setVersionOutputs = (version: string) => { + core.setOutput("atmos-version", version); + core.setOutput("atmos-image", `ghcr.io/cloudposse/atmos:${version.replace(/^v/, "")}`); +}; + export const run = async () => { try { let versionSpec = core.getInput("atmos-version"); @@ -94,6 +99,12 @@ export const run = async () => { const token = core.getInput("token"); const auth = !token ? undefined : `token ${token}`; + if (!core.getBooleanInput("install")) { + const info = await installer.resolveAtmosVersion(versionSpec, auth, arch); + setVersionOutputs(info.resolvedVersion); + return; + } + const { toolPath, info } = await installer.getAtmos(versionSpec, auth, arch, installWrapper, checksumValidation); core.info(`Successfully set up Atmos version ${versionSpec} in ${toolPath}`); @@ -105,7 +116,7 @@ export const run = async () => { }); } - core.setOutput("atmos-version", info?.resolvedVersion); + setVersionOutputs(info.resolvedVersion); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { core.setFailed(error instanceof Error ? error.message : `${error}`); From 65264a21f513f694a2b7fc42ff3b0b66f087f5a2 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 11:58:12 -0600 Subject: [PATCH 5/9] Run CI on the Node 24 action runtime --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b896c3..6234cca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-node@v6 with: - node-version-file: package.json + node-version: "24" cache: yarn - name: Install Dependencies From df3258e40012d054981ed1a4835e4be95bf58296 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 12:08:36 -0600 Subject: [PATCH 6/9] Recognize the qualified cloudposse/atmos tool name --- README.md | 4 ++-- README.yaml | 2 +- action.yml | 4 ++-- dist/index.js | 3 +-- src/__tests__/version-file.test.ts | 5 +++++ src/main.ts | 4 +--- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dc139ae..1a89c1b 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ steps: ```` The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise -`.tool-versions` format (an `atmos ` line) as well as a plain version file whose contents are the version +`.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) as well as a plain version file whose contents are the version (e.g. `.atmos-version`): ```yaml @@ -162,7 +162,7 @@ steps: | Name | Description | Default | Required | |------|-------------|---------|----------| | atmos-version | Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0. | | false | -| atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | +| atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | | install | Install Atmos on the runner. Set to false to return the version and container image and skip all installation. | true | false | | install-toolchain | Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file. | false | false | diff --git a/README.yaml b/README.yaml index b8f579d..6e02f5b 100644 --- a/README.yaml +++ b/README.yaml @@ -74,7 +74,7 @@ usage: |- ```` The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise - `.tool-versions` format (an `atmos ` line) as well as a plain version file whose contents are the version + `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) as well as a plain version file whose contents are the version (e.g. `.atmos-version`): ```yaml diff --git a/action.yml b/action.yml index c3ed691..ee3d182 100644 --- a/action.yml +++ b/action.yml @@ -9,8 +9,8 @@ inputs: description: "Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0." atmos-version-file: description: - Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (an `atmos - ` line) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both + Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (the first + version listed for `atmos` or `cloudposse/atmos`) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. required: false install: diff --git a/dist/index.js b/dist/index.js index b79c50e..a8dfa94 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49412,7 +49412,6 @@ const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), -const ATMOS_TOOL_NAME = "atmos"; // Parses `.tool-versions` content (asdf/mise format) and returns the atmos // version, or an empty string when none is declared. Lines look like // `atmos 1.15.0`; comments (`#`) and blank lines are ignored. @@ -49423,7 +49422,7 @@ const parseToolVersions = (content) => { continue; } const [tool, version] = trimmed.split("#", 1)[0].trim().split(/\s+/); - if (tool === ATMOS_TOOL_NAME && version) { + if ((tool === "atmos" || tool === "cloudposse/atmos") && version) { return version; } } diff --git a/src/__tests__/version-file.test.ts b/src/__tests__/version-file.test.ts index 497a62b..d8a37ec 100644 --- a/src/__tests__/version-file.test.ts +++ b/src/__tests__/version-file.test.ts @@ -9,6 +9,11 @@ describe("parseToolVersions", () => { expect(parseToolVersions("terraform 1.7.0\natmos 1.15.0\n")).toBe("1.15.0"); }); + it("selects the first version of the qualified Atmos tool", () => { + const content = "hashicorp/terraform 1.9.8\nother/atmos 9.0.0\ncloudposse/atmos v1.235.0 1.234.0\nhelm/helm 3.0.0"; + expect(parseToolVersions(content)).toBe("v1.235.0"); + }); + it("ignores comments and blank lines", () => { expect(parseToolVersions("# pinned tools\n\n atmos 1.13.0 \n")).toBe("1.13.0"); }); diff --git a/src/main.ts b/src/main.ts index a322d61..e823b5f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,6 @@ import * as core from "@actions/core"; import { getAtmosBinaryName } from "./atmos-bin"; import * as installer from "./installer"; -const ATMOS_TOOL_NAME = "atmos"; - // Parses `.tool-versions` content (asdf/mise format) and returns the atmos // version, or an empty string when none is declared. Lines look like // `atmos 1.15.0`; comments (`#`) and blank lines are ignored. @@ -23,7 +21,7 @@ export const parseToolVersions = (content: string): string => { const [tool, version] = trimmed.split("#", 1)[0].trim().split(/\s+/); - if (tool === ATMOS_TOOL_NAME && version) { + if ((tool === "atmos" || tool === "cloudposse/atmos") && version) { return version; } } From c1fa561234091040c4ca48f80cc51c5796932aad Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 13:00:33 -0600 Subject: [PATCH 7/9] Discover the workspace .tool-versions pin by default --- README.md | 11 ++++------- README.yaml | 7 ++----- action.yml | 4 ++-- dist/index.js | 22 ++++++++++++---------- src/__tests__/setup-atmos.test.ts | 6 +++--- src/__tests__/version-file.test.ts | 5 +++++ src/main.ts | 23 ++++++++++++----------- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 1a89c1b..93e0321 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,8 @@ steps: atmos-version: 0.15.0 ```` -The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise -`.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) as well as a plain version file whose contents are the version -(e.g. `.atmos-version`): +After checkout, setup reads the first version listed for `atmos` or `cloudposse/atmos` in the workspace’s `.tool-versions`. +If the file or Atmos entry is absent, setup uses `latest`. Set `atmos-version-file` to select another file, such as `.atmos-version`. ```yaml steps: @@ -78,7 +77,6 @@ steps: - name: Setup atmos uses: cloudposse/github-action-setup-atmos@v3 with: - atmos-version-file: .tool-versions install-toolchain: true ``` @@ -100,7 +98,6 @@ jobs: - id: atmos uses: cloudposse/github-action-setup-atmos@v3 with: - atmos-version-file: .tool-versions install: false plan: needs: setup @@ -161,8 +158,8 @@ steps: | Name | Description | Default | Required | |------|-------------|---------|----------| -| atmos-version | Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0. | | false | -| atmos-version-file | Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | +| atmos-version | Version Spec of the version to use. Defaults to the workspace .tool-versions pin, then latest. Examples: 1.x, 10.15.1, >=10.15.0. | | false | +| atmos-version-file | Optional override for the automatically discovered workspace .tool-versions file. Supports the asdf/mise `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. | | false | | checksum-validation | Controls SHA256SUMS validation. Use `warn` to validate when checksums are published and warn when they are missing, `enforce` to fail when checksums are missing, or `skip` to disable checksum validation. Checksum mismatches always fail when validation runs. | warn | false | | install | Install Atmos on the runner. Set to false to return the version and container image and skip all installation. | true | false | | install-toolchain | Run `atmos toolchain install` after setting up Atmos to install tools declared in the repository’s `.tool-versions` file. | false | false | diff --git a/README.yaml b/README.yaml index 6e02f5b..232df2f 100644 --- a/README.yaml +++ b/README.yaml @@ -73,9 +73,8 @@ usage: |- atmos-version: 0.15.0 ```` - The version can also be read from a file with the `atmos-version-file` input. This supports the asdf/mise - `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) as well as a plain version file whose contents are the version - (e.g. `.atmos-version`): + After checkout, setup reads the first version listed for `atmos` or `cloudposse/atmos` in the workspace’s `.tool-versions`. + If the file or Atmos entry is absent, setup uses `latest`. Set `atmos-version-file` to select another file, such as `.atmos-version`. ```yaml steps: @@ -84,7 +83,6 @@ usage: |- - name: Setup atmos uses: cloudposse/github-action-setup-atmos@v3 with: - atmos-version-file: .tool-versions install-toolchain: true ``` @@ -106,7 +104,6 @@ usage: |- - id: atmos uses: cloudposse/github-action-setup-atmos@v3 with: - atmos-version-file: .tool-versions install: false plan: needs: setup diff --git a/action.yml b/action.yml index ee3d182..593f0b5 100644 --- a/action.yml +++ b/action.yml @@ -6,10 +6,10 @@ branding: color: "blue" inputs: atmos-version: - description: "Version Spec of the version to use. Defaults to latest when no version file is supplied. Examples: 1.x, 10.15.1, >=10.15.0." + description: "Version Spec of the version to use. Defaults to the workspace .tool-versions pin, then latest. Examples: 1.x, 10.15.1, >=10.15.0." atmos-version-file: description: - Path to a file that declares the atmos version to use. Supports the asdf/mise `.tool-versions` format (the first + Optional override for the automatically discovered workspace .tool-versions file. Supports the asdf/mise `.tool-versions` format (the first version listed for `atmos` or `cloudposse/atmos`) and a plain version file whose contents are the version (e.g. `.atmos-version`). When both `atmos-version` and `atmos-version-file` are set, `atmos-version` takes precedence. required: false diff --git a/dist/index.js b/dist/index.js index a8dfa94..6fc053f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49442,19 +49442,21 @@ const parsePlainVersion = (content) => { // Reads an atmos version from a version file. Supports the asdf/mise // `.tool-versions` format (an `atmos ` line) and a plain version file // whose contents are the version string (e.g. `.atmos-version`). -const getVersionFromFile = (filePath) => { +const getVersionFromFile = (filePath, required = true) => { let content; try { content = external_fs_default().readFileSync(filePath, "utf8"); } catch (error) { if (error.code === "ENOENT") { + if (!required) + return ""; throw new Error(`The atmos-version-file '${filePath}' does not exist`); } throw error; } const version = external_path_default().basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); - if (!version) { + if (!version && required) { throw new Error(`No atmos version found in '${filePath}'`); } return version; @@ -49467,14 +49469,14 @@ const run = async () => { try { let versionSpec = core.getInput("atmos-version"); const versionFile = core.getInput("atmos-version-file"); - if (versionFile) { - if (versionSpec) { - core.warning("Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used."); - } - else { - versionSpec = getVersionFromFile(versionFile); - core.info(`Resolved atmos version '${versionSpec}' from '${versionFile}'`); - } + if (versionSpec && versionFile) { + core.warning("Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used."); + } + if (!versionSpec) { + const file = versionFile || external_path_default().resolve(process.env.GITHUB_WORKSPACE || ".", ".tool-versions"); + versionSpec = getVersionFromFile(file, Boolean(versionFile)); + if (versionSpec) + core.info(`Resolved atmos version '${versionSpec}' from '${file}'`); } versionSpec ||= "latest"; core.info(`Setup atmos version spec ${versionSpec}`); diff --git a/src/__tests__/setup-atmos.test.ts b/src/__tests__/setup-atmos.test.ts index 7f962a1..6c795b2 100644 --- a/src/__tests__/setup-atmos.test.ts +++ b/src/__tests__/setup-atmos.test.ts @@ -546,7 +546,7 @@ describe("Setup Atmos", () => { it.each([ ["", ".tool-versions", "1.2.3"], ["latest", ".tool-versions", "latest"], - ["", "", "latest"] + ["", "", "1.2.3"] ])("resolves version %j with file %j to %j", async (explicit, file, expected) => { jest.spyOn(core, "getInput").mockImplementation((name) => { if (name === "atmos-version") return explicit; @@ -561,7 +561,7 @@ describe("Setup Atmos", () => { await run(); expect(install.mock.calls[0][0]).toBe(expected); - if (explicit || !file) expect(fs.readFileSync).not.toHaveBeenCalled(); + if (explicit) expect(fs.readFileSync).not.toHaveBeenCalled(); }); it.each([false, true])("runs toolchain install with wrapper=%s", async (wrapped) => { @@ -596,7 +596,7 @@ describe("Setup Atmos", () => { it("resolves the image from .tool-versions without installing anything", async () => { jest.mocked(core.getBooleanInput).mockImplementation((name) => name === "install-toolchain"); - jest.mocked(core.getInput).mockImplementation((name) => (name === "atmos-version-file" ? ".tool-versions" : "")); + jest.mocked(core.getInput).mockReturnValue(""); mockReadFileSync(() => "atmos 1.222.0"); const resolve = jest.spyOn(installer, "resolveAtmosVersion").mockResolvedValue(versionInfo); const install = jest.spyOn(installer, "getAtmos"); diff --git a/src/__tests__/version-file.test.ts b/src/__tests__/version-file.test.ts index d8a37ec..3564c00 100644 --- a/src/__tests__/version-file.test.ts +++ b/src/__tests__/version-file.test.ts @@ -55,6 +55,11 @@ describe("getVersionFromFile", () => { expect(getVersionFromFile(filePath)).toBe("1.14.0"); }); + it("falls back when the discovered file is missing or contains only other tools", () => { + expect(getVersionFromFile(path.join(dir, ".tool-versions"), false)).toBe(""); + expect(getVersionFromFile(write(".tool-versions", "terraform 1.7.0"), false)).toBe(""); + }); + it("throws when the file does not exist", () => { expect(() => getVersionFromFile(path.join(dir, "missing"))).toThrow("does not exist"); }); diff --git a/src/main.ts b/src/main.ts index e823b5f..46e6be6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,12 +46,13 @@ const parsePlainVersion = (content: string): string => { // Reads an atmos version from a version file. Supports the asdf/mise // `.tool-versions` format (an `atmos ` line) and a plain version file // whose contents are the version string (e.g. `.atmos-version`). -export const getVersionFromFile = (filePath: string): string => { +export const getVersionFromFile = (filePath: string, required = true): string => { let content: string; try { content = fs.readFileSync(filePath, "utf8"); } catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") { + if (!required) return ""; throw new Error(`The atmos-version-file '${filePath}' does not exist`); } throw error; @@ -59,7 +60,7 @@ export const getVersionFromFile = (filePath: string): string => { const version = path.basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); - if (!version) { + if (!version && required) { throw new Error(`No atmos version found in '${filePath}'`); } @@ -76,15 +77,15 @@ export const run = async () => { let versionSpec = core.getInput("atmos-version"); const versionFile = core.getInput("atmos-version-file"); - if (versionFile) { - if (versionSpec) { - core.warning( - "Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used." - ); - } else { - versionSpec = getVersionFromFile(versionFile); - core.info(`Resolved atmos version '${versionSpec}' from '${versionFile}'`); - } + if (versionSpec && versionFile) { + core.warning( + "Both 'atmos-version' and 'atmos-version-file' inputs are specified, only 'atmos-version' will be used." + ); + } + if (!versionSpec) { + const file = versionFile || path.resolve(process.env.GITHUB_WORKSPACE || ".", ".tool-versions"); + versionSpec = getVersionFromFile(file, Boolean(versionFile)); + if (versionSpec) core.info(`Resolved atmos version '${versionSpec}' from '${file}'`); } versionSpec ||= "latest"; From fde6408763047b4fe1c552d75af850fd8e19ce39 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 14:50:35 -0600 Subject: [PATCH 8/9] Read Atmos pins from renamed tool manifests --- dist/index.js | 12 ++++++++---- src/__tests__/version-file.test.ts | 13 +++++++++++++ src/main.ts | 9 ++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6fc053f..6dae365 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49028,6 +49028,8 @@ var external_path_ = __nccwpck_require__(1017); var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js var core = __nccwpck_require__(2186); +// EXTERNAL MODULE: ./node_modules/semver/index.js +var semver = __nccwpck_require__(1383); ;// CONCATENATED MODULE: ./src/system.ts const isWindowsPlatform = (platform) => platform.startsWith("win"); @@ -49069,8 +49071,6 @@ var io = __nccwpck_require__(7436); var tool_cache = __nccwpck_require__(7784); // EXTERNAL MODULE: ./node_modules/octokit/dist-node/index.js var dist_node = __nccwpck_require__(7467); -// EXTERNAL MODULE: ./node_modules/semver/index.js -var semver = __nccwpck_require__(1383); ;// CONCATENATED MODULE: ./src/installer.ts @@ -49412,6 +49412,7 @@ const getAtmos = async (versionSpec, auth, arch = external_os_default().arch(), + // Parses `.tool-versions` content (asdf/mise format) and returns the atmos // version, or an empty string when none is declared. Lines look like // `atmos 1.15.0`; comments (`#`) and blank lines are ignored. @@ -49434,7 +49435,7 @@ const parsePlainVersion = (content) => { for (const line of content.split(/\r?\n/)) { const trimmed = line.trim(); if (trimmed && !trimmed.startsWith("#")) { - return trimmed; + return trimmed === "latest" || semver.validRange(trimmed) ? trimmed : ""; } } return ""; @@ -49455,7 +49456,10 @@ const getVersionFromFile = (filePath, required = true) => { } throw error; } - const version = external_path_default().basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); + let version = parseToolVersions(content); + if (!version && external_path_default().basename(filePath) !== ".tool-versions") { + version = parsePlainVersion(content); + } if (!version && required) { throw new Error(`No atmos version found in '${filePath}'`); } diff --git a/src/__tests__/version-file.test.ts b/src/__tests__/version-file.test.ts index 3564c00..35ce829 100644 --- a/src/__tests__/version-file.test.ts +++ b/src/__tests__/version-file.test.ts @@ -50,6 +50,19 @@ describe("getVersionFromFile", () => { expect(getVersionFromFile(filePath)).toBe("1.15.0"); }); + it("reads the Atmos entry from a renamed tool manifest", () => { + const file = write(".tool-versions.ci", "terraform 1.7.0\ncloudposse/atmos v1.222.0 1.221.0"); + expect(getVersionFromFile(file)).toBe("v1.222.0"); + }); + + it("rejects a renamed manifest containing only other tools", () => { + expect(() => getVersionFromFile(write("ci.versions", "terraform 1.7.0"))).toThrow("No atmos version found"); + }); + + it.each(["latest", ">=1.2.0 <2"])("preserves the plain version selector %s", (spec) => { + expect(getVersionFromFile(write("ci.version", spec))).toBe(spec); + }); + it("reads a plain version file as the version", () => { const filePath = write(".atmos-version", "1.14.0\n"); expect(getVersionFromFile(filePath)).toBe("1.14.0"); diff --git a/src/main.ts b/src/main.ts index 46e6be6..aaeb715 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import os from "os"; import path from "path"; import * as core from "@actions/core"; +import * as semver from "semver"; import { getAtmosBinaryName } from "./atmos-bin"; import * as installer from "./installer"; @@ -36,7 +37,7 @@ const parsePlainVersion = (content: string): string => { const trimmed = line.trim(); if (trimmed && !trimmed.startsWith("#")) { - return trimmed; + return trimmed === "latest" || semver.validRange(trimmed) ? trimmed : ""; } } @@ -57,8 +58,10 @@ export const getVersionFromFile = (filePath: string, required = true): string => } throw error; } - const version = - path.basename(filePath) === ".tool-versions" ? parseToolVersions(content) : parsePlainVersion(content); + let version = parseToolVersions(content); + if (!version && path.basename(filePath) !== ".tool-versions") { + version = parsePlainVersion(content); + } if (!version && required) { throw new Error(`No atmos version found in '${filePath}'`); From 1295d51dcacd8303618cc23618b215f89259b6e3 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Mon, 30 Nov 2026 19:34:57 -0600 Subject: [PATCH 9/9] Enable CodeRabbit automatic approvals for this repository --- .coderabbit.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .coderabbit.yaml diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..5c881dd --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,5 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json +inheritance: true +reviews: + auto_approvals: + enabled: true