Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- add `STEAM_CMD`
- add `STEAM_DIR`
  • Loading branch information
StephenHodgson authored Jul 27, 2024
1 parent c92039e commit af3bba5
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 76 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @StephenHodgson
7 changes: 5 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ jobs:
uses: ./

- run: |
which steamcmd
steamcmd +help +quit
echo "STEAM_CMD: $STEAM_CMD"
echo "STEAM_DIR: $STEAM_DIR"
which steamcmd > /dev/null
steamcmd +login anonymous +help +quit
shell: bash
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# setup-steamcmd

Sets up `steamcmd` for Github Action Runners.
A GitHub Action to setup the [`steamcmd`](https://developer.valvesoftware.com/wiki/SteamCMD) command alias.

## Exported Env Vars

- `STEAM_CMD` the `steamcmd` directory location.
- `STEAM_DIR` the steam install directory location.

## How to use

Expand All @@ -13,11 +18,12 @@ jobs:
os: [ macos-latest, windows-latest, ubuntu-latest ]

steps:
- uses: actions/checkout@v4
# download and setup the steamcmd
- uses: RageAgainstThePixel/setup-steamcmd@v1
# run commands
- run: |
which steamcmd
steamcmd +help +quit
```
for a list of `steamcmd` commands see [this list](https://github.com/dgibbs64/SteamCMD-Commands-List).
For a full list of `steamcmd` commands see [this list](https://github.com/dgibbs64/SteamCMD-Commands-List/blob/main/steamcmd_commands.txt).
77 changes: 50 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30691,6 +30691,8 @@ const exec = __nccwpck_require__(1514);
const fs = (__nccwpck_require__(7147).promises);

const steamcmd = 'steamcmd';
const STEAM_CMD = 'STEAM_CMD';
const STEAM_DIR = 'STEAM_DIR';
const IS_LINUX = process.platform === 'linux';
const IS_MAC = process.platform === 'darwin';
const IS_WINDOWS = process.platform === 'win32';
Expand All @@ -30699,7 +30701,7 @@ const toolPath = `${steamcmd}${toolExtension}`;

const main = async () => {
try {
core.info('Setting up steamcmd');
core.info(`Setting up ${steamcmd}...`);
await setup_steamcmd();
} catch (error) {
core.setFailed(error.message);
Expand All @@ -30709,24 +30711,27 @@ const main = async () => {
main();

async function setup_steamcmd() {
const [tool, toolDirectory] = await findOrDownload();
core.debug(`${steamcmd} -> ${tool}`);
const [toolDirectory, steamDir] = await findOrDownload();
core.debug(`${STEAM_CMD} -> ${toolDirectory}`);
core.addPath(toolDirectory);
core.exportVariable(steamcmd, tool);
await exec.exec(tool, ['+help', '+quit']);
const steam_cmd = path.join(toolDirectory, steamcmd);
core.exportVariable(STEAM_CMD, steam_cmd);
core.debug(`${STEAM_DIR} -> ${steamDir}`);
core.exportVariable(STEAM_DIR, steamDir);
await exec.exec(steamcmd, ['+help', '+quit']);
}

async function findOrDownload() {
let toolDirectory = tc.find(steamcmd, '*');
let tool = undefined;
if (!toolDirectory) {
const [url, archiveName] = getDownloadUrl();
const archiveDownloadPath = path.resolve(getTempDirectory(), archiveName);
const archiveDownloadPath = path.join(getTempDirectory(), archiveName);
core.debug(`Attempting to download ${steamcmd} from ${url} to ${archiveDownloadPath}`);
const archivePath = await tc.downloadTool(url, archiveDownloadPath);
core.debug(`Successfully downloaded ${steamcmd} to ${archivePath}`);
core.debug(`Extracting ${steamcmd} from ${archivePath}`);
let downloadDirectory = path.resolve(getTempDirectory(), steamcmd);
let downloadDirectory = path.join(getTempDirectory(), steamcmd);
if (IS_WINDOWS) {
downloadDirectory = await tc.extractZip(archivePath, downloadDirectory);
} else {
Expand All @@ -30739,28 +30744,22 @@ async function findOrDownload() {
await exec.exec(`chmod +x ${downloadDirectory}`);
}
core.debug(`Successfully extracted ${steamcmd} to ${downloadDirectory}`);
tool = getExecutable(downloadDirectory);
tool = path.join(downloadDirectory, toolPath);
if (IS_LINUX) {
const binDir = path.resolve(downloadDirectory, 'bin');
const binExe = path.resolve(binDir, steamcmd);
await fs.mkdir(binDir);
await fs.writeFile(binExe, `#!/bin/bash\nexec "${tool}" "$@"`);
await fs.chmod(binExe, 0o755);
tool = binExe;
const exe = path.join(downloadDirectory, steamcmd);
await fs.writeFile(exe, `#!/bin/bash\nexec "${tool}" "$@"`);
await fs.chmod(exe, 0o755);
}
const downloadVersion = await getVersion(tool);
core.debug(`Setting tool cache: ${downloadDirectory} | ${steamcmd} | ${downloadVersion}`);
toolDirectory = await tc.cacheDir(downloadDirectory, steamcmd, downloadVersion);
}

