Skip to content

Commit

Permalink
fix: sp 1.12+ include path resolution (#6)
Browse files Browse the repository at this point in the history
* fix: missing & outdated dependencies

* fix: sp 1.12+ include path resolution

* ci: separate ci flow for dev
  • Loading branch information
rumblefrog committed Jul 6, 2022
1 parent 15e37fb commit 7efa536
Show file tree
Hide file tree
Showing 10 changed files with 1,082 additions and 79 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/dev_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Development Workflow

on:
push:
branches-ignore:
- 'master'

jobs:
run:
name: Run action
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup SourcePawn Compiler
uses: ./
with:
version: "1.12.x"

- name: Verify compiler
run: |
which spcomp
echo $includePath
ls -l $scriptingPath
cat $(which spcomp)
spcomp __tests__/compile.sp
17 changes: 9 additions & 8 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
name: Main Workflow

on: [push]
on:
push:
branches:
- 'master'

jobs:
run:
name: Run action
runs-on: ${{ matrix.operating-systems }}
strategy:
matrix:
operating-systems: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup SourcePawn Compiler
uses: rumblefrog/setup-sp@master
with:
version: "1.11.x"
version: "1.12.x"

# For some reason, mac compiler doesn't use the include directory in which the compiler is in
- name: Verify compiler
run: |
which spcomp
echo $includePath
spcomp -i$includePath __tests__/compile.sp
ls -l $scriptingPath
cat $(which spcomp)
spcomp __tests__/compile.sp
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ outputs:
version-file:
description: 'Version of the .sp file'
runs:
using: 'node12'
using: 'node16'
main: 'lib/index.js'
branding:
icon: 'command'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/tool-cache": "^1.1.2",
"@types/node": "^12.12.7",
"@types/semver": "^6.2.0",
"await-to-js": "^2.1.1",
"semver": "^6.3.0"
"@actions/core": "^1.9.0",
"@actions/tool-cache": "^2.0.1",
"@types/node": "^18.0.3",
"@types/semver": "^7.3.10",
"await-to-js": "^3.0.0",
"semver": "^7.3.7",
"typed-rest-client": "^1.8.9"
},
"devDependencies": {
"ts-loader": "^9.2.6",
"typescript": "^4.4.3",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
"ts-loader": "^9.3.1",
"typescript": "^4.7.4",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
"scripts": {
"start": "./node_modules/.bin/webpack --config ./webpack.config.js"
"build": "./node_modules/.bin/webpack --config ./webpack.config.js"
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from '@actions/core';
import { installCompiler } from './installer';
import * as path from "path";
import * as fs from "fs";
import { parseFile } from "./utils/parser";

Expand All @@ -13,11 +12,13 @@ async function run() {

const versionFile = core.getInput('version-file', { required: false });
const defineName = core.getInput('define-name', { required: false });

if(versionFile !== "") {
if(!fs.existsSync(versionFile)) {
core.error("The path of the file containing the version is incorrect.");
return;
}

let parsedVersion = parseFile(versionFile, defineName);
core.setOutput('plugin-version', parsedVersion);
}
Expand Down
32 changes: 27 additions & 5 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { find as findCache, downloadTool, extractTar, extractZip, cacheDir } from '@actions/tool-cache';
import { addPath, exportVariable } from '@actions/core';
import { maxSatisfying } from 'semver';
import { existsSync } from 'fs';
import { rename, writeFile } from 'fs/promises';
import { join as pathJoin } from 'path';
import { getVersions } from './utils/scraper';
import { Version } from './structures/versioning';

let versions;
const CACHE_KEY = 'sourcepawn';
let versions: { [x: string]: Version | { toEndpoint: () => string; }; };

export async function installCompiler(range: string): Promise<string> {
versions = await getVersions();
Expand All @@ -15,13 +19,31 @@ export async function installCompiler(range: string): Promise<string> {
throw new Error(`Unable to find a version matching ${range}`);
}

let cache = findCache('sourcepawn', version);
let cache = findCache(CACHE_KEY, version);

if (!cache) {
cache = await downloadCompiler(version);
}

// Workaround for https://github.com/rumblefrog/setup-sp/issues/5
// We use a proxy script to call the original spcomp64 and include the path to the compiler
if (
process.platform == 'linux' && !existsSync(pathJoin(cache, 'spcomp64_original'))
) {
await rename(pathJoin(cache, 'spcomp64'), pathJoin(cache, 'spcomp64_original'));
await rename(pathJoin(cache, 'spcomp'), pathJoin(cache, 'spcomp_original'));

const proxy_script = `
#!/bin/bash
${pathJoin(cache, 'spcomp64_original')} -i${pathJoin(cache, 'include')} $@
`;

await writeFile(pathJoin(cache, 'spcomp'), proxy_script, { mode: 0o755 });
await writeFile(pathJoin(cache, 'spcomp64'), proxy_script, { mode: 0o755 });
}

addPath(cache);
exportVariable('scriptingPath', pathJoin(cache));
exportVariable('includePath', pathJoin(cache, 'include'));

return version;
Expand All @@ -30,15 +52,15 @@ export async function installCompiler(range: string): Promise<string> {
async function downloadCompiler(version: string) {
const spPath = await downloadTool(versions[version].toEndpoint());

let extracted;
let extracted: string;

if (process.platform === 'linux') {
extracted = await extractTar(spPath);
} else {
extracted = await extractZip(spPath);
}

let spRoot = pathJoin(extracted, 'addons', 'sourcemod', 'scripting');
const spRoot = pathJoin(extracted, 'addons', 'sourcemod', 'scripting');

return await cacheDir(spRoot, 'sourcepawn', version);
return await cacheDir(spRoot, CACHE_KEY, version);
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"lib": [ "es2015" ],
"lib": [ "es2020" ],
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
Expand Down
Loading

0 comments on commit 7efa536

Please sign in to comment.