Skip to content

Commit dff1353

Browse files
authored
feat: allowed passing snapshot name as version (#49)
i.e. `swift-DEVELOPMENT-SNAPSHOT-2023-09-06-a`
1 parent 5bd49ae commit dff1353

File tree

10 files changed

+240
-18
lines changed

10 files changed

+240
-18
lines changed

__tests__/snapshot/linux.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,44 @@ describe('fetch linux tool data based on options', () => {
180180
expect(lTool.docker).toBeTruthy()
181181
})
182182

183+
it('fetches ubuntu 22.04 named swift tool', async () => {
184+
setos({os: 'linux', dist: 'Ubuntu', release: '22.04'})
185+
jest.spyOn(os, 'arch').mockReturnValue('x64')
186+
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a'
187+
const version = ToolchainVersion.create(name, false)
188+
const tool = await Platform.toolchain(version)
189+
expect(tool).toBeTruthy()
190+
const lTool = tool as LinuxToolchainSnapshot
191+
expect(lTool.download).toBe(
192+
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-ubuntu22.04.tar.gz'
193+
)
194+
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a')
195+
expect(lTool.platform).toBe('ubuntu2204')
196+
expect(lTool.branch).toBe('development')
197+
expect(lTool.download_signature).toBe(
198+
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-ubuntu22.04.tar.gz.sig'
199+
)
200+
})
201+
202+
it('fetches ubuntu 22.04 named versioned swift tool', async () => {
203+
setos({os: 'linux', dist: 'Ubuntu', release: '22.04'})
204+
jest.spyOn(os, 'arch').mockReturnValue('x64')
205+
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a'
206+
const version = ToolchainVersion.create(name, false)
207+
const tool = await Platform.toolchain(version)
208+
expect(tool).toBeTruthy()
209+
const lTool = tool as LinuxToolchainSnapshot
210+
expect(lTool.download).toBe(
211+
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-ubuntu22.04.tar.gz'
212+
)
213+
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a')
214+
expect(lTool.platform).toBe('ubuntu2204')
215+
expect(lTool.branch).toBe('swift-5.9-branch')
216+
expect(lTool.download_signature).toBe(
217+
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-ubuntu22.04.tar.gz.sig'
218+
)
219+
})
220+
183221
it('fetches ubuntu 18.04 latest swift 5.5 tools', async () => {
184222
setos({os: 'linux', dist: 'Ubuntu', release: '18.04'})
185223
jest.spyOn(os, 'arch').mockReturnValue('x64')

__tests__/snapshot/windows.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,44 @@ describe('fetch windows tool data based on options', () => {
106106
expect(wTool.download_signature).toBeTruthy()
107107
})
108108

109+
it('fetches windows 10 named swift tool', async () => {
110+
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
111+
jest.spyOn(os, 'arch').mockReturnValue('x64')
112+
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a'
113+
const version = ToolchainVersion.create(name, false)
114+
const tool = await Platform.toolchain(version)
115+
expect(tool).toBeTruthy()
116+
const lTool = tool as WindowsToolchainSnapshot
117+
expect(lTool.download).toBe(
118+
'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a-windows10.exe'
119+
)
120+
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a')
121+
expect(lTool.platform).toBe('windows10')
122+
expect(lTool.branch).toBe('development')
123+
expect(lTool.download_signature).toBe(
124+
'swift-DEVELOPMENT-SNAPSHOT-2023-08-10-a-windows10.exe.sig'
125+
)
126+
})
127+
128+
it('fetches windows 10 named versioned swift tool', async () => {
129+
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
130+
jest.spyOn(os, 'arch').mockReturnValue('x64')
131+
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a'
132+
const version = ToolchainVersion.create(name, false)
133+
const tool = await Platform.toolchain(version)
134+
expect(tool).toBeTruthy()
135+
const lTool = tool as WindowsToolchainSnapshot
136+
expect(lTool.download).toBe(
137+
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a-windows10.exe'
138+
)
139+
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a')
140+
expect(lTool.platform).toBe('windows10')
141+
expect(lTool.branch).toBe('swift-5.9-branch')
142+
expect(lTool.download_signature).toBe(
143+
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-11-a-windows10.exe.sig'
144+
)
145+
})
146+
109147
it('fetches windows 10 latest swift 5.5 tools', async () => {
110148
setos({os: 'win32', dist: 'Windows', release: '10.0.17063'})
111149
jest.spyOn(os, 'arch').mockReturnValue('x64')

__tests__/snapshot/xcode.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,38 @@ describe('fetch macos tool data based on options', () => {
138138
}
139139
})
140140

141+
it('fetches macOs named swift tool', async () => {
142+
setos({os: 'darwin', dist: 'macOS', release: '21'})
143+
jest.spyOn(os, 'arch').mockReturnValue('x64')
144+
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a'
145+
const version = ToolchainVersion.create(name, false)
146+
const tool = await Platform.toolchain(version)
147+
expect(tool).toBeTruthy()
148+
const lTool = tool as XcodeToolchainSnapshot
149+
expect(lTool.download).toBe(
150+
'swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a-osx.pkg'
151+
)
152+
expect(lTool.dir).toBe('swift-DEVELOPMENT-SNAPSHOT-2023-09-02-a')
153+
expect(lTool.platform).toBe('xcode')
154+
expect(lTool.branch).toBe('development')
155+
})
156+
157+
it('fetches macOS named versioned swift tool', async () => {
158+
setos({os: 'darwin', dist: 'macOS', release: '21'})
159+
jest.spyOn(os, 'arch').mockReturnValue('x64')
160+
const name = 'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a'
161+
const version = ToolchainVersion.create(name, false)
162+
const tool = await Platform.toolchain(version)
163+
expect(tool).toBeTruthy()
164+
const lTool = tool as XcodeToolchainSnapshot
165+
expect(lTool.download).toBe(
166+
'swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a-osx.pkg'
167+
)
168+
expect(lTool.dir).toBe('swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a')
169+
expect(lTool.platform).toBe('xcode')
170+
expect(lTool.branch).toBe('swift-5.9-branch')
171+
})
172+
141173
it('detects earliest toolchains', async () => {
142174
const platform = new XcodePlatform('x64')
143175
const version = ToolchainVersion.create('latest', false)

__tests__/swiftorg.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('swiftorg sync validation', () => {
1515
const swiftorg = new Swiftorg(true)
1616
await swiftorg.update()
1717
expect(rmdirSpy).not.toHaveBeenCalled()
18-
expect(execSpy).toHaveBeenCalledTimes(3)
18+
expect(execSpy).toHaveBeenCalledTimes(2)
1919
const gitArgs = [
2020
'submodule',
2121
'update',
@@ -24,7 +24,7 @@ describe('swiftorg sync validation', () => {
2424
'--remote',
2525
'--merge'
2626
]
27-
expect(execSpy.mock.calls[2]).toStrictEqual([
27+
expect(execSpy.mock.calls[1]).toStrictEqual([
2828
'git',
2929
gitArgs,
3030
{cwd: MODULE_DIR}
@@ -38,9 +38,9 @@ describe('swiftorg sync validation', () => {
3838
const swiftorg = new Swiftorg(false)
3939
await swiftorg.update()
4040
expect(rmdirSpy).not.toHaveBeenCalled()
41-
expect(execSpy).toHaveBeenCalledTimes(3)
42-
const gitArgs = ['submodule', 'update']
43-
expect(execSpy.mock.calls[2]).toStrictEqual([
41+
expect(execSpy).toHaveBeenCalledTimes(2)
42+
const gitArgs = ['submodule', 'update', '--init']
43+
expect(execSpy.mock.calls[1]).toStrictEqual([
4444
'git',
4545
gitArgs,
4646
{cwd: MODULE_DIR}
@@ -54,7 +54,7 @@ describe('swiftorg sync validation', () => {
5454
const swiftorg = new Swiftorg(true)
5555
await swiftorg.update()
5656
expect(rmdirSpy).toHaveBeenCalled()
57-
expect(execSpy).toHaveBeenCalledTimes(4)
57+
expect(execSpy).toHaveBeenCalledTimes(3)
5858
})
5959

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

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

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

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

101101
it('tests without latest sync failure with no swiftorg and no commit in package.json', async () => {
@@ -106,6 +106,6 @@ describe('swiftorg sync validation', () => {
106106
const swiftorg = new Swiftorg(false)
107107
await swiftorg.update()
108108
expect(rmdirSpy).not.toHaveBeenCalled()
109-
expect(execSpy).toHaveBeenCalledTimes(4)
109+
expect(execSpy).toHaveBeenCalledTimes(3)
110110
})
111111
})

__tests__/version.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
ToolchainVersion,
33
SemanticToolchainVersion,
4-
LatestToolchainVersion
4+
LatestToolchainVersion,
5+
ToolchainSnapshotName
56
} from '../src/version'
67

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

88+
it('parses toolchain name', async () => {
89+
const name = 'swift-DEVELOPMENT-SNAPSHOT-2023-09-06-a'
90+
const version = ToolchainVersion.create(name, false)
91+
expect(version).toBeInstanceOf(ToolchainSnapshotName)
92+
expect(version.dev).toBe(true)
93+
const lVersion = version as ToolchainSnapshotName
94+
expect(lVersion['dirGlob']).toBe('*')
95+
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(name))
96+
})
97+
98+
it('parses toolchain name without prefix', async () => {
99+
const input = '5.9-DEVELOPMENT-SNAPSHOT-2023-09-05-a'
100+
const name = `swift-${input}`
101+
const version = ToolchainVersion.create(input, false)
102+
expect(version).toBeInstanceOf(ToolchainSnapshotName)
103+
expect(version.dev).toBe(true)
104+
const lVersion = version as ToolchainSnapshotName
105+
expect(lVersion['dirGlob']).toBe('swift-5_9-*')
106+
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(name))
107+
})
108+
87109
it('parses invalid input', async () => {
88110
const creation = () => ToolchainVersion.create('invalid', false)
89111
expect(creation).toThrow()

dist/index.js

Lines changed: 51 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/platform/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export abstract class Platform<
4848
} as SnapshotForInstaller<Installer>
4949
})
5050
})
51+
.filter(item => version.satisfiedBy((item as ToolchainSnapshot).dir))
5152
.sort(
5253
(item1, item2) =>
5354
(item2 as ToolchainSnapshot).date.getTime() -

src/swiftorg.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ export class Swiftorg {
4545
}
4646

4747
async update() {
48-
const gitArgs = ['submodule', 'update']
48+
const gitArgs = ['submodule', 'update', '--init']
4949
if (this.checkLatest) {
50-
gitArgs.push('--init', '--recursive', '--remote', '--merge')
50+
gitArgs.push('--recursive', '--remote', '--merge')
5151
}
5252
core.debug(`Initializing submodules in "${MODULE_DIR}"`)
5353
await exec('git', ['init'], {cwd: MODULE_DIR})
54-
await exec('git', ['submodule', 'init'], {cwd: MODULE_DIR})
5554
core.debug(`Updating submodules in "${MODULE_DIR}" with args "${gitArgs}"`)
5655
await exec('git', gitArgs, {cwd: MODULE_DIR})
5756
const swiftorg = path.join(MODULE_DIR, 'swiftorg')

0 commit comments

Comments
 (0)