This repository has been archived by the owner on Mar 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
93 lines (81 loc) · 2.28 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as core from "@actions/core"
import * as tc from "@actions/tool-cache"
import axios from "axios"
import { execSync } from "child_process"
import os = require("os")
import path = require("path")
import process = require("process")
const downloadURL = "https://dl.gitea.io/gitea"
let exp = ""
const getAssetURL = (version: string): string => {
let platform = os.platform().toString()
switch (platform) {
case "win32":
platform = "windows"
break
}
let arch = os.arch()
switch (arch) {
case "x64":
arch = "amd64"
break
case "x32":
case "ia32":
arch = "386"
break
}
switch (platform) {
case "windows":
platform = "windows-4.0"
exp = ".exe"
break
case "darwin":
platform = "darwin-10.12"
break
}
return `${downloadURL}/${version}/gitea-${version}-${platform}-${arch}${exp}`
}
const installGitea = async (version: string): Promise<string> => {
core.info(`Installing gitea ${version}...`)
const startedAt = Date.now()
const assetURL = getAssetURL(version)
core.info(`Downloading ${assetURL} ...`)
const toolPath = await tc.downloadTool(assetURL, `${os.tmpdir()}/gitea${exp}`)
core.info(`Installed gitea into ${toolPath} in ${Date.now() - startedAt}ms`)
run(`chmod +x ${toolPath}`)
core.addPath(path.dirname(toolPath))
core.exportVariable("OS_TMPDIR", path.dirname(toolPath))
return toolPath
}
function run(command: string) {
core.info(command)
const env = Object.assign({}, process.env)
delete env.CI // for Homebrew on macos-11.0
execSync(command, { stdio: "inherit", env: env })
}
const versionURL = "https://dl.gitea.io/gitea/version.json"
const getLatestVersion = (): string => {
let version = "1.15.7"
axios
.get(versionURL)
.then((res) => {
version = res.data.latest.version
})
.catch((err) => {
core.setFailed(`Error: ${err.message}`)
})
return version
}
let installVersion = getLatestVersion()
const inputVersion = core.getInput(`gitea-version`)
if (inputVersion != "" && inputVersion.toLowerCase() != "latest") {
installVersion = inputVersion
}
const args = core.getInput(`args`)
installGitea(installVersion)
.then((toolPath) => {
run(`${toolPath} ${args}`)
})
.catch((err) => {
core.setFailed(`Error: ${err.message}`)
})