Add setup-qemu action (#71)

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-07 11:05:37 +02:00
parent 36c90bc3ab
commit 64d53ac2cf
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
14 changed files with 5770 additions and 0 deletions

36
.github/workflows/setup-qemu-ci.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: setup-qemu-ci
on:
push:
paths:
- .github/workflows/setup-qemu-ci.yml
- setup-qemu/**
pull_request:
paths:
- .github/workflows/setup-qemu-ci.yml
- setup-qemu/**
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
qemu-version:
- latest
- 4.2.0-7
steps:
-
name: Runner info
run: |
sudo apt-get install -y hwinfo
sudo hwinfo --short
sudo mount
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Set up QEMU
uses: ./setup-qemu/
with:
qemu-version: ${{ matrix.qemu-version }}

View File

@ -0,0 +1,32 @@
name: setup-qemu-precheckin
on:
push:
paths:
- .github/workflows/setup-qemu-precheckin.yml
- setup-qemu/**
pull_request:
paths:
- .github/workflows/setup-qemu-precheckin.yml
- setup-qemu/**
jobs:
pre-checkin:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Install
run: yarn --cwd ./setup-qemu/ install
-
name: Pre-checkin
run: yarn --cwd ./setup-qemu/ run pre-checkin
-
name: Check for uncommitted changes
run: |
if [[ `git status --porcelain` ]]; then
git status --porcelain
echo "::warning::Found changes. Please run 'yarn --cwd ./setup-qemu/ run pre-checkin' and push"
fi

15
setup-qemu/.editorconfig Normal file
View 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
setup-qemu/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
/dist/** linguist-generated=true
/lib/** linguist-generated=true

95
setup-qemu/.gitignore vendored Normal file
View File

@ -0,0 +1,95 @@
node_modules
lib
# Jetbrains
/.idea
/*.iml
# 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/

View File

@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

51
setup-qemu/README.md Normal file
View File

@ -0,0 +1,51 @@
## About
GitHub Action to install [QEMU static binaries](https://github.com/multiarch/qemu-user-static).
___
* [Usage](#usage)
* [Quick start](#quick-start)
* [Customizing](#customizing)
* [inputs](#inputs)
* [Limitation](#limitation)
## Usage
```yaml
name: ci
on:
pull_request:
branches: master
push:
branches: master
tags:
jobs:
qemu:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/action/setup-qemu@v2
with:
qemu-version: latest
```
## Customizing
### inputs
Following inputs can be used as `step.with` keys
| Name | Type | Default | Description |
|------------------|---------|-----------|------------------------------------|
| `qemu-version` | String | `latest` | [qemu-user-static](https://github.com/multiarch/qemu-user-static) version (Docker tag). Example: `4.2.0-7` |
## Limitation
This action is only available for Linux [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources).

17
setup-qemu/action.yml Normal file
View File

@ -0,0 +1,17 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Docker - Setup QEMU'
description: 'GitHub Action to install QEMU static binaries'
author: 'crazy-max'
branding:
color: 'blue'
icon: 'truck'
inputs:
qemu-version:
description: 'QEMU static binaries Docker image version. Example: 4.2.0-7'
default: 'latest'
required: false
runs:
using: 'node12'
main: 'dist/index.js'

1654
setup-qemu/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

12
setup-qemu/jest.config.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
setupFiles: ["dotenv/config"],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: false
}

41
setup-qemu/package.json Normal file
View File

@ -0,0 +1,41 @@
{
"name": "docker-setup-qemu",
"description": "GitHub Action to install QEMU static binaries",
"main": "lib/main.js",
"scripts": {
"build": "tsc && ncc build",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"test": "jest --coverage",
"pre-checkin": "yarn run format && yarn run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/docker/action.git",
"directory": "setup-qemu"
},
"keywords": [
"actions",
"docker",
"qemu"
],
"author": "CrazyMax",
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4"
},
"devDependencies": {
"@types/jest": "^26.0.3",
"@types/node": "^14.0.14",
"@zeit/ncc": "^0.22.3",
"dotenv": "^8.2.0",
"jest": "^26.1.0",
"jest-circus": "^26.1.0",
"jest-runtime": "^26.1.0",
"prettier": "^2.0.5",
"ts-jest": "^26.1.1",
"typescript": "^3.9.5",
"typescript-formatter": "^7.2.2"
}
}

31
setup-qemu/src/main.ts Normal file
View File

@ -0,0 +1,31 @@
import * as os from 'os';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run(): Promise<void> {
try {
if (os.platform() !== 'linux') {
core.setFailed('Only supported on linux platform');
return;
}
const qemuVer: string = core.getInput('qemu-version') || 'latest';
core.info(`💎 Installing QEMU static binaries...`);
await exec.exec('docker', [
'run',
'--rm',
'--privileged',
`multiarch/qemu-user-static:${qemuVer}`,
'--reset',
'-p',
'yes',
'--credential',
'yes'
]);
} catch (error) {
core.setFailed(error.message);
}
}
run();

18
setup-qemu/tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"newLine": "lf",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"sourceMap": true
},
"exclude": ["node_modules", "**/*.test.ts"]
}

3755
setup-qemu/yarn.lock Normal file

File diff suppressed because it is too large Load Diff