if (IS_LINUX) {
tool = path.resolve(toolDirectory, 'bin', steamcmd);
toolDirectory = path.resolve(toolDirectory, 'bin');
} else {
tool = getExecutable(toolDirectory);
tool = path.join(toolDirectory, toolPath);
}
fs.access(tool);
core.debug(`Found ${tool} in ${toolDirectory}`);
return [tool, toolDirectory];
const steamDir = getSteamDir(toolDirectory);
return [toolDirectory, steamDir];
}

function getDownloadUrl() {
Expand All @@ -30786,14 +30785,10 @@ function getTempDirectory() {
return tempDirectory
}

function getExecutable(directory) {
return path.resolve(directory, toolPath);
}

async function getVersion(path) {
async function getVersion(tool) {
const semVerRegEx = 'Steam Console Client \\(c\\) Valve Corporation - version (?<version>\\d+)';
let output = '';
await exec.exec(path, '+quit', {
await exec.exec(tool, '+quit', {
listeners: {
stdout: (data) => {
output += data.toString();
Expand All @@ -30814,6 +30809,34 @@ async function getVersion(path) {
return version
}

function getSteamDir(toolDirectory) {
let steamDir = undefined;
switch (process.platform) {
case 'linux':
steamDir = '/home/runner/Steam';
break;
case 'darwin':
steamDir = '/Users/runner/Library/Application Support/Steam';
break;
default:
steamDir = toolDirectory;
break;
}
// check if steam directory exists and create if not
try {
fs.access(steamDir);
} catch (error) {
if (error.code === 'ENOENT') {
core.debug(`Creating steam directory: ${steamDir}`);
fs.mkdir(steamDir);
} else {
throw error;
}
}
core.debug(`Steam directory: ${steamDir}`);
return steamDir;
}

})();

module.exports = __webpack_exports__;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 3 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-steamcmd",
"version": "1.0.0",
"version": "1.1.0",
"description": "Sets up steamcmd for Github Action Runners",
"author": "RageAgainstThePixel",
"repository": {
Expand Down
77 changes: 50 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const exec = require('@actions/exec');
const fs = require('fs').promises;

const steamcmd = 'steamcmd';
const STEAM_CMD = 'STEAM_CMD';
const STEAM_DIR = 'STEAM_DIR';
const IS_LINUX = process.platform === 'linux';
const IS_MAC = process.platform === 'darwin';
const IS_WINDOWS = process.platform === 'win32';
Expand All @@ -13,7 +15,7 @@ const toolPath = `${steamcmd}${toolExtension}`;

const main = async () => {
try {
core.info('Setting up steamcmd');
core.info(`Setting up ${steamcmd}...`);
await setup_steamcmd();
} catch (error) {
core.setFailed(error.message);
Expand All @@ -23,24 +25,27 @@ const main = async () => {
main();

async function setup_steamcmd() {
const [tool, toolDirectory] = await findOrDownload();
core.debug(`${steamcmd} -> ${tool}`);
const [toolDirectory, steamDir] = await findOrDownload();
core.debug(`${STEAM_CMD} -> ${toolDirectory}`);
core.addPath(toolDirectory);
core.exportVariable(steamcmd, tool);
await exec.exec(tool, ['+help', '+quit']);
const steam_cmd = path.join(toolDirectory, steamcmd);
core.exportVariable(STEAM_CMD, steam_cmd);
core.debug(`${STEAM_DIR} -> ${steamDir}`);
core.exportVariable(STEAM_DIR, steamDir);
await exec.exec(steamcmd, ['+help', '+quit']);
}

async function findOrDownload() {
let toolDirectory = tc.find(steamcmd, '*');
let tool = undefined;
if (!toolDirectory) {
const [url, archiveName] = getDownloadUrl();
const archiveDownloadPath = path.resolve(getTempDirectory(), archiveName);
const archiveDownloadPath = path.join(getTempDirectory(), archiveName);
core.debug(`Attempting to download ${steamcmd} from ${url} to ${archiveDownloadPath}`);
const archivePath = await tc.downloadTool(url, archiveDownloadPath);
core.debug(`Successfully downloaded ${steamcmd} to ${archivePath}`);
core.debug(`Extracting ${steamcmd} from ${archivePath}`);
let downloadDirectory = path.resolve(getTempDirectory(), steamcmd);
let downloadDirectory = path.join(getTempDirectory(), steamcmd);
if (IS_WINDOWS) {
downloadDirectory = await tc.extractZip(archivePath, downloadDirectory);
} else {
Expand All @@ -53,28 +58,22 @@ async function findOrDownload() {
await exec.exec(`chmod +x ${downloadDirectory}`);
}
core.debug(`Successfully extracted ${steamcmd} to ${downloadDirectory}`);
tool = getExecutable(downloadDirectory);
tool = path.join(downloadDirectory, toolPath);
if (IS_LINUX) {
const binDir = path.resolve(downloadDirectory, 'bin');
const binExe = path.resolve(binDir, steamcmd);
await fs.mkdir(binDir);
await fs.writeFile(binExe, `#!/bin/bash\nexec "${tool}" "$@"`);
await fs.chmod(binExe, 0o755);
tool = binExe;
const exe = path.join(downloadDirectory, steamcmd);
await fs.writeFile(exe, `#!/bin/bash\nexec "${tool}" "$@"`);
await fs.chmod(exe, 0o755);
}
const downloadVersion = await getVersion(tool);
core.debug(`Setting tool cache: ${downloadDirectory} | ${steamcmd} | ${downloadVersion}`);
toolDirectory = await tc.cacheDir(downloadDirectory, steamcmd, downloadVersion);
}

if (IS_LINUX) {
tool = path.resolve(toolDirectory, 'bin', steamcmd);
toolDirectory = path.resolve(toolDirectory, 'bin');
} else {
tool = getExecutable(toolDirectory);
tool = path.join(toolDirectory, toolPath);
}
fs.access(tool);
core.debug(`Found ${tool} in ${toolDirectory}`);
return [tool, toolDirectory];
const steamDir = getSteamDir(toolDirectory);
return [toolDirectory, steamDir];
}

function getDownloadUrl() {
Expand All @@ -100,14 +99,10 @@ function getTempDirectory() {
return tempDirectory
}

function getExecutable(directory) {
return path.resolve(directory, toolPath);
}

async function getVersion(path) {
async function getVersion(tool) {
const semVerRegEx = 'Steam Console Client \\(c\\) Valve Corporation - version (?<version>\\d+)';
let output = '';
await exec.exec(path, '+quit', {
await exec.exec(tool, '+quit', {
listeners: {
stdout: (data) => {
output += data.toString();
Expand All @@ -127,3 +122,31 @@ async function getVersion(path) {
core.debug(`Found version: ${version}`);
return version
}

function getSteamDir(toolDirectory) {
let steamDir = undefined;
switch (process.platform) {
case 'linux':
steamDir = '/home/runner/Steam';
break;
case 'darwin':
steamDir = '/Users/runner/Library/Application Support/Steam';
break;
default:
steamDir = toolDirectory;
break;
}
// check if steam directory exists and create if not
try {
fs.access(steamDir);
} catch (error) {
if (error.code === 'ENOENT') {
core.debug(`Creating steam directory: ${steamDir}`);
fs.mkdir(steamDir);
} else {
throw error;
}
}
core.debug(`Steam directory: ${steamDir}`);
return steamDir;
}

0 comments on commit af3bba5

Please sign in to comment.