Skip to content

Commit

Permalink
Merge pull request #19 from phillipjf/feature/flexible-release
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxstorm committed May 6, 2022
2 parents 6ae45b9 + 65f48ea commit 5ec0ddb
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 77 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
push:
branches:
- master
- 'releases/*'
- "releases/*"

jobs:
crd2pulumi:
strategy:
matrix:
runs-on: [ "ubuntu-latest", "macos-latest" ]
runs-on: ["ubuntu-latest", "macos-latest"]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
Expand All @@ -25,7 +25,7 @@ jobs:
change-aws-credentials:
strategy:
matrix:
runs-on: [ "ubuntu-latest", "macos-latest" ]
runs-on: ["ubuntu-latest", "macos-latest"]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
Expand All @@ -41,8 +41,8 @@ jobs:
tf2pulumi:
strategy:
matrix:
version: ["v0.7.0", "v0.8.0", "latest" ]
runs-on: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
version: ["v0.7.0", "v0.8.0", "latest"]
runs-on: ["ubuntu-latest", "macos-latest", "windows-latest"]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
Expand All @@ -55,3 +55,30 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: tf2pulumi version
tfsec:
strategy:
matrix:
version: ["v1.18.0", "v1.19.0", "latest"]
runs-on: ["ubuntu-latest", "macos-latest", "windows-latest"]
arch: ["amd64"]
include:
- runs-on: "ubuntu-latest"
platform: linux
- runs-on: "macos-latest"
platform: darwin
- runs-on: "windows-latest"
platform: windows
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm run build
- uses: ./
with:
repo: aquasecurity/tfsec
tag: ${{ matrix.version }}
platform: ${{ matrix.platform }}
arch: ${{ matrix.arch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: tfsec --version
82 changes: 72 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,81 @@

This repository contains an action for use with GitHub Actions, which will install any GitHub release into your action environment:

This is especially useful when installing arbitrary Go binaries. It can lookup the latest version, or download a specific tag
This is especially useful when installing arbitrary Go binaries. It can lookup the latest version, or download a specific tag.

## Usage

This action requires a Github Token (`GITHUB_TOKEN`) in the environment to authenticate with.

### Grab the Latest Version

```yaml
# ...
steps:
- name: Install go-task
uses: jaxxstorm/action-install-gh-release@v1.5.0
with: # Grab the latest version
repo: go-task/task
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github token scoped to step
```

### Grab a Specific Tags

```yaml
# ...
jobs:
my_job:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github token scoped to job
steps:
- name: Install tf2pulumi
uses: jaxxstorm/action-install-gh-release@v1.5.0
with: # Grab a specific tag
repo: pulumi/tf2pulumi
tag: v0.7.0
```

### Grab a Specific Platform And/Or Architecture

```yaml
- name: Install go-task
uses: jaxxstorm/action-install-gh-release@release/v1-alpha
with: # Grab the latest version
repo: go-task/task
- name: Install tf2pulumi
uses: jaxxstorm/action-install-gh-release@release/v1-alpha
with: # Grab a specific tag
repo: pulumi/tf2pulumi
tag: v0.7.0
name: my_action

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github token scoped to action

jobs:
my_job:
steps:
- name: Install tfsec
uses: jaxxstorm/action-install-gh-release@v1.5.0
with: # Grab a specific platform and/or architecture
repo: aquasecurity/tfsec
platform: linux
arch: x86-64
```

## Finding a release

By default, this action will lookup the Platform and Architecture of the runner and use those values to interpolate and match a release package. **The release package name is first converted to lowercase**. The match pattern is:

```js
`(osPlatform|osArchs).*(osPlatform|osArchs).*\.(tar\.gz|zip)`;
```

Natively, the action will only match the following platforms: `linux`, `darwin`, `windows`.

Some examples of matches:

- `my_package_linux_x86_64.tar.gz` (or `.zip`)
- `my_package_x86_64_linux.tar.gz` (or `.zip`)
- `my_package.linux.x86_64.tar.gz` (or `.zip`)
- `my_package.x86_64.linux.tar.gz` (or `.zip`)
- `linux_x86_64_my_package.tar.gz` (or `.zip`)
- `x86_64_linux_my_package.tar.gz` (or `.zip`)
- `linux.x86_64.my_package.tar.gz` (or `.zip`)
- `x86_64.linux.my_package.tar.gz` (or `.zip`)
- `linux_x86_64.tar.gz` (or `.zip`)
- `x86_64_linux.tar.gz` (or `.zip`)
- `linux.x86_64.tar.gz` (or `.zip`)
- `x86_64.linux.tar.gz` (or `.zip`)
14 changes: 10 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ inputs:
description: "tag containing binary to install"
default: latest
required: true
platform:
description: "OS Platform to match in release package. Specify this parameter if the repository releases do not follow a normal convention otherwise it will be auto-detected."
required: false
arch:
description: "OS Architecture to match in release package. Specify this parameter if the repository releases do not follow a normal convention otherwise it will be auto-detected."
required: false
branding:
icon: 'archive'
color: 'green'
icon: "archive"
color: "green"
runs:
using: 'node12'
main: 'lib/main.js'
using: "node12"
main: "lib/main.js"
68 changes: 42 additions & 26 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,46 @@ function run() {
throw new Error(`Tag not specified`);
}
const [owner, project] = repo.split("/");
let osPlatform = "";
switch (os.platform()) {
case "linux":
osPlatform = "linux";
break;
case "darwin":
osPlatform = "darwin";
break;
case "win32":
osPlatform = "windows";
break;
default:
core.setFailed("Unsupported operating system - $this action is only released for Darwin, Linux and Windows");
return;
let osMatch = [];
// Determine Platform
let osPlatform = core.getInput("platform");
if (osPlatform === "") {
switch (os.platform()) {
case "linux":
osPlatform = "linux";
break;
case "darwin":
osPlatform = "darwin";
break;
case "win32":
osPlatform = "windows";
break;
default:
core.setFailed("Unsupported operating system - $this action is only released for Darwin, Linux and Windows");
return;
}
}
// set up some arch regexs
let osArch = "";
switch (os.arch()) {
case "x64":
osArch = "(x64|amd64)";
break;
default:
osArch = os.arch();
return;
osMatch.push(osPlatform);
core.info(`==> System reported platform: ${os.platform()}`);
core.info(`==> Using platform: ${osPlatform}`);
// Determine Architecture
let osArch = core.getInput("arch");
if (osArch === "") {
osArch = os.arch();
switch (os.arch()) {
case "x64":
osMatch.push("x86_64", "x64", "amd64");
break;
default:
osMatch.push(os.arch());
return;
}
}
else {
osMatch.push(osArch);
}
core.info(`==> System reported arch: ${os.arch()}`);
core.info(`==> Using arch: ${osArch}`);
let getReleaseUrl;
if (tag === "latest") {
getReleaseUrl = yield octokit.rest.repos.getLatestRelease({
Expand All @@ -102,10 +117,12 @@ function run() {
tag: tag,
});
}
let re = new RegExp(`${osPlatform}.${osArch}.*\.(tar.gz|zip)`);
let osMatchRegexForm = `(${osMatch.join('|')})`;
let re = new RegExp(`${osMatchRegexForm}.*${osMatchRegexForm}.*\.(tar.gz|zip)`);
let asset = getReleaseUrl.data.assets.find(obj => {
core.info(`searching for ${obj.name} with ${re.source}`);
return re.test(obj.name);
let normalized_obj_name = obj.name.toLowerCase();
return re.test(normalized_obj_name);
});
if (!asset) {
const found = getReleaseUrl.data.assets.map(f => f.name);
Expand All @@ -120,7 +137,6 @@ function run() {
core.addPath(extractedPath);
}
catch (error) {
let errorMessage = "Failed to download and extract release";
if (error instanceof Error) {
core.setFailed(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

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

4 changes: 2 additions & 2 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": "action-install-gh-release",
"version": "1.4.0",
"version": "1.6.0",
"private": true,
"description": "Install a GitHub release binary in a GitHub Actions build environment",
"main": "lib/main.js",
Expand Down

0 comments on commit 5ec0ddb

Please sign in to comment.