diff --git a/.github/linters/.eslintrc.yml b/.github/linters/.eslintrc.yml index 9e95e33..f395c5d 100644 --- a/.github/linters/.eslintrc.yml +++ b/.github/linters/.eslintrc.yml @@ -42,6 +42,7 @@ rules: 'i18n-text/no-en': 'off', 'import/no-namespace': 'off', 'no-console': 'off', + 'no-shadow': 'off', 'no-unused-vars': 'off', 'prettier/prettier': 'error', 'semi': 'off', @@ -63,6 +64,7 @@ rules: '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-assertion': 'warn', '@typescript-eslint/no-require-imports': 'error', + '@typescript-eslint/no-shadow': 'error', '@typescript-eslint/no-unnecessary-qualifier': 'error', '@typescript-eslint/no-unnecessary-type-assertion': 'error', '@typescript-eslint/no-unused-vars': 'error', diff --git a/.github/workflows/Check-Version.ps1 b/.github/workflows/Check-Version.ps1 new file mode 100644 index 0000000..d3c489a --- /dev/null +++ b/.github/workflows/Check-Version.ps1 @@ -0,0 +1,12 @@ +if($args.count -ne 1) { + Write-Host "This command requires 1 arg with the version to check" + exit 1 +} + +$result = pkl.exe --version | Select-String -Pattern $args[0] -Quiet + +if($result -eq "True") { + exit 0 +} else { + exit 1 +} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebcc250..19250e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,9 @@ on: permissions: contents: read +env: + CHECK_VERSION: 0.26.0 + jobs: test-typescript: name: TypeScript Tests @@ -60,7 +63,12 @@ jobs: id: test-action uses: ./ with: - pkl-version: 0.26.0 + pkl-version: ${{ env.CHECK_VERSION }} + + - name: Confirm download (unix) + run: pkl --version | grep "Pkl ${{ env.CHECK_VERSION }}" + if: matrix.os != 'windows-latest' - - name: Confirm download - run: pkl --version + - name: Confirm download (windows) + run: .github/workflows/Check-Version.ps1 "Pkl ${{ env.CHECK_VERSION }}" + if: matrix.os == 'windows-latest' diff --git a/dist/index.js b/dist/index.js index 6a127be..c5313e2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28595,15 +28595,12 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = run; const core = __importStar(__nccwpck_require__(2186)); const tc = __importStar(__nccwpck_require__(7784)); -const node_os_1 = __importDefault(__nccwpck_require__(612)); const promises_1 = __nccwpck_require__(3292); +const platform_1 = __nccwpck_require__(2999); /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. @@ -28618,8 +28615,8 @@ async function run() { core.debug(`Found cached Pkl version at ${cachedPath}`); } else { - const assetName = findAssetName(); - const downloadUrl = `https://github.com/apple/pkl/releases/download/${pklVersion}/${assetName}`; + const platformInfo = (0, platform_1.determinePlatformInfo)(); + const downloadUrl = `https://github.com/apple/pkl/releases/download/${pklVersion}/${platformInfo.githubSourceAssetName}`; core.debug(`Download URL: ${downloadUrl}`); // Download the PKL binary const pklBinaryPath = await tc.downloadTool(downloadUrl); @@ -28629,7 +28626,7 @@ async function run() { await (0, promises_1.chmod)(pklBinaryPath, permissionsMode); core.debug(`Set executable permissions on: ${pklBinaryPath}`); // Cache the downloaded file - cachedPath = await tc.cacheFile(pklBinaryPath, 'pkl', 'pkl', pklVersion); + cachedPath = await tc.cacheFile(pklBinaryPath, platformInfo.targetFileName, 'pkl', pklVersion); core.debug(`Cached PKL binary to: ${cachedPath}`); } core.addPath(cachedPath); @@ -28641,25 +28638,64 @@ async function run() { core.setFailed(error.message); } } -function findAssetName() { - const op = node_os_1.default.platform(); - const arch = node_os_1.default.arch(); - core.info(`Try to find asset name for: ${op}-${arch}`); - switch (op) { + + +/***/ }), + +/***/ 2999: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.determinePlatformInfo = determinePlatformInfo; +const node_os_1 = __importDefault(__nccwpck_require__(612)); +function determinePlatformInfo() { + const plat = determineOS(); + const arch = determineArch(); + return { + githubSourceAssetName: determineGithubAsset(plat, arch), + targetFileName: determineTargetFileName(plat) + }; +} +function determineOS() { + switch (node_os_1.default.platform()) { case 'linux': - return 'pkl-linux-amd64'; + return 'linux'; case 'darwin': - switch (arch) { - case 'x64': - return 'pkl-macos-amd64'; - case 'arm64': - return 'pkl-macos-aarch64'; - } - break; + return 'macos'; case 'win32': - return 'pkl-windows-amd64.exe'; + return 'windows'; + default: + throw new Error('Unsupported platform'); + } +} +function determineArch() { + switch (node_os_1.default.arch()) { + case 'arm64': + return 'aarch64'; + case 'x64': + return 'amd64'; + default: + throw new Error('Unsupported architecture'); + } +} +function determineGithubAsset(plat, arch) { + if (plat === 'windows') { + return `pkl-windows-${arch}.exe`; + } + return `pkl-${plat}-${arch}`; +} +function determineTargetFileName(plat) { + switch (plat) { + case 'windows': + return 'pkl.exe'; + default: + return 'pkl'; } - throw new Error(`Couldn't find asset name for ${op}-${arch}`); } diff --git a/package-lock.json b/package-lock.json index dda59e6..94aef7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "setup-pkl", - "version": "0.0.1", + "version": "0.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "setup-pkl", - "version": "0.0.1", + "version": "0.0.6", "license": "Apache-2.0", "dependencies": { "@actions/core": "^1.10.1", diff --git a/src/main.ts b/src/main.ts index 630af71..9a1cc9c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core' import * as tc from '@actions/tool-cache' -import os from 'node:os' import { chmod } from 'fs/promises' +import { determinePlatformInfo } from './platform' /** * The main function for the action. @@ -17,8 +17,8 @@ export async function run(): Promise { if (cachedPath) { core.debug(`Found cached Pkl version at ${cachedPath}`) } else { - const assetName = findAssetName() - const downloadUrl = `https://github.com/apple/pkl/releases/download/${pklVersion}/${assetName}` + const platformInfo = determinePlatformInfo() + const downloadUrl = `https://github.com/apple/pkl/releases/download/${pklVersion}/${platformInfo.githubSourceAssetName}` core.debug(`Download URL: ${downloadUrl}`) @@ -32,7 +32,12 @@ export async function run(): Promise { core.debug(`Set executable permissions on: ${pklBinaryPath}`) // Cache the downloaded file - cachedPath = await tc.cacheFile(pklBinaryPath, 'pkl', 'pkl', pklVersion) + cachedPath = await tc.cacheFile( + pklBinaryPath, + platformInfo.targetFileName, + 'pkl', + pklVersion + ) core.debug(`Cached PKL binary to: ${cachedPath}`) } @@ -43,26 +48,3 @@ export async function run(): Promise { if (error instanceof Error) core.setFailed(error.message) } } - -function findAssetName(): string { - const op = os.platform() - const arch = os.arch() - - core.info(`Try to find asset name for: ${op}-${arch}`) - switch (op) { - case 'linux': - return 'pkl-linux-amd64' - case 'darwin': - switch (arch) { - case 'x64': - return 'pkl-macos-amd64' - case 'arm64': - return 'pkl-macos-aarch64' - } - break - case 'win32': - return 'pkl-windows-amd64.exe' - } - - throw new Error(`Couldn't find asset name for ${op}-${arch}`) -} diff --git a/src/platform.ts b/src/platform.ts new file mode 100644 index 0000000..241f7c1 --- /dev/null +++ b/src/platform.ts @@ -0,0 +1,60 @@ +import os from 'node:os' + +type Platform = 'linux' | 'macos' | 'windows' +type Architecture = 'amd64' | 'aarch64' + +type PlatformInfo = { + githubSourceAssetName: string + targetFileName: string +} + +export function determinePlatformInfo(): PlatformInfo { + const plat = determineOS() + const arch = determineArch() + + return { + githubSourceAssetName: determineGithubAsset(plat, arch), + targetFileName: determineTargetFileName(plat) + } +} + +function determineOS(): Platform { + switch (os.platform()) { + case 'linux': + return 'linux' + case 'darwin': + return 'macos' + case 'win32': + return 'windows' + default: + throw new Error('Unsupported platform') + } +} + +function determineArch(): Architecture { + switch (os.arch()) { + case 'arm64': + return 'aarch64' + case 'x64': + return 'amd64' + default: + throw new Error('Unsupported architecture') + } +} + +function determineGithubAsset(plat: Platform, arch: Architecture): string { + if (plat === 'windows') { + return `pkl-windows-${arch}.exe` + } + + return `pkl-${plat}-${arch}` +} + +function determineTargetFileName(plat: Platform): string { + switch (plat) { + case 'windows': + return 'pkl.exe' + default: + return 'pkl' + } +}