This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.ts
77 lines (71 loc) · 2.44 KB
/
installer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as core from '@actions/core'
import * as httpm from '@actions/http-client'
import * as tc from '@actions/tool-cache'
import {Release} from './release'
import os from 'os'
import path from 'path'
export async function getWaypointIndex(): Promise<Release> {
const http: httpm.HttpClient = new httpm.HttpClient(
'setup-waypoint (GitHub Action)',
[],
{
headers: {
Accept:
'application/vnd+hashicorp.releases-api.v0+json;application/vnd+hashicorp.releases-api.v1+json',
'Content-Type': 'application/json'
}
}
)
const indexUrl = 'https://releases.hashicorp.com/waypoint/index.json'
const res: httpm.HttpClientResponse = await http.get(indexUrl)
const body: string = await res.readBody()
const result: Release = JSON.parse(body)
return result
}
export async function installWaypointVersion(
version: string,
plat: string,
architecture: string
): Promise<string> {
core.info(`Acquiring ${version}`)
// Windows requires that we keep the extension (.zip) for extraction
const isWindows = os.platform() === 'win32'
const tempDir = process.env.RUNNER_TEMP || '.'
const fileName = isWindows
? path.join(tempDir, `waypoint_${version}_${plat}_${architecture}.zip`)
: undefined
const downloadUrl = `https://releases.hashicorp.com/waypoint/${version}/waypoint_${version}_${plat}_${architecture}.zip`
core.info(`Downloading ${downloadUrl}`)
const downloadPath = await tc.downloadTool(
`https://releases.hashicorp.com/waypoint/${version}/waypoint_${version}_${plat}_${architecture}.zip`,
fileName
)
core.info('Extracting Waypoint...')
const waypointExtractedFolder = await tc.extractZip(downloadPath)
core.info(`Successfully extracted Waypoint to ${waypointExtractedFolder}`)
core.info('Adding to the cache...')
const cachedDir = await tc.cacheDir(
waypointExtractedFolder,
'waypoint',
version,
architecture
)
core.info(`Successfully cached Waypoint to ${cachedDir}`)
return cachedDir
}
export async function getWaypoint(
version: string,
plat: string,
architecture: string
): Promise<string> {
// check cache
const toolPath = tc.find('waypoint', version, architecture)
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`)
return toolPath
}
core.info(`Attempting to download ${version}...`)
const waypointPath = await installWaypointVersion(version, plat, architecture)
return waypointPath
}