From bde155d847f6e80844766a6cb18948f2f958c013 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Wed, 18 Sep 2024 11:56:02 +0000 Subject: [PATCH] chore: adopt swiftorg metadata contract changes --- .github/workflows/main.yml | 46 +++++++++++++++++++++++++++++++++++++- dist/index.js | 5 ++++- src/installer/base.ts | 3 +++ src/platform/versioned.ts | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f34dcd..bb99481 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -160,7 +160,7 @@ jobs: swift: '5.0.0' development: false - os: macos-13 - swift: 'latest' + swift: '5.9' development: false - os: windows-latest swift: '5.9' @@ -216,6 +216,50 @@ jobs: if: runner.os == 'Windows' run: which link | grep "Microsoft Visual Studio" || exit 1 + - name: Get cached installation + id: get-tool + if: failure() + uses: actions/github-script@v7 + with: + script: | + const os = require('os'); + const fs = require('fs/promises'); + const toolCache = require('@actions/tool-cache'); + let arch = ''; + switch (os.arch()) { + case 'x64': + arch = 'x86_64'; + break; + case 'arm64': + arch = 'aarch64'; + break; + default: + arch = os.arch(); + break; + } + const key = process.env['SWIFT_SETUP_TOOL_KEY']; + if (!key) { + core.debug(`Toolcache not set`); + return; + } + const tools = toolCache.findAllVersions(key, arch); + if (!tools.length) { + core.debug(`No tools found for "${key}" with arch ${arch}`); + return; + } else { + core.debug(`Found tools "${tools.join(', ')}" for "${key}" with arch ${arch}`); + } + const tool = tools[0]; + await fs.access(tool); + return { key: key, tool: tool }; + + - name: Upload cached installation as artifact + if: always() && steps.get-tool.outputs.result != '' + uses: actions/upload-artifact@v4 + with: + name: ${{ fromJson(steps.get-tool.outputs.result).key }}-tool + path: ${{ fromJson(steps.get-tool.outputs.result).tool }} + dry-run: name: Check action with dry run if: needs.ci.outputs.run == 'true' diff --git a/dist/index.js b/dist/index.js index 799722e..11c7e07 100644 --- a/dist/index.js +++ b/dist/index.js @@ -142,6 +142,9 @@ class ToolchainInstaller { } if (tool && version) { tool = yield toolCache.cacheDir(tool, key, version, arch); + if (core.isDebug()) { + core.exportVariable('SWIFT_SETUP_TOOL_KEY', key); + } core.debug(`Added to tool cache at "${tool}"`); } if (tool && @@ -1687,7 +1690,7 @@ class VersionedPlatform extends base_1.Platform { const pName = (_a = platform.dir) !== null && _a !== void 0 ? _a : platform.name.replaceAll(/\s+|\./g, '').toLowerCase(); const pDownloadName = (_b = platform.dir) !== null && _b !== void 0 ? _b : platform.name.replaceAll(/\s+/g, '').toLowerCase(); const download = `${release.tag}-${pDownloadName}${this.archSuffix}.${this.downloadExtension}`; - return platform.archs.includes(this.arch) + return platform.archs && platform.archs.includes(this.arch) ? { name: platform.name, date: release.date, diff --git a/src/installer/base.ts b/src/installer/base.ts index 972c47e..cabf60a 100644 --- a/src/installer/base.ts +++ b/src/installer/base.ts @@ -71,6 +71,9 @@ export abstract class ToolchainInstaller { if (tool && version) { tool = await toolCache.cacheDir(tool, key, version, arch) + if (core.isDebug()) { + core.exportVariable('SWIFT_SETUP_TOOL_KEY', key) + } core.debug(`Added to tool cache at "${tool}"`) } if ( diff --git a/src/platform/versioned.ts b/src/platform/versioned.ts index 212722c..06128d4 100644 --- a/src/platform/versioned.ts +++ b/src/platform/versioned.ts @@ -109,7 +109,7 @@ export abstract class VersionedPlatform< const pDownloadName = platform.dir ?? platform.name.replaceAll(/\s+/g, '').toLowerCase() const download = `${release.tag}-${pDownloadName}${this.archSuffix}.${this.downloadExtension}` - return platform.archs.includes(this.arch) + return platform.archs && platform.archs.includes(this.arch) ? ({ name: platform.name, date: release.date,