Skip to content

Commit

Permalink
simplify cache/product directory into one
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberbeni committed Oct 22, 2024
1 parent 2a687a7 commit 548a6e4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function getUuid(url: string, commitHash: string): Promise<string>
const swiftVersion = await exec('swift', ['-version'])
additionalInfo = `${osVersion}-${os.arch()}-${swiftVersion}`
}
return _uuid(`${url}-${commitHash}-${additionalInfo}`, '6050636b-7499-41d4-b9c6-756aff9856d0')
return _uuid(`${url}-${commitHash}-${additionalInfo}`, '96adb500-f0f6-43f2-9774-ad6c1160a37b')
}

export function errorMessage(error: unknown): string {
Expand Down
18 changes: 6 additions & 12 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,24 @@ export class SwiftToolInstaller {
}
}

uuid = ''
cacheKey = ''
workingDirectory = ''
productDirectory = ''
cacheDirectory = ''
updateDirectoryNames(newUuid: string): void {
this.uuid = newUuid
this.cacheKey = `installswifttool-${this.uuid}`
this.workingDirectory = `${os.homedir()}/install-swift-tool-${this.uuid}`
this.productDirectory = `${this.workingDirectory}/.build/release`
this.cacheDirectory = `${this.workingDirectory}/.build/*/release`
}
async createWorkingDirectory(): Promise<void> {
await core.group('Creating working directory', async () => {
this.commit = await this.getCommitHash()
this.updateDirectoryNames(await getUuid(this.url, this.commit))
const uuid = await getUuid(this.url, this.commit)
this.cacheKey = `installswifttool-${uuid}`
this.workingDirectory = `${os.homedir()}/install-swift-tool-${uuid}`
await exec('mkdir', ['-p', this.workingDirectory])
this.productDirectory = await exec('swift', ['build', '--package-path', this.workingDirectory, '--configuration', 'release', '--show-bin-dir'])
})
}

didRestore = false
async tryToRestore(): Promise<void> {
await core.group('Trying to restore from cache', async () => {
this.didRestore = (await cache.restoreCache([this.cacheDirectory, this.productDirectory], this.cacheKey)) !== undefined
this.didRestore = (await cache.restoreCache([this.productDirectory], this.cacheKey)) !== undefined
})
}

Expand Down Expand Up @@ -146,7 +140,7 @@ export class SwiftToolInstaller {
async tryToCache(): Promise<void> {
await core.group('Trying to save to cache', async () => {
try {
await cache.saveCache([this.cacheDirectory, this.productDirectory], this.cacheKey)
await cache.saveCache([this.productDirectory], this.cacheKey)
} catch (error) {
logError(error)
}
Expand Down

0 comments on commit 548a6e4

Please sign in to comment.