move action

This commit is contained in:
Erin Power 2020-02-18 20:07:25 +01:00
parent 99969c2baf
commit 62a3dcac32
No known key found for this signature in database
GPG Key ID: C5B2B187874CE1AC
9 changed files with 2 additions and 165 deletions

View File

@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v1
with:
depth: 50
- uses: ./actions/get-github-release
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded

View File

@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v1
with:
depth: 50
- uses: ./actions/get-github-release
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded

View File

@ -1,42 +0,0 @@
# run-github-release
The `run-github-release` action allows you to run any binary release on GitHub.
See [`actions.yml`] for configuration options.
[`actions.yml`]: ./actions.yml
## Example
This example builds an mdbook project on linux.
```yaml
- uses: rust-lang/simpleinfra/github-actions/run-github-release@master
with:
args: build
regex: unknown-linux-gnu
repo: mdbook
token: "${{ secrets.GITHUB_TOKEN }}"
```
## Development
The action is written in NodeJS 12, and you can install the dependencies with:
```
npm install
```
### Running
```
npm start
```
GitHub Actions requires all the dependencies to be committed, so before
creating a commit you need to run:
```
npm run build
```
The command will bundle everything in `dist/index.js`. That file will need to
be committed.

View File

@ -1,23 +0,0 @@
name: Get GitHub Release
description: Installs the latest binary from GitHub Releases.
inputs:
owner:
description: The owner of the GitHub repository e.g. `rust-lang`
required: true
repo:
description: The name of the repository containing the releases.
required: true
matches:
description: The regex to match against the name of the asset release.
required: true
token:
description: GitHub token for authenication.
required: true
install_path:
description: The path to install the binary. Defaults to /tmp/<repo name>
required: false
runs:
using: node12
main: dist/index.js

File diff suppressed because one or more lines are too long

View File

@ -1,13 +0,0 @@
// GitHub Actions script.
const actions = require('@actions/core')
const { getGitHubRelease } = require('./lib.js')
// Configuration
const repo = actions.getInput('repo', { required: true })
const installPath = actions.getInput('install_path') || undefined
const owner = actions.getInput('owner', { required: true })
const matches = new RegExp(actions.getInput('matches', { required: true }))
const token = actions.getInput('token', { required: true })
getGitHubRelease(owner, repo, matches, token, installPath)

View File

@ -1,51 +0,0 @@
const fs = require('fs')
const path = require('path')
const process = require('process')
const util = require('util')
const writeFile = util.promisify(fs.writeFile)
// Third Party libraries
const core = require('@actions/core')
const exec = require('@actions/exec')
const github = require('@actions/github')
const fetch = require('node-fetch')
/**
* Fetches the latest release from `owner/repo` on GitHub that matches the
* `matches` regular expression, and installs the binary to `installPath`. By
* default the install path is `/tmp/<repo name>`. This function requires a valid
* GitHub `token` that is able to read the repository.
*
* @param {string} owner - The owner of the repository.
* @param {string} repo - The name of the repository
* @param {Regex} matches - The regex to match against the name pick the
* specific asset in the release.
* @param {string} token - A GitHub token, with `read` permissions on
* the repository.
* @param {string} [installPath='/tmp/${repo}'] - The path to install the binary.
*/
exports.getGitHubRelease = async function (owner, repo, matches, token, installPath = `/tmp/${repo}`) {
try {
// Change to be in the installation directory.
process.chdir(path.dirname(installPath))
const octokit = new github.GitHub(token)
const tarFile = `${installPath}.tar.gz`
// Retrieve first release that matched `regex` and download a tar archive of
// the binary.
const url = (await octokit.repos.getLatestRelease({ owner, repo }))
.data
.assets
.find(asset => asset.name.match(matches))
.browser_download_url
await writeFile(tarFile, await (await fetch(url)).buffer())
await exec.exec('tar', ['-xvzf', tarFile])
core.setOutput('install_path', installPath)
return installPath
} catch (error) {
console.log(error)
process.exit(1)
}
}

View File

@ -1,21 +0,0 @@
{
"name": "run-github-release",
"version": "1.0.0",
"description": "Run any GitHub release binary",
"main": "index.js",
"scripts": {
"start": "node index.js",
"build": "node_modules/.bin/ncc build --minify index.js"
},
"author": "",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.1.1",
"@actions/exec": "^1.0.1",
"@actions/github": "^2.0.1",
"node-fetch": "^2.6.0"
},
"devDependencies": {
"@zeit/ncc": "^0.20.5"
}
}

View File

@ -1,12 +0,0 @@
#!/usr/bin/env bash
set -e
INPUT_REPO=mdbook \
INPUT_MATCHES=apple \
INPUT_OWNER=rust-lang \
INPUT_TOKEN=$GITHUB_API_KEY \
RUNNER_TEMP=./node_modules/temp/runner \
RUNNER_TOOL_CACHE=./node_modules/temp/cache \
node index.js
/tmp/mdbook -h