Skip to content

Commit

Permalink
Merge pull request #44 from jaxxstorm/binaries_support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxstorm authored Mar 13, 2023
2 parents 58384a4 + 9e7ba79 commit 32cdb7d
Show file tree
Hide file tree
Showing 1,077 changed files with 1,603,836 additions and 435,602 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,27 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: grcov --version

wasmer:
strategy:
matrix:
version: [ "latest" ]
runs-on: [ "ubuntu-latest", "macos-latest"]
arch: [ "amd64" ]
include:
- runs-on: "ubuntu-latest"
platform: linux
- runs-on: "macos-latest"
platform: darwin
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm run build
- uses: ./
with:
repo: wasmerio/wasmer
binaries-location: bin
chmod: 0755
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: wasmer --version
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ typings/
.idea

**/.DS_Store

30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is especially useful when installing arbitrary Go binaries. It can lookup t
# ...
steps:
- name: Install go-task
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab the latest version
repo: go-task/task
```
Expand All @@ -23,7 +23,7 @@ steps:
# ...
steps:
- name: Install tf2pulumi
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab a specific tag
repo: pulumi/tf2pulumi
tag: v0.7.0
Expand All @@ -34,7 +34,7 @@ steps:
```yaml
steps:
- name: Install tfsec
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab a specific platform and/or architecture
repo: aquasecurity/tfsec
platform: linux
Expand All @@ -48,7 +48,7 @@ Use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/git
```yaml
steps:
- name: Install private tool
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab from a private repository
token: ${{ secrets.MY_PAT }}
repo: my-org/my-private-repo
Expand All @@ -62,7 +62,7 @@ This action can use [actions/cache](https://github.com/actions/cache) under the
# ...
steps:
- name: Install tf2pulumi
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab a specific tag with caching
repo: pulumi/tf2pulumi
tag: v0.7.0
Expand All @@ -89,7 +89,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github token scoped to job
steps:
- name: Install Mozilla grcov
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab a specific file extension
repo: mozilla/grcov
tag: v0.8.12
Expand All @@ -112,7 +112,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github token scoped to job
steps:
- name: Install Open Telemetry Collector Builder (ocb)
uses: jaxxstorm/action-install-gh-release@v1.5.0
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab a pure binary
repo: open-telemetry/opentelemetry-collector
tag: v0.62.1
Expand All @@ -123,6 +123,22 @@ jobs:

Note the use of the `rename-to` and `chmod` parameters to rename the downloaded binary and make it executable.

### Grab multiple binaries from a specific location

If the archive of the release contains binaries in a specific location, you can
specify it with the `binaries-location` parameter. Note that the path is
relative to the root of the archive. The option `rename-to` has no effect in
this case. The option `chmod` is applied to all binaries.

```yaml
- name: Install the latest Wasmer version
uses: jaxxstorm/[email protected]
with:
repo: wasmerio/wasmer
binaries-location: bin
chmod: 0755
```

## 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:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ inputs:
cache:
description: "When set to 'enable', caches the downloads of known tags with actions/cache"
required: false
binaries-location:
description: "Specify this parameter if the binaries are not located in the root of the release archive. The parameter should be a relative path to the release archive. For example, if the binaries are located in the 'bin' directory of the release archive, the parameter should be 'bin'."
required: false
branding:
icon: "archive"
color: "green"
Expand Down
39 changes: 34 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,19 @@ function run() {
osArch: osArch,
osPlatform: osPlatform
};
// first candidate folder where to find the binaries
// after downloading the release
let dest = toolPath(toolInfo);
// If the user has specified a custom bin location, it means
// that the archive contains a folder with the binaries.
// In this case, we need to use that folder and add it to the path.
let binariesLocation = core.getInput("binaries-location");
let finalBinLocation = dest;
if (binariesLocation !== "") {
core.info(`==> Given bin location: ${binariesLocation}`);
finalBinLocation = path.join(dest, binariesLocation);
}
core.info(`==> Binaries will be located at: ${finalBinLocation}`);
// Look in the cache first.
let cacheKey = cachePrimaryKey(toolInfo);
if (cacheEnabled && cacheKey !== undefined) {
Expand Down Expand Up @@ -192,11 +204,26 @@ function run() {
yield extractFn(binPath, dest);
}
core.info(`Automatically extracted release asset ${asset.name} to ${dest}`);
if (renameTo !== "") {
core.warning("rename-to parameter ignored when installing a release from an archive");
const bins = fs.readdirSync(finalBinLocation, { withFileTypes: true })
.filter(item => item.isFile())
.map(bin => bin.name);
if (bins.length === 0)
throw new Error(`No files found in ${finalBinLocation}`);
else if (bins.length > 1 && renameTo !== "") {
core.warning("rename-to parameter ignored when installing \
a release from an archive that contains multiple files.");
}
if (chmodTo !== "") {
core.warning("chmod parameter ignored when installing a release from an archive");
bins.forEach(bin => {
const binPath = path.join(finalBinLocation, bin);
try {
fs.chmodSync(binPath, chmodTo);
core.info(`chmod'd ${binPath} to ${chmodTo}`);
}
catch (chmodErr) {
core.setFailed(`Failed to chmod ${binPath} to ${chmodTo}: ${chmodErr}`);
}
});
}
}
else {
Expand Down Expand Up @@ -248,8 +275,10 @@ function run() {
}
}
}
core.addPath(dest);
core.info(`Successfully installed ${project} to ${dest}`);
core.info(`Adding ${finalBinLocation} to the path`);
core.addPath(finalBinLocation);
core.info(`Successfully installed ${project}`);
core.info(`Binaries available at ${finalBinLocation}`);
}
catch (error) {
if (error instanceof Error) {
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

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

Loading

0 comments on commit 32cdb7d

Please sign in to comment.