Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion dist/logout/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/logout/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";

const runnerWindows = "Windows";
const runnerMacOS = "macOS";
Expand Down Expand Up @@ -61,7 +63,13 @@ async function logout(): Promise<void> {
await exec.exec("net", ["stop", "Tailscale"]);
await exec.exec("taskkill", ["/F", "/IM", "tailscale-ipn.exe"]);
} else {
const pid = fs.readFileSync("tailscaled.pid").toString();
const xdgRuntimeDir =
process.env.XDG_RUNTIME_DIR ||
process.env.XDG_CACHE_HOME ||
path.join(os.homedir(), ".cache");
const pid = fs
.readFileSync(path.join(xdgRuntimeDir, "tailscaled.pid"))
.toString();
if (pid === "") {
throw new Error("pid file empty");
}
Expand Down
17 changes: 15 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const runnerLinux = "Linux";
const runnerWindows = "Windows";
const runnerMacOS = "macOS";

// XDG base directories with sensible defaults.
function xdgCacheDir(): string {
return process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
}

function xdgRuntimeDir(): string {
return process.env.XDG_RUNTIME_DIR || xdgCacheDir();
}

const versionLatest = "latest";
const versionUnstable = "unstable";

Expand Down Expand Up @@ -420,7 +429,9 @@ async function installTailscaleLinux(
const downloadUrl = `${baseUrl}/tailscale_${config.resolvedVersion}_${config.arch}.tgz`;
core.info(`Downloading ${downloadUrl}`);

const tarPath = await tc.downloadTool(downloadUrl, "tailscale.tgz");
const tarDest = path.join(xdgCacheDir(), "tailscale.tgz");
fs.mkdirSync(path.dirname(tarDest), { recursive: true });
const tarPath = await tc.downloadTool(downloadUrl, tarDest);

// Verify checksum
const actualSha = await calculateFileSha256(tarPath);
Expand Down Expand Up @@ -651,7 +662,9 @@ async function startTailscaleDaemon(config: TailscaleConfig): Promise<void> {
});

// Store PID for cleaning up daemon process in logout.ts.
fs.writeFileSync("tailscaled.pid", `${daemon.pid}`);
const pidFile = path.join(xdgRuntimeDir(), "tailscaled.pid");
fs.mkdirSync(path.dirname(pidFile), { recursive: true });
fs.writeFileSync(pidFile, `${daemon.pid}`);

daemon.unref(); // Ensure daemon doesn't keep Node.js process alive

Expand Down
Loading