Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed swift package build failure on windows #23

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,22 @@ jobs:
state: 'closed'
});

feature-test:
name: Run ${{ github.event.pull_request.head.repo.full_name || github.repository }}@${{ github.head_ref || github.ref_name }} with latest Swift on ${{ matrix.os }}
if: always() && (needs.dependabot.result == 'success' || needs.dependabot.result == 'skipped')
e2e-test:
name: End-to-end test latest Swift on ${{ matrix.os }}
if: |
always() &&
(needs.ci.result == 'success' || needs.ci.result == 'skipped') &&
(needs.dependabot.result == 'success' || needs.dependabot.result == 'skipped')
needs: [ci, dependabot]
runs-on: ${{ matrix.os }}
concurrency:
group: feature-test-${{ github.ref }}-${{ matrix.os }}
group: e2e-test-${{ github.ref }}-${{ matrix.os }}
cancel-in-progress: ${{ needs.ci.outputs.run == 'true' }}
env:
COMPOSITE: ./.ref-download-test
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Setup wrapper composite action at ${{ env.COMPOSITE }}
if: needs.ci.outputs.run == 'true'
Expand Down Expand Up @@ -407,10 +410,17 @@ jobs:
if: needs.ci.outputs.run == 'true'
run: swift --version | grep ${{ steps.setup-swift.outputs.swift-version }} || exit 1

- name: Test Swift package
if: needs.ci.outputs.run == 'true'
run: |
swift package init --type library --name SetupLib
swift build --build-tests
swift test

merge:
name: Auto-merge submodule update PR
if: needs.ci.outputs.run == 'true' && needs.dependabot.outputs.merge == 'true'
needs: [ci, analyze, unit-test, integration-test, dry-run, dependabot, feature-test]
needs: [ci, analyze, unit-test, integration-test, dry-run, dependabot, e2e-test]
runs-on: ubuntu-latest
concurrency:
group: swiftorg-update
Expand All @@ -427,8 +437,14 @@ jobs:

cd:
name: Create release
if: always() && needs.ci.outputs.release == 'true' && (needs.analyze.result == 'success' || needs.analyze.result == 'skipped')
needs: [ci, analyze, unit-test, integration-test, dry-run, feature-test]
if: |
always() && needs.ci.outputs.release == 'true' &&
(needs.analyze.result == 'success' || needs.analyze.result == 'skipped') &&
(needs.unit-test.result == 'success' || needs.unit-test.result == 'skipped') &&
(needs.integration-test.result == 'success' || needs.integration-test.result == 'skipped') &&
(needs.dry-run.result == 'success' || needs.dry-run.result == 'skipped') &&
(needs.e2e-test.result == 'success' || needs.e2e-test.result == 'skipped')
needs: [ci, analyze, unit-test, integration-test, dry-run, e2e-test]
runs-on: ubuntu-latest
concurrency:
group: cd-${{ github.ref }}
Expand Down
13 changes: 13 additions & 0 deletions __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path'
import {promises as fs} from 'fs'
import * as os from 'os'
import * as exec from '@actions/exec'
import * as cache from '@actions/cache'
import * as toolCache from '@actions/tool-cache'
Expand Down Expand Up @@ -27,6 +28,11 @@ describe('windows toolchain installation verification', () => {
setupEngineFilePath: path.join('C:', 'Visual Studio', 'setup.exe')
}
}
const vsEnvs = [
`UniversalCRTSdkDir=${path.join('C:', 'Windows Kits')}`,
`UCRTVersion=10.0.17063`,
`VCToolsInstallDir=${path.join('C:', 'Visual Studio', 'Tools')}`
]

beforeEach(() => {
process.env = {...env}
Expand Down Expand Up @@ -97,7 +103,14 @@ describe('windows toolchain installation verification', () => {
const installer = new WindowsToolchainInstaller(toolchain)
installer['visualStudio'] = visualStudio
const installation = path.resolve('tool', 'installed', 'path')
jest.spyOn(fs, 'access').mockRejectedValue(new Error())
jest.spyOn(fs, 'copyFile').mockResolvedValue()
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: vsEnvs.join(os.EOL),
stderr: ''
})
const toolPath = path.join(
installation,
'Developer',
Expand Down
18 changes: 0 additions & 18 deletions __tests__/utils/visual_studio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ describe('visual studio setup validation', () => {
)
)
})

it('tests visual studio setup fails with exit code', async () => {
fsAccessMock()
process.env.VSWHERE_PATH = path.join('C:', 'Visual Studio')
jest.spyOn(exec, 'exec').mockResolvedValue(-1)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: JSON.stringify([visualStudio]),
stderr: ''
})
await expect(
vs.setupVisualStudioTools({version: '16', components: ['Component']})
).rejects.toMatchObject(
new Error(
`Visual Studio installer failed to install required components with exit code: -1.`
)
)
})
})

function fsAccessMock(value = true) {
Expand Down
95 changes: 64 additions & 31 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions src/installer/windows.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as os from 'os'
import * as path from 'path'
import {promises as fs} from 'fs'
import * as core from '@actions/core'
import {exec} from '@actions/exec'
import * as semver from 'semver'
import {VerifyingToolchainInstaller} from './verify'
import {WindowsToolchainSnapshot} from '../snapshot'
import {
Expand All @@ -17,17 +15,13 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
private visualStudio?: VisualStudio

protected async download() {
const reccommended = '10.0.17763'
const current = os.release()
const version = semver.gte(current, reccommended) ? current : reccommended
const winsdk = semver.patch(version)
const vsRequirement: VisualStudioRequirement = {
version: '16',
components: [
'Microsoft.VisualStudio.Component.VC.ATL',
'Microsoft.VisualStudio.Component.VC.CMake.Project',
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
`Microsoft.VisualStudio.Component.Windows10SDK.${winsdk}`,
'Component.CPython.x64',
'Microsoft.VisualStudio.Component.VC.CMake.Project'
'Microsoft.VisualStudio.Component.Windows10SDK'
]
}
core.debug(`Using Visual Studio requirement ${vsRequirement}`)
Expand Down Expand Up @@ -74,9 +68,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
if (!this.visualStudio) {
throw new Error('No supported Visual Studio installation in installer')
}
if (this.version && semver.lt(this.version, '5.4.2')) {
await setupSupportFiles(this.visualStudio)
}
await setupSupportFiles(this.visualStudio, installation.sdkroot)
const swiftFlags = `-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows`
core.exportVariable('SWIFTFLAGS', swiftFlags)
}
Expand Down Expand Up @@ -112,7 +104,14 @@ class Installation {
try {
core.debug(`Checking for development snapshot installation`)
toolchain = path.join(location, 'Toolchains', '0.0.0+Asserts')
sdkroot = path.join(location, 'Toolchains', '0.0.0+Asserts')
sdkroot = path.join(
location,
'Platforms',
'Windows.platform',
'Developer',
'SDKs',
'Windows.sdk'
)
runtime = path.join(location, 'Runtimes', '0.0.0')
await fs.access(toolchain)
} catch (error) {
Expand Down
Loading
Loading