Skip to content

Commit 6317259

Browse files
author
Sergey Vilgelm
authored
Run action on different platforms (#65)
1 parent 809d3b0 commit 6317259

File tree

6 files changed

+147
-24
lines changed

6 files changed

+147
-24
lines changed

.github/workflows/test.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ jobs:
1515
npm install
1616
npm run all
1717
test: # make sure the action works on a clean machine without building
18-
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
os:
21+
- ubuntu-latest
22+
- macos-latest
23+
- windows-latest
24+
runs-on: ${{ matrix.os }}
1925
steps:
2026
- uses: actions/checkout@v2
2127
- uses: ./

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ We use JavaScript-based action. We don't use Docker-based action because:
8282
1. docker pulling is slow currently
8383
2. it's easier to use caching from [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache)
8484

85+
We support different platforms, such as `ubuntu`, `macos` and `windows` with `x32` and `x64` archs.
86+
8587
Inside our action we perform 3 steps:
8688

8789
1. Setup environment running in parallel:
@@ -95,7 +97,7 @@ Inside our action we perform 3 steps:
9597
### Caching internals
9698

9799
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
98-
2. The primary caching key looks like `golangci-lint.cache-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
100+
2. The primary caching key looks like `golangci-lint.cache-{platform-arch}-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
99101
our cache (every 7 days). `go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed.
100102
3. We use [restore keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key): `golangci-lint.cache-{interval_number}-`, `golangci-lint.cache-`. GitHub matches keys by prefix if we have no exact match for the primary cache.
101103

dist/post_run/index.js

+46-7
Original file line numberDiff line numberDiff line change
@@ -41407,18 +41407,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
4140741407
exports.installGo = exports.installLint = void 0;
4140841408
const core = __importStar(__webpack_require__(470));
4140941409
const tc = __importStar(__webpack_require__(533));
41410+
const os_1 = __importDefault(__webpack_require__(87));
4141041411
const path_1 = __importDefault(__webpack_require__(622));
4141141412
const main_1 = __webpack_require__(514);
41413+
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
41414+
const getAssetURL = (versionConfig) => {
41415+
let ext = "tar.gz";
41416+
let platform = os_1.default.platform().toString();
41417+
switch (platform) {
41418+
case "win32":
41419+
platform = "windows";
41420+
ext = "zip";
41421+
break;
41422+
}
41423+
let arch = os_1.default.arch();
41424+
switch (arch) {
41425+
case "x64":
41426+
arch = "amd64";
41427+
break;
41428+
case "x32":
41429+
case "ia32":
41430+
arch = "386";
41431+
break;
41432+
}
41433+
const noPrefix = versionConfig.TargetVersion.slice(1);
41434+
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
41435+
};
4141241436
// The installLint returns path to installed binary of golangci-lint.
4141341437
function installLint(versionConfig) {
4141441438
return __awaiter(this, void 0, void 0, function* () {
4141541439
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
4141641440
const startedAt = Date.now();
41417-
core.info(`Downloading ${versionConfig.AssetURL} ...`);
41418-
const tarGzPath = yield tc.downloadTool(versionConfig.AssetURL);
41419-
const extractedDir = yield tc.extractTar(tarGzPath, process.env.HOME);
41420-
const urlParts = versionConfig.AssetURL.split(`/`);
41421-
const dirName = urlParts[urlParts.length - 1].replace(/\.tar\.gz$/, ``);
41441+
const assetURL = getAssetURL(versionConfig);
41442+
core.info(`Downloading ${assetURL} ...`);
41443+
const archivePath = yield tc.downloadTool(assetURL);
41444+
let extractedDir = "";
41445+
let repl = /\.tar\.gz$/;
41446+
if (assetURL.endsWith("zip")) {
41447+
extractedDir = yield tc.extractZip(archivePath, process.env.HOME);
41448+
repl = /\.zip$/;
41449+
}
41450+
else {
41451+
extractedDir = yield tc.extractTar(archivePath, process.env.HOME);
41452+
}
41453+
const urlParts = assetURL.split(`/`);
41454+
const dirName = urlParts[urlParts.length - 1].replace(repl, ``);
4142241455
const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`);
4142341456
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`);
4142441457
return lintPath;
@@ -42651,12 +42684,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4265142684
step((generator = generator.apply(thisArg, _arguments || [])).next());
4265242685
});
4265342686
};
42687+
var __importDefault = (this && this.__importDefault) || function (mod) {
42688+
return (mod && mod.__esModule) ? mod : { "default": mod };
42689+
};
4265442690
Object.defineProperty(exports, "__esModule", { value: true });
4265542691
exports.saveCache = exports.restoreCache = void 0;
4265642692
const cache = __importStar(__webpack_require__(638));
4265742693
const core = __importStar(__webpack_require__(470));
4265842694
const crypto = __importStar(__webpack_require__(417));
4265942695
const fs = __importStar(__webpack_require__(747));
42696+
const path_1 = __importDefault(__webpack_require__(622));
4266042697
const constants_1 = __webpack_require__(694);
4266142698
const utils = __importStar(__webpack_require__(443));
4266242699
function checksumFile(hashName, path) {
@@ -42669,10 +42706,12 @@ function checksumFile(hashName, path) {
4266942706
});
4267042707
}
4267142708
const pathExists = (path) => __awaiter(void 0, void 0, void 0, function* () { return !!(yield fs.promises.stat(path).catch(() => false)); });
42672-
const getLintCacheDir = () => `${process.env.HOME}/.cache/golangci-lint`;
42709+
const getLintCacheDir = () => {
42710+
return path_1.default.resolve(`${process.env.HOME}/.cache/golangci-lint`);
42711+
};
4267342712
const getCacheDirs = () => {
4267442713
// Not existing dirs are ok here: it works.
42675-
return [getLintCacheDir(), `${process.env.HOME}/.cache/go-build`, `${process.env.HOME}/go/pkg`];
42714+
return [getLintCacheDir(), path_1.default.resolve(`${process.env.HOME}/.cache/go-build`), path_1.default.resolve(`${process.env.HOME}/go/pkg`)];
4267642715
};
4267742716
const getIntervalKey = (invalidationIntervalDays) => {
4267842717
const now = new Date();

dist/run/index.js

+46-7
Original file line numberDiff line numberDiff line change
@@ -41417,18 +41417,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
4141741417
exports.installGo = exports.installLint = void 0;
4141841418
const core = __importStar(__webpack_require__(470));
4141941419
const tc = __importStar(__webpack_require__(533));
41420+
const os_1 = __importDefault(__webpack_require__(87));
4142041421
const path_1 = __importDefault(__webpack_require__(622));
4142141422
const main_1 = __webpack_require__(514);
41423+
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
41424+
const getAssetURL = (versionConfig) => {
41425+
let ext = "tar.gz";
41426+
let platform = os_1.default.platform().toString();
41427+
switch (platform) {
41428+
case "win32":
41429+
platform = "windows";
41430+
ext = "zip";
41431+
break;
41432+
}
41433+
let arch = os_1.default.arch();
41434+
switch (arch) {
41435+
case "x64":
41436+
arch = "amd64";
41437+
break;
41438+
case "x32":
41439+
case "ia32":
41440+
arch = "386";
41441+
break;
41442+
}
41443+
const noPrefix = versionConfig.TargetVersion.slice(1);
41444+
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
41445+
};
4142241446
// The installLint returns path to installed binary of golangci-lint.
4142341447
function installLint(versionConfig) {
4142441448
return __awaiter(this, void 0, void 0, function* () {
4142541449
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
4142641450
const startedAt = Date.now();
41427-
core.info(`Downloading ${versionConfig.AssetURL} ...`);
41428-
const tarGzPath = yield tc.downloadTool(versionConfig.AssetURL);
41429-
const extractedDir = yield tc.extractTar(tarGzPath, process.env.HOME);
41430-
const urlParts = versionConfig.AssetURL.split(`/`);
41431-
const dirName = urlParts[urlParts.length - 1].replace(/\.tar\.gz$/, ``);
41451+
const assetURL = getAssetURL(versionConfig);
41452+
core.info(`Downloading ${assetURL} ...`);
41453+
const archivePath = yield tc.downloadTool(assetURL);
41454+
let extractedDir = "";
41455+
let repl = /\.tar\.gz$/;
41456+
if (assetURL.endsWith("zip")) {
41457+
extractedDir = yield tc.extractZip(archivePath, process.env.HOME);
41458+
repl = /\.zip$/;
41459+
}
41460+
else {
41461+
extractedDir = yield tc.extractTar(archivePath, process.env.HOME);
41462+
}
41463+
const urlParts = assetURL.split(`/`);
41464+
const dirName = urlParts[urlParts.length - 1].replace(repl, ``);
4143241465
const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`);
4143341466
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`);
4143441467
return lintPath;
@@ -42661,12 +42694,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4266142694
step((generator = generator.apply(thisArg, _arguments || [])).next());
4266242695
});
4266342696
};
42697+
var __importDefault = (this && this.__importDefault) || function (mod) {
42698+
return (mod && mod.__esModule) ? mod : { "default": mod };
42699+
};
4266442700
Object.defineProperty(exports, "__esModule", { value: true });
4266542701
exports.saveCache = exports.restoreCache = void 0;
4266642702
const cache = __importStar(__webpack_require__(638));
4266742703
const core = __importStar(__webpack_require__(470));
4266842704
const crypto = __importStar(__webpack_require__(417));
4266942705
const fs = __importStar(__webpack_require__(747));
42706+
const path_1 = __importDefault(__webpack_require__(622));
4267042707
const constants_1 = __webpack_require__(694);
4267142708
const utils = __importStar(__webpack_require__(443));
4267242709
function checksumFile(hashName, path) {
@@ -42679,10 +42716,12 @@ function checksumFile(hashName, path) {
4267942716
});
4268042717
}
4268142718
const pathExists = (path) => __awaiter(void 0, void 0, void 0, function* () { return !!(yield fs.promises.stat(path).catch(() => false)); });
42682-
const getLintCacheDir = () => `${process.env.HOME}/.cache/golangci-lint`;
42719+
const getLintCacheDir = () => {
42720+
return path_1.default.resolve(`${process.env.HOME}/.cache/golangci-lint`);
42721+
};
4268342722
const getCacheDirs = () => {
4268442723
// Not existing dirs are ok here: it works.
42685-
return [getLintCacheDir(), `${process.env.HOME}/.cache/go-build`, `${process.env.HOME}/go/pkg`];
42724+
return [getLintCacheDir(), path_1.default.resolve(`${process.env.HOME}/.cache/go-build`), path_1.default.resolve(`${process.env.HOME}/go/pkg`)];
4268642725
};
4268742726
const getIntervalKey = (invalidationIntervalDays) => {
4268842727
const now = new Date();

src/cache.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as cache from "@actions/cache"
22
import * as core from "@actions/core"
33
import * as crypto from "crypto"
44
import * as fs from "fs"
5+
import path from "path"
56

67
import { Events, State } from "./constants"
78
import * as utils from "./utils/actionUtils"
@@ -18,11 +19,13 @@ function checksumFile(hashName: string, path: string): Promise<string> {
1819

1920
const pathExists = async (path: string): Promise<boolean> => !!(await fs.promises.stat(path).catch(() => false))
2021

21-
const getLintCacheDir = (): string => `${process.env.HOME}/.cache/golangci-lint`
22+
const getLintCacheDir = (): string => {
23+
return path.resolve(`${process.env.HOME}/.cache/golangci-lint`)
24+
}
2225

2326
const getCacheDirs = (): string[] => {
2427
// Not existing dirs are ok here: it works.
25-
return [getLintCacheDir(), `${process.env.HOME}/.cache/go-build`, `${process.env.HOME}/go/pkg`]
28+
return [getLintCacheDir(), path.resolve(`${process.env.HOME}/.cache/go-build`), path.resolve(`${process.env.HOME}/go/pkg`)]
2629
}
2730

2831
const getIntervalKey = (invalidationIntervalDays: number): string => {

src/install.ts

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
import * as core from "@actions/core"
22
import * as tc from "@actions/tool-cache"
3+
import os from "os"
34
import path from "path"
45
import { run as setupGo } from "setup-go/lib/main"
56

67
import { VersionConfig } from "./version"
78

9+
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
10+
11+
const getAssetURL = (versionConfig: VersionConfig): string => {
12+
let ext = "tar.gz"
13+
let platform = os.platform().toString()
14+
switch (platform) {
15+
case "win32":
16+
platform = "windows"
17+
ext = "zip"
18+
break
19+
}
20+
let arch = os.arch()
21+
switch (arch) {
22+
case "x64":
23+
arch = "amd64"
24+
break
25+
case "x32":
26+
case "ia32":
27+
arch = "386"
28+
break
29+
}
30+
const noPrefix = versionConfig.TargetVersion.slice(1)
31+
32+
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
33+
}
34+
835
// The installLint returns path to installed binary of golangci-lint.
936
export async function installLint(versionConfig: VersionConfig): Promise<string> {
1037
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
1138
const startedAt = Date.now()
39+
const assetURL = getAssetURL(versionConfig)
40+
core.info(`Downloading ${assetURL} ...`)
41+
const archivePath = await tc.downloadTool(assetURL)
42+
let extractedDir = ""
43+
let repl = /\.tar\.gz$/
44+
if (assetURL.endsWith("zip")) {
45+
extractedDir = await tc.extractZip(archivePath, process.env.HOME)
46+
repl = /\.zip$/
47+
} else {
48+
extractedDir = await tc.extractTar(archivePath, process.env.HOME)
49+
}
1250

13-
core.info(`Downloading ${versionConfig.AssetURL} ...`)
14-
const tarGzPath = await tc.downloadTool(versionConfig.AssetURL)
15-
const extractedDir = await tc.extractTar(tarGzPath, process.env.HOME)
16-
17-
const urlParts = versionConfig.AssetURL.split(`/`)
18-
const dirName = urlParts[urlParts.length - 1].replace(/\.tar\.gz$/, ``)
51+
const urlParts = assetURL.split(`/`)
52+
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
1953
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
2054
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
2155
return lintPath

0 commit comments

Comments
 (0)