Skip to content

Commit

Permalink
Add setup-buildx action (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Aug 7, 2020
1 parent 836357f commit f2b8a9d
Show file tree
Hide file tree
Showing 20 changed files with 11,823 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/setup-buildx-ci.yml
@@ -0,0 +1,40 @@
name: setup-buildx-ci

on:
push:
paths:
- .github/workflows/setup-buildx-ci.yml
- setup-buildx/**
pull_request:
paths:
- .github/workflows/setup-buildx-ci.yml
- setup-buildx/**

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
buildx-version:
- latest
- v0.2.2
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 Docker Buildx
id: buildx
uses: ./setup-buildx/
with:
buildx-version: ${{ matrix.buildx-version }}
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
32 changes: 32 additions & 0 deletions .github/workflows/setup-buildx-precheckin.yml
@@ -0,0 +1,32 @@
name: setup-buildx-precheckin

on:
push:
paths:
- .github/workflows/setup-buildx-precheckin.yml
- setup-buildx/**
pull_request:
paths:
- .github/workflows/setup-buildx-precheckin.yml
- setup-buildx/**

jobs:
pre-checkin:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Install
run: yarn --cwd ./setup-buildx/ install
-
name: Pre-checkin
run: yarn --cwd ./setup-buildx/ 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-buildx/ run pre-checkin' and push"
fi
32 changes: 32 additions & 0 deletions .github/workflows/setup-buildx-test.yml
@@ -0,0 +1,32 @@
name: setup-buildx-test

on:
push:
paths:
- .github/workflows/setup-buildx-test.yml
- setup-buildx/**
pull_request:
paths:
- .github/workflows/setup-buildx-test.yml
- setup-buildx/**

jobs:
test:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Install
run: yarn install
-
name: Test
run: yarn run test
# -
# name: Upload coverage
# uses: codecov/codecov-action@v1.0.7
# if: success()
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage/clover.xml
15 changes: 15 additions & 0 deletions setup-buildx/.editorconfig
@@ -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 changes: 2 additions & 0 deletions setup-buildx/.gitattributes
@@ -0,0 +1,2 @@
/dist/** linguist-generated=true
/lib/** linguist-generated=true
95 changes: 95 additions & 0 deletions setup-buildx/.gitignore
@@ -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/
11 changes: 11 additions & 0 deletions setup-buildx/.prettierrc.json
@@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
75 changes: 75 additions & 0 deletions setup-buildx/README.md
@@ -0,0 +1,75 @@
## About

GitHub Action to set up Docker [Buildx](https://github.com/docker/buildx).

___

* [Usage](#usage)
* [Quick start](#quick-start)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
* [environment variables](#environment-variables)
* [Limitation](#limitation)

## Usage

### Quick start

```yaml
name: ci

on:
pull_request:
branches: master
push:
branches: master
tags:

jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
id: buildx
uses: docker/action/setup-buildx@v2
with:
buildx-version: latest
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
```

## Customizing

### inputs

Following inputs can be used as `step.with` keys

| Name | Type | Default | Description |
|------------------|---------|-----------|------------------------------------|
| `buildx-version` | String | `latest` | [Buildx](https://github.com/docker/buildx) version. Example: `v0.3.0` |

### outputs

Following outputs are available

| Name | Type | Description |
|---------------|---------|---------------------------------------|
| `platforms` | String | Available platforms (comma separated) |

### environment variables

The following [official docker environment variables](https://docs.docker.com/engine/reference/commandline/cli/#environment-variables) are supported:

| Name | Type | Default | Description |
|-----------------|---------|-------------|-------------------------------------------------|
| `DOCKER_CONFIG` | String | `~/.docker` | The location of your client configuration files |

## 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 changes: 17 additions & 0 deletions setup-buildx/__tests__/github.test.ts
@@ -0,0 +1,17 @@
import * as github from '../src/github';

describe('github', () => {
it('returns latest buildx GitHub release', async () => {
const release = await github.getRelease('latest');
console.log(release);
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});

it('returns v0.2.2 buildx GitHub release', async () => {
const release = await github.getRelease('v0.2.2');
console.log(release);
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.2.2');
});
});
20 changes: 20 additions & 0 deletions setup-buildx/__tests__/installer.test.ts
@@ -0,0 +1,20 @@
import fs = require('fs');
import * as installer from '../src/installer';
import * as path from 'path';
import * as os from 'os';

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-docker-buildx-'));

describe('installer', () => {
it('acquires v0.2.2 version of buildx', async () => {
const buildx = await installer.buildx('v0.2.2', tmpDir);
console.log(buildx);
expect(fs.existsSync(buildx)).toBe(true);
}, 100000);

it('acquires latest version of buildx', async () => {
const buildx = await installer.buildx('latest', tmpDir);
console.log(buildx);
expect(fs.existsSync(buildx)).toBe(true);
}, 100000);
});
22 changes: 22 additions & 0 deletions setup-buildx/action.yml
@@ -0,0 +1,22 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Docker - Setup Buildx'
description: 'GitHub Action to set up Docker Buildx'
author: 'crazy-max'
branding:
color: 'blue'
icon: 'truck'

inputs:
buildx-version:
description: 'Buildx version. Example: v0.3.0'
default: 'latest'
required: false

outputs:
platforms:
description: 'Available platforms (comma separated)'

runs:
using: 'node12'
main: 'dist/index.js'
post: 'dist/index.js'

0 comments on commit f2b8a9d

Please sign in to comment.