-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/github_actions/actions/upload-art…
…ifact-4.4.0
- Loading branch information
Showing
12 changed files
with
251 additions
and
144 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as tc from "@actions/tool-cache"; | ||
import * as core from "@actions/core"; | ||
import * as cp from "child_process"; | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
import { verifyChecksum } from "./checksum"; | ||
import { EOL } from "os"; | ||
import { ARM64_RUNNER_MESSAGE } from "./common"; | ||
|
||
export async function installAgent( | ||
isTLS: boolean, | ||
configStr: string | ||
): Promise<boolean> { | ||
// Note: to avoid github rate limiting | ||
const token = core.getInput("token", { required: true }); | ||
const auth = `token ${token}`; | ||
|
||
const variant = process.arch === "x64" ? "amd64" : "arm64"; | ||
|
||
let downloadPath: string; | ||
|
||
fs.appendFileSync(process.env.GITHUB_STATE, `isTLS=${isTLS}${EOL}`, { | ||
encoding: "utf8", | ||
}); | ||
|
||
if (isTLS) { | ||
downloadPath = await tc.downloadTool( | ||
`https://packages.stepsecurity.io/github-hosted/harden-runner_1.3.2_linux_${variant}.tar.gz` | ||
); | ||
} else { | ||
if (variant === "arm64") { | ||
console.log(ARM64_RUNNER_MESSAGE); | ||
return false; | ||
} | ||
downloadPath = await tc.downloadTool( | ||
"https://github.com/step-security/agent/releases/download/v0.13.7/agent_0.13.7_linux_amd64.tar.gz", | ||
undefined, | ||
auth | ||
); | ||
} | ||
|
||
verifyChecksum(downloadPath, isTLS, variant); | ||
|
||
const extractPath = await tc.extractTar(downloadPath); | ||
|
||
let cmd = "cp", | ||
args = [path.join(extractPath, "agent"), "/home/agent/agent"]; | ||
|
||
cp.execFileSync(cmd, args); | ||
|
||
cp.execSync("chmod +x /home/agent/agent"); | ||
|
||
fs.writeFileSync("/home/agent/agent.json", configStr); | ||
|
||
cmd = "sudo"; | ||
args = [ | ||
"cp", | ||
path.join(__dirname, "agent.service"), | ||
"/etc/systemd/system/agent.service", | ||
]; | ||
cp.execFileSync(cmd, args); | ||
cp.execSync("sudo systemctl daemon-reload"); | ||
cp.execSync("sudo service agent start", { timeout: 15000 }); | ||
return true; | ||
} |
Oops, something went wrong.