mirror of
https://github.com/crazy-max/ghaction-upx.git
synced 2024-12-21 23:56:08 -07:00
Initial commit
This commit is contained in:
commit
ed73f152fc
15
.editorconfig
Normal file
15
.editorconfig
Normal file
|
@ -0,0 +1,15 @@
|
|||
# This file is for unifying the coding style for different editors and IDEs.
|
||||
# More information at http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/lib/** linguist-detectable=false
|
||||
/node_modules/** linguist-detectable=false
|
32
.github/CONTRIBUTING.md
vendored
Normal file
32
.github/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
## Contributing
|
||||
|
||||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
||||
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork](https://github.com/crazy-max/ghaction-upx/fork) and clone the repository
|
||||
2. Configure and install the dependencies: `npm install`
|
||||
3. Make sure the tests pass on your machine: `npm run test`
|
||||
4. Create a new branch: `git checkout -b my-branch-name`
|
||||
5. Make your change, add tests, and make sure the tests still pass
|
||||
6. Compile your Typescript code: `npm run build`
|
||||
7. Format your code: `npm run format`
|
||||
8. Prune dependencies: `npm prune --production`
|
||||
9. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-upx/compare)
|
||||
10. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||
|
||||
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
||||
|
||||
- Write tests.
|
||||
- Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
|
||||
- We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
|
||||
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as **separate pull requests**.
|
||||
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
||||
|
||||
## Resources
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
|
||||
- [GitHub Help](https://help.github.com)
|
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
github: crazy-max
|
||||
custom: https://www.paypal.me/crazyws
|
37
.github/workflows/uncommited.yml
vendored
Normal file
37
.github/workflows/uncommited.yml
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
name: uncommited
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
# https://github.com/actions/checkout
|
||||
name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
-
|
||||
# https://github.com/actions/setup-node
|
||||
name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
-
|
||||
name: Build
|
||||
run: |
|
||||
npm install
|
||||
npm run format
|
||||
npm run build
|
||||
-
|
||||
name: Prune prod
|
||||
run: |
|
||||
rm -rf node_modules
|
||||
npm install --production
|
||||
-
|
||||
name: Check for uncommitted changes
|
||||
run: |
|
||||
if [[ `git status --porcelain` ]]; then
|
||||
git status --porcelain
|
||||
echo "##[error] found changed files after build. please 'npm run build && npm run format && npm prune --production'"
|
||||
exit 1
|
||||
fi
|
98
.gitignore
vendored
Normal file
98
.gitignore
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
/.dev
|
||||
/dist
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
# Explicitly not ignoring node_modules so that they are included in package downloaded by runner
|
||||
!node_modules/
|
||||
|
||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 CrazyMax
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
59
README.md
Normal file
59
README.md
Normal file
|
@ -0,0 +1,59 @@
|
|||
[![GitHub release](https://img.shields.io/github/release/crazy-max/ghaction-upx.svg?style=flat-square)](https://github.com/crazy-max/ghaction-upx/releases/latest)
|
||||
[![GitHub marketplace](https://img.shields.io/badge/marketplace-upx--github--action-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/upx-github-action)
|
||||
[![Release workflow](https://github.com/crazy-max/ghaction-upx/workflows/release/badge.svg)](https://github.com/crazy-max/ghaction-upx/actions?workflow=release)
|
||||
[![Test workflow](https://github.com/crazy-max/ghaction-upx/workflows/test/badge.svg)](https://github.com/crazy-max/ghaction-upx/actions?workflow=test)
|
||||
[![Become a sponsor](https://img.shields.io/badge/sponsor-crazy--max-181717.svg?logo=github&style=flat-square)](https://github.com/sponsors/crazy-max)
|
||||
[![Paypal Donate](https://img.shields.io/badge/donate-paypal-00457c.svg?logo=paypal&style=flat-square)](https://www.paypal.me/crazyws)
|
||||
|
||||
## ✨ About
|
||||
|
||||
GitHub Action for [UPX](https://github.com/upx/upx), the Ultimate Packer for eXecutables.
|
||||
|
||||
## 🚀 Usage
|
||||
|
||||
Below is a simple snippet to use this action. A [live example](https://github.com/crazy-max/ghaction-upx/actions) is also available for this repository.
|
||||
|
||||
```yaml
|
||||
name: upx
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
upx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@master
|
||||
-
|
||||
name: Run UPX
|
||||
uses: crazy-max/ghaction-upx@master
|
||||
with:
|
||||
version: latest
|
||||
file: ./bin/mybinary
|
||||
args: -fq
|
||||
```
|
||||
|
||||
## 💅 Customizing
|
||||
|
||||
### inputs
|
||||
|
||||
Following inputs can be used as `step.with` keys
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|---------------|---------|-----------|-------------------------------|
|
||||
| `version` | String | `latest` | UPX version. Example: `3.95` |
|
||||
| `file` | String | | File to compress |
|
||||
| `args` | String | | Arguments to pass to UPX |
|
||||
|
||||
## 🤝 How can I help ?
|
||||
|
||||
All kinds of contributions are welcome :raised_hands:! The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon: You can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) :clap: or by making a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely! :rocket:
|
||||
|
||||
Thanks again for your support, it is much appreciated! :pray:
|
||||
|
||||
## 📝 License
|
||||
|
||||
MIT. See `LICENSE` for more details.
|
14
__tests__/installer.test.ts
Normal file
14
__tests__/installer.test.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import fs = require('fs');
|
||||
import * as installer from '../src/installer';
|
||||
|
||||
describe('installer', () => {
|
||||
it('acquires 3.95 version of UPX', async () => {
|
||||
const upx = await installer.getUPX('3.95');
|
||||
expect(fs.existsSync(upx)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires latest version of UPX', async () => {
|
||||
const upx = await installer.getUPX('latest');
|
||||
expect(fs.existsSync(upx)).toBe(true);
|
||||
}, 100000);
|
||||
});
|
21
action.yml
Normal file
21
action.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
name: 'UPX Action'
|
||||
description: 'GitHub Action for UPX, the Ultimate Packer for eXecutables'
|
||||
author: 'crazy-max'
|
||||
branding:
|
||||
color: 'yellow'
|
||||
icon: 'trending-down'
|
||||
|
||||
inputs:
|
||||
version:
|
||||
description: 'UPX version. Example: 3.95'
|
||||
default: 'latest'
|
||||
file:
|
||||
description: 'File to compress'
|
||||
required: true
|
||||
args:
|
||||
description: 'Arguments to pass to UPX'
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
11
jest.config.js
Normal file
11
jest.config.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
79
lib/installer.js
Normal file
79
lib/installer.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const decompress = require("decompress");
|
||||
const decompresstarxz = require("decompress-tarxz");
|
||||
const download = __importStar(require("download"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const util = __importStar(require("util"));
|
||||
const restm = __importStar(require("typed-rest-client/RestClient"));
|
||||
let osPlat = os.platform();
|
||||
let osArch = os.arch();
|
||||
function getUPX(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const selected = yield determineVersion(version);
|
||||
if (selected) {
|
||||
version = selected;
|
||||
}
|
||||
console.log(`✅ UPX version found: ${version}`);
|
||||
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'upx-'));
|
||||
const fileName = getFileName(version);
|
||||
const downloadUrl = util.format('https://github.com/upx/upx/releases/download/v%s/%s', version, fileName);
|
||||
console.log(`⬇️ Downloading ${downloadUrl}...`);
|
||||
yield download.default(downloadUrl, tmpdir, { filename: fileName });
|
||||
console.log('📦 Extracting UPX...');
|
||||
if (osPlat == 'win32') {
|
||||
yield decompress(`${tmpdir}/${fileName}`, tmpdir, { strip: 1 });
|
||||
}
|
||||
else {
|
||||
yield decompresstarxz(`${tmpdir}/${fileName}`, tmpdir, { strip: 1 });
|
||||
}
|
||||
return path.join(tmpdir, osPlat == 'win32' ? 'upx.exe' : 'upx');
|
||||
});
|
||||
}
|
||||
exports.getUPX = getUPX;
|
||||
function getFileName(version) {
|
||||
let platform = '';
|
||||
if (osPlat == 'win32') {
|
||||
platform = osArch == 'x64' ? 'win64' : 'win32';
|
||||
}
|
||||
else if (osPlat == 'linux') {
|
||||
platform = osArch == 'x64' ? 'amd64_linux' : 'i386_linux';
|
||||
}
|
||||
const ext = osPlat == 'win32' ? 'zip' : 'tar.xz';
|
||||
return util.format('upx-%s-%s.%s', version, platform, ext);
|
||||
}
|
||||
function determineVersion(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let rest = new restm.RestClient('ghaction-upx', 'https://github.com', undefined, {
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
});
|
||||
if (version !== 'latest') {
|
||||
version = `v${version}`;
|
||||
}
|
||||
let res = yield rest.get(`/upx/upx/releases/${version}`);
|
||||
if (res.statusCode != 200 || res.result === null) {
|
||||
throw new Error(`Cannot find UPX ${version} release (http ${res.statusCode})`);
|
||||
}
|
||||
return res.result.tag_name.replace(/^v/, '');
|
||||
});
|
||||
}
|
44
lib/main.js
Normal file
44
lib/main.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const installer = __importStar(require("./installer"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
function run(silent) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const version = core.getInput('version') || 'latest';
|
||||
const file = core.getInput('file', { required: true });
|
||||
const args = core.getInput('args');
|
||||
const upx = yield installer.getUPX(version);
|
||||
if (!fs.existsSync(file)) {
|
||||
core.setFailed(`⛔ File to compress not found: ${file}`);
|
||||
}
|
||||
console.log('🏃 Running UPX...');
|
||||
yield exec.exec(`${upx} ${args} ${file}`, undefined, {
|
||||
silent: silent
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.run = run;
|
||||
run();
|
6189
package-lock.json
generated
Normal file
6189
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
44
package.json
Normal file
44
package.json
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "upx-github-action",
|
||||
"description": "GitHub Action for UPX, the Ultimate Packer for eXecutables",
|
||||
"main": "lib/main.js",
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"prune": "npm prune --production"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/crazy-max/ghaction-upx.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"upx"
|
||||
],
|
||||
"author": "CrazyMax",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.1.1",
|
||||
"@actions/exec": "^1.0.1",
|
||||
"decompress": "^4.2.0",
|
||||
"decompress-tarxz": "^3.0.0",
|
||||
"download": "^7.1.0",
|
||||
"typed-rest-client": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/node": "^12.0.4",
|
||||
"@types/decompress": "^4.2.3",
|
||||
"@types/download": "^6.2.4",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"prettier": "^1.17.1",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.5.1",
|
||||
"typescript-formatter": "^7.2.2"
|
||||
}
|
||||
}
|
38
src/decompress-tarxz.d.ts
vendored
Normal file
38
src/decompress-tarxz.d.ts
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
export = decompresstarxz;
|
||||
|
||||
declare function decompresstarxz(
|
||||
input: string | Buffer,
|
||||
output?: string | decompresstarxz.DecompressOptions,
|
||||
opts?: decompresstarxz.DecompressOptions
|
||||
): Promise<decompresstarxz.File[]>;
|
||||
|
||||
declare namespace decompresstarxz {
|
||||
interface File {
|
||||
data: Buffer;
|
||||
mode: number;
|
||||
mtime: string;
|
||||
path: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface DecompressOptions {
|
||||
/**
|
||||
* Filter out files before extracting
|
||||
*/
|
||||
filter?(file: File): boolean;
|
||||
/**
|
||||
* Map files before extracting
|
||||
*/
|
||||
map?(file: File): File;
|
||||
/**
|
||||
* Array of plugins to use.
|
||||
* Default: [decompressTar(), decompressTarbz2(), decompressTargz(), decompressUnzip()]
|
||||
*/
|
||||
plugins?: any[];
|
||||
/**
|
||||
* Remove leading directory components from extracted files.
|
||||
* Default: 0
|
||||
*/
|
||||
strip?: number;
|
||||
}
|
||||
}
|
69
src/installer.ts
Normal file
69
src/installer.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import decompress = require('decompress');
|
||||
import decompresstarxz = require('decompress-tarxz');
|
||||
import * as download from 'download';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as restm from 'typed-rest-client/RestClient';
|
||||
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = os.arch();
|
||||
|
||||
export async function getUPX(version: string): Promise<string> {
|
||||
const selected = await determineVersion(version);
|
||||
if (selected) {
|
||||
version = selected;
|
||||
}
|
||||
|
||||
console.log(`✅ UPX version found: ${version}`);
|
||||
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'upx-'));
|
||||
const fileName = getFileName(version);
|
||||
const downloadUrl = util.format('https://github.com/upx/upx/releases/download/v%s/%s', version, fileName);
|
||||
|
||||
console.log(`⬇️ Downloading ${downloadUrl}...`);
|
||||
await download.default(downloadUrl, tmpdir, {filename: fileName});
|
||||
|
||||
console.log('📦 Extracting UPX...');
|
||||
if (osPlat == 'win32') {
|
||||
await decompress(`${tmpdir}/${fileName}`, tmpdir, {strip: 1});
|
||||
} else {
|
||||
await decompresstarxz(`${tmpdir}/${fileName}`, tmpdir, {strip: 1});
|
||||
}
|
||||
|
||||
return path.join(tmpdir, osPlat == 'win32' ? 'upx.exe' : 'upx');
|
||||
}
|
||||
|
||||
function getFileName(version: string): string {
|
||||
let platform: string = '';
|
||||
if (osPlat == 'win32') {
|
||||
platform = osArch == 'x64' ? 'win64' : 'win32';
|
||||
} else if (osPlat == 'linux') {
|
||||
platform = osArch == 'x64' ? 'amd64_linux' : 'i386_linux';
|
||||
}
|
||||
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.xz';
|
||||
return util.format('upx-%s-%s.%s', version, platform, ext);
|
||||
}
|
||||
|
||||
interface GitHubRelease {
|
||||
tag_name: string;
|
||||
}
|
||||
|
||||
async function determineVersion(version: string): Promise<string> {
|
||||
let rest: restm.RestClient = new restm.RestClient('ghaction-upx', 'https://github.com', undefined, {
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (version !== 'latest') {
|
||||
version = `v${version}`;
|
||||
}
|
||||
|
||||
let res: restm.IRestResponse<GitHubRelease> = await rest.get<GitHubRelease>(`/upx/upx/releases/${version}`);
|
||||
if (res.statusCode != 200 || res.result === null) {
|
||||
throw new Error(`Cannot find UPX ${version} release (http ${res.statusCode})`);
|
||||
}
|
||||
|
||||
return res.result.tag_name.replace(/^v/, '');
|
||||
}
|
26
src/main.ts
Normal file
26
src/main.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import * as installer from './installer';
|
||||
import * as fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
export async function run(silent?: boolean) {
|
||||
try {
|
||||
const version = core.getInput('version') || 'latest';
|
||||
const file = core.getInput('file', {required: true});
|
||||
const args = core.getInput('args');
|
||||
const upx = await installer.getUPX(version);
|
||||
|
||||
if (!fs.existsSync(file)) {
|
||||
core.setFailed(`⛔ File to compress not found: ${file}`);
|
||||
}
|
||||
|
||||
console.log('🏃 Running UPX...');
|
||||
await exec.exec(`${upx} ${args} ${file}`, undefined, {
|
||||
silent: silent
|
||||
});
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user