Skip to content

Commit

Permalink
feat: allowed passing snapshot name as version (#49)
Browse files Browse the repository at this point in the history
i.e. `swift-DEVELOPMENT-SNAPSHOT-2023-09-06-a`
  • Loading branch information
soumyamahunt authored Sep 8, 2023
1 parent 5bd49ae commit dff1353
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 18 deletions.
38 changes: 38 additions & 0 deletions __tests__/snapshot/linux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,44 @@ describe('fetch linux tool data based on options', () => {
expect(lTool.docker).toBeTruthy()
})

it('fetches ubuntu 22.04 named swift tool', async () => {
setos({os: 'linux', dist: 'Ubuntu', release: '22.04'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as LinuxToolchainSnapshot
expect(lTool.download).toBe(
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-ubuntu22.04.tar.gz'
)
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a')
expect(lTool.platform).toBe('ubuntu2204')
expect(lTool.branch).toBe('development')
expect(lTool.download_signature).toBe(
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-ubuntu22.04.tar.gz.sig'
)
})

it('fetches ubuntu 22.04 named versioned swift tool', async () => {
setos({os: 'linux', dist: 'Ubuntu', release: '22.04'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as LinuxToolchainSnapshot
expect(lTool.download).toBe(
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-ubuntu22.04.tar.gz'
)
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a')
expect(lTool.platform).toBe('ubuntu2204')
expect(lTool.branch).toBe('swift-5.9-branch')
expect(lTool.download_signature).toBe(
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-ubuntu22.04.tar.gz.sig'
)
})

it('fetches ubuntu 18.04 latest swift 5.5 tools', async () => {
setos({os: 'linux', dist: 'Ubuntu', release: '18.04'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
Expand Down
38 changes: 38 additions & 0 deletions __tests__/snapshot/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ describe('fetch windows tool data based on options', () => {
expect(wTool.download_signature).toBeTruthy()
})

it('fetches windows 10 named swift tool', async () => {
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as WindowsToolchainSnapshot
expect(lTool.download).toBe(
'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a-windows10.exe'
)
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a')
expect(lTool.platform).toBe('windows10')
expect(lTool.branch).toBe('development')
expect(lTool.download_signature).toBe(
'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a-windows10.exe.sig'
)
})

it('fetches windows 10 named versioned swift tool', async () => {
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as WindowsToolchainSnapshot
expect(lTool.download).toBe(
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a-windows10.exe'
)
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a')
expect(lTool.platform).toBe('windows10')
expect(lTool.branch).toBe('swift-5.9-branch')
expect(lTool.download_signature).toBe(
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a-windows10.exe.sig'
)
})

it('fetches windows 10 latest swift 5.5 tools', async () => {
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
Expand Down
32 changes: 32 additions & 0 deletions __tests__/snapshot/xcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,38 @@ describe('fetch macos tool data based on options', () => {
}
})

it('fetches macOs named swift tool', async () => {
setos({os: 'darwin', dist: 'macOS', release: '21'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as XcodeToolchainSnapshot
expect(lTool.download).toBe(
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-osx.pkg'
)
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a')
expect(lTool.platform).toBe('xcode')
expect(lTool.branch).toBe('development')
})

it('fetches macOS named versioned swift tool', async () => {
setos({os: 'darwin', dist: 'macOS', release: '21'})
jest.spyOn(os, 'arch').mockReturnValue('x64')
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a'
const version = ToolchainVersion.create(name, false)
const tool = await Platform.toolchain(version)
expect(tool).toBeTruthy()
const lTool = tool as XcodeToolchainSnapshot
expect(lTool.download).toBe(
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-osx.pkg'
)
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a')
expect(lTool.platform).toBe('xcode')
expect(lTool.branch).toBe('swift-5.9-branch')
})

it('detects earliest toolchains', async () => {
const platform = new XcodePlatform('x64')
const version = ToolchainVersion.create('latest', false)
Expand Down
22 changes: 11 additions & 11 deletions __tests__/swiftorg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(true)
await swiftorg.update()
expect(rmdirSpy).not.toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(3)
expect(execSpy).toHaveBeenCalledTimes(2)
const gitArgs = [
'submodule',
'update',
Expand All @@ -24,7 +24,7 @@ describe('swiftorg sync validation', () => {
'--remote',
'--merge'
]
expect(execSpy.mock.calls[2]).toStrictEqual([
expect(execSpy.mock.calls[1]).toStrictEqual([
'git',
gitArgs,
{cwd: MODULE_DIR}
Expand All @@ -38,9 +38,9 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(false)
await swiftorg.update()
expect(rmdirSpy).not.toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(3)
const gitArgs = ['submodule', 'update']
expect(execSpy.mock.calls[2]).toStrictEqual([
expect(execSpy).toHaveBeenCalledTimes(2)
const gitArgs = ['submodule', 'update', '--init']
expect(execSpy.mock.calls[1]).toStrictEqual([
'git',
gitArgs,
{cwd: MODULE_DIR}
Expand All @@ -54,7 +54,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(true)
await swiftorg.update()
expect(rmdirSpy).toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(4)
expect(execSpy).toHaveBeenCalledTimes(3)
})

it('tests without latest sync failure with empty swiftorg', async () => {
Expand All @@ -64,7 +64,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(false)
await swiftorg.update()
expect(rmdirSpy).toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(5)
expect(execSpy).toHaveBeenCalledTimes(4)
})

it('tests latest sync failure with no swiftorg', async () => {
Expand All @@ -74,7 +74,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(true)
await swiftorg.update()
expect(rmdirSpy).not.toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(4)
expect(execSpy).toHaveBeenCalledTimes(3)
})

it('tests without latest sync failure with no swiftorg', async () => {
Expand All @@ -84,7 +84,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(false)
await swiftorg.update()
expect(rmdirSpy).not.toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(5)
expect(execSpy).toHaveBeenCalledTimes(4)
})

it('tests without latest sync failure with empty swiftorg and no commit in package.json', async () => {
Expand All @@ -95,7 +95,7 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(false)
await swiftorg.update()
expect(rmdirSpy).toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(4)
expect(execSpy).toHaveBeenCalledTimes(3)
})

it('tests without latest sync failure with no swiftorg and no commit in package.json', async () => {
Expand All @@ -106,6 +106,6 @@ describe('swiftorg sync validation', () => {
const swiftorg = new Swiftorg(false)
await swiftorg.update()
expect(rmdirSpy).not.toHaveBeenCalled()
expect(execSpy).toHaveBeenCalledTimes(4)
expect(execSpy).toHaveBeenCalledTimes(3)
})
})
24 changes: 23 additions & 1 deletion __tests__/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
ToolchainVersion,
SemanticToolchainVersion,
LatestToolchainVersion
LatestToolchainVersion,
ToolchainSnapshotName
} from '../src/version'

describe('parse version from provided string', () => {
Expand Down Expand Up @@ -84,6 +85,27 @@ describe('parse version from provided string', () => {
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.5.1/)
})

it('parses toolchain name', async () => {
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-06-a'
const version = ToolchainVersion.create(name, false)
expect(version).toBeInstanceOf(ToolchainSnapshotName)
expect(version.dev).toBe(true)
const lVersion = version as ToolchainSnapshotName
expect(lVersion['dirGlob']).toBe('*')
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(name))
})

it('parses toolchain name without prefix', async () => {
const input = '5.9-DEVELOPMENT-SNAPSHOT-2023-09-05-a'
const name = `swift-${input}`
const version = ToolchainVersion.create(input, false)
expect(version).toBeInstanceOf(ToolchainSnapshotName)
expect(version.dev).toBe(true)
const lVersion = version as ToolchainSnapshotName
expect(lVersion['dirGlob']).toBe('swift-5_9-*')
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(name))
})

it('parses invalid input', async () => {
const creation = () => ToolchainVersion.create('invalid', false)
expect(creation).toThrow()
Expand Down
54 changes: 51 additions & 3 deletions dist/index.js

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

1 change: 1 addition & 0 deletions src/platform/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export abstract class Platform<
} as SnapshotForInstaller<Installer>
})
})
.filter(item => version.satisfiedBy((item as ToolchainSnapshot).dir))
.sort(
(item1, item2) =>
(item2 as ToolchainSnapshot).date.getTime() -
Expand Down
5 changes: 2 additions & 3 deletions src/swiftorg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ export class Swiftorg {
}

async update() {
const gitArgs = ['submodule', 'update']
const gitArgs = ['submodule', 'update', '--init']
if (this.checkLatest) {
gitArgs.push('--init', '--recursive', '--remote', '--merge')
gitArgs.push('--recursive', '--remote', '--merge')
}
core.debug(`Initializing submodules in "${MODULE_DIR}"`)
await exec('git', ['init'], {cwd: MODULE_DIR})
await exec('git', ['submodule', 'init'], {cwd: MODULE_DIR})
core.debug(`Updating submodules in "${MODULE_DIR}" with args "${gitArgs}"`)
await exec('git', gitArgs, {cwd: MODULE_DIR})
const swiftorg = path.join(MODULE_DIR, 'swiftorg')
Expand Down
Loading

0 comments on commit dff1353

Please sign in to comment.