Skip to content

Commit

Permalink
feat: added fallback windows installation without caching support (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyamahunt authored Apr 4, 2024
1 parent dc93ecd commit 7030849
Show file tree
Hide file tree
Showing 18 changed files with 476 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"extends": ["plugin:github/recommended","plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
Expand Down
2 changes: 1 addition & 1 deletion .github/utils/update_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ exports.fetch = async () => {
let checkoutData;
if (process.env.SETUPSWIFT_SWIFTORG_METADATA) {
checkoutData = JSON.parse(process.env.SETUPSWIFT_SWIFTORG_METADATA);
}
}
if (!checkoutData || !checkoutData.commit) {
checkoutData = await this.currentData();
}
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ jobs:
if: needs.ci.outputs.run == 'true'
needs: ci
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.os == 'windows-latest' && matrix.swift == 'latest' }}
concurrency:
group: integration-test-${{ github.ref }}-${{ matrix.os }}-${{ matrix.swift }}-${{ matrix.development }}
cancel-in-progress: true
Expand All @@ -172,7 +171,6 @@ jobs:
- os: ubuntu-22.04
swift: ${{ fromJSON(vars.SETUPSWIFT_CUSTOM_TOOLCHAINS).ubuntu2204 }}
development: true
noverify: true

steps:
- name: Checkout repository
Expand Down Expand Up @@ -205,11 +203,10 @@ jobs:
cache-snapshot: ${{ !matrix.development }}

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

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

dry-run:
Expand Down Expand Up @@ -263,7 +260,6 @@ jobs:
if: needs.ci.outputs.run == 'true'
needs: ci
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.os == 'windows-latest' }}
concurrency:
group: e2e-test-${{ github.ref }}-${{ matrix.os }}
cancel-in-progress: true
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
[GitHub Action](https://github.com/features/actions) that will setup [Swift](https://swift.org) environment with specified version.
This action supports the following functionalities:

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

## Latest supported toolchains
Expand Down Expand Up @@ -105,7 +105,7 @@ In other words specifying...
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
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

> [!IMPORTANT]
> [!IMPORTANT]
> 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.
</details>

Expand Down
32 changes: 31 additions & 1 deletion __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ describe('windows toolchain installation verification', () => {
await expect(installer['unpack'](exe)).resolves.toBe(toolPath)
})

it('tests unpack for failed path matching', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
const exe = path.resolve('tool', 'downloaded', 'toolchain.exe')
process.env.SystemDrive = 'C:'
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest
.spyOn(exec, 'getExecOutput')
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
.mockResolvedValueOnce({exitCode: 0, stdout: '{"PATH":"a"}', stderr: ''})
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
.mockResolvedValue({
exitCode: 0,
stdout: `{"SDKROOT":"root","PATH":"a${path.delimiter}b${path.delimiter}c"}`,
stderr: ''
})
jest
.spyOn(fs, 'access')
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValue()
jest.spyOn(fs, 'cp').mockRejectedValue(new Error())
const addPathSpy = jest.spyOn(core, 'addPath')
const exportVariableSpy = jest.spyOn(core, 'exportVariable')
await expect(installer['unpack'](exe)).resolves.toBe('')
expect(addPathSpy).toHaveBeenCalledTimes(2)
expect(exportVariableSpy).toHaveBeenCalledTimes(1)
expect(addPathSpy.mock.calls).toStrictEqual([['b'], ['c']])
expect(exportVariableSpy.mock.calls).toStrictEqual([['SDKROOT', 'root']])
})

it('tests add to PATH', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
const installation = path.resolve('tool', 'installed', 'path')
Expand Down Expand Up @@ -188,7 +218,7 @@ describe('windows toolchain installation verification', () => {
const setupSpy = jest
.spyOn(VisualStudio, 'setup')
.mockResolvedValue(visualStudio)
jest.spyOn(fs, 'access').mockImplementation(p => {
jest.spyOn(fs, 'access').mockImplementation(async p => {
if (
typeof p === 'string' &&
(p.startsWith(path.join(cached, 'Developer')) ||
Expand Down
Loading

0 comments on commit 7030849

Please sign in to comment.