Skip to content

Commit 7030849

Browse files
authored
feat: added fallback windows installation without caching support (#276)
1 parent dc93ecd commit 7030849

File tree

18 files changed

+476
-189
lines changed

18 files changed

+476
-189
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"plugins": ["jest", "@typescript-eslint"],
3-
"extends": ["plugin:github/recommended"],
3+
"extends": ["plugin:github/recommended","plugin:@typescript-eslint/recommended"],
44
"parser": "@typescript-eslint/parser",
55
"parserOptions": {
66
"ecmaVersion": 9,

.github/utils/update_metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exports.fetch = async () => {
111111
let checkoutData;
112112
if (process.env.SETUPSWIFT_SWIFTORG_METADATA) {
113113
checkoutData = JSON.parse(process.env.SETUPSWIFT_SWIFTORG_METADATA);
114-
}
114+
}
115115
if (!checkoutData || !checkoutData.commit) {
116116
checkoutData = await this.currentData();
117117
}

.github/workflows/main.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ jobs:
145145
if: needs.ci.outputs.run == 'true'
146146
needs: ci
147147
runs-on: ${{ matrix.os }}
148-
continue-on-error: ${{ matrix.os == 'windows-latest' && matrix.swift == 'latest' }}
149148
concurrency:
150149
group: integration-test-${{ github.ref }}-${{ matrix.os }}-${{ matrix.swift }}-${{ matrix.development }}
151150
cancel-in-progress: true
@@ -172,7 +171,6 @@ jobs:
172171
- os: ubuntu-22.04
173172
swift: ${{ fromJSON(vars.SETUPSWIFT_CUSTOM_TOOLCHAINS).ubuntu2204 }}
174173
development: true
175-
noverify: true
176174

177175
steps:
178176
- name: Checkout repository
@@ -205,11 +203,10 @@ jobs:
205203
cache-snapshot: ${{ !matrix.development }}
206204

207205
- name: Verify Swift version in macos
208-
if: runner.os == 'macOS' && matrix.noverify != 'true'
206+
if: runner.os == 'macOS'
209207
run: xcrun --toolchain ${{ env.TOOLCHAINS || '""' }} swift --version | grep ${{ steps.setup-swift.outputs.swift-version }} || exit 1
210208

211209
- name: Verify Swift version
212-
if: matrix.noverify != 'true'
213210
run: swift --version | grep ${{ steps.setup-swift.outputs.swift-version }} || exit 1
214211

215212
dry-run:
@@ -263,7 +260,6 @@ jobs:
263260
if: needs.ci.outputs.run == 'true'
264261
needs: ci
265262
runs-on: ${{ matrix.os }}
266-
continue-on-error: ${{ matrix.os == 'windows-latest' }}
267263
concurrency:
268264
group: e2e-test-${{ github.ref }}-${{ matrix.os }}
269265
cancel-in-progress: true

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
[GitHub Action](https://github.com/features/actions) that will setup [Swift](https://swift.org) environment with specified version.
1111
This action supports the following functionalities:
1212

13-
- Works on Linux, macOS and Windows(Swift 5.10 and after not supported on Windows).
13+
- Works on Linux, macOS and Windows.
1414
- Supports [installing latest major/minor/patch](#specifying-version).
1515
- Provides snapshots as soon as published in `swift.org`.
1616
- Verifies toolchain snapshots before installation (`gpg` for Linux and Windows, `pkgutil` for macOS) .
1717
- Allows development snapshots by enabling `development` flag and optional version.
1818
- Prefers existing Xcode installations.
19-
- Caches installed setup in tool cache.
19+
- Caches installed setup in tool cache and actions cache(Swift 5.10 and after does not support caching on Windows).
2020
- Allows fetching snapshot metadata without installation (can be used to setup docker images).
2121

2222
## Latest supported toolchains
@@ -105,7 +105,7 @@ In other words specifying...
105105
i.e. for `macOS`: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10-SNAPSHOT-2024-03-30-a/swift-wasm-5.10-SNAPSHOT-2024-03-30-a-macos_x86_64.pkg
106106
for `Linux`: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10-SNAPSHOT-2024-03-30-a/swift-wasm-5.10-SNAPSHOT-2024-03-30-a-ubuntu22.04_x86_64.tar.gz
107107

108-
> [!IMPORTANT]
108+
> [!IMPORTANT]
109109
> When using custom toolchains, please ensure that the toolchain can be installed and used on the GitHub runner, this action won't be able to validate this for custom toolchains.
110110
</details>
111111

__tests__/installer/windows.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,36 @@ describe('windows toolchain installation verification', () => {
126126
await expect(installer['unpack'](exe)).resolves.toBe(toolPath)
127127
})
128128

129+
it('tests unpack for failed path matching', async () => {
130+
const installer = new WindowsToolchainInstaller(toolchain)
131+
const exe = path.resolve('tool', 'downloaded', 'toolchain.exe')
132+
process.env.SystemDrive = 'C:'
133+
jest.spyOn(exec, 'exec').mockResolvedValue(0)
134+
jest
135+
.spyOn(exec, 'getExecOutput')
136+
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
137+
.mockResolvedValueOnce({exitCode: 0, stdout: '{"PATH":"a"}', stderr: ''})
138+
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
139+
.mockResolvedValue({
140+
exitCode: 0,
141+
stdout: `{"SDKROOT":"root","PATH":"a${path.delimiter}b${path.delimiter}c"}`,
142+
stderr: ''
143+
})
144+
jest
145+
.spyOn(fs, 'access')
146+
.mockRejectedValueOnce(new Error())
147+
.mockRejectedValueOnce(new Error())
148+
.mockResolvedValue()
149+
jest.spyOn(fs, 'cp').mockRejectedValue(new Error())
150+
const addPathSpy = jest.spyOn(core, 'addPath')
151+
const exportVariableSpy = jest.spyOn(core, 'exportVariable')
152+
await expect(installer['unpack'](exe)).resolves.toBe('')
153+
expect(addPathSpy).toHaveBeenCalledTimes(2)
154+
expect(exportVariableSpy).toHaveBeenCalledTimes(1)
155+
expect(addPathSpy.mock.calls).toStrictEqual([['b'], ['c']])
156+
expect(exportVariableSpy.mock.calls).toStrictEqual([['SDKROOT', 'root']])
157+
})
158+
129159
it('tests add to PATH', async () => {
130160
const installer = new WindowsToolchainInstaller(toolchain)
131161
const installation = path.resolve('tool', 'installed', 'path')
@@ -188,7 +218,7 @@ describe('windows toolchain installation verification', () => {
188218
const setupSpy = jest
189219
.spyOn(VisualStudio, 'setup')
190220
.mockResolvedValue(visualStudio)
191-
jest.spyOn(fs, 'access').mockImplementation(p => {
221+
jest.spyOn(fs, 'access').mockImplementation(async p => {
192222
if (
193223
typeof p === 'string' &&
194224
(p.startsWith(path.join(cached, 'Developer')) ||

0 commit comments

Comments
 (0)