Merge pull request #7 from crazy-max/context-input

context input
This commit is contained in:
CrazyMax 2023-03-10 01:35:42 +00:00 committed by GitHub
commit c3a68cbeca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 12 deletions

View File

@ -50,3 +50,27 @@ jobs:
with: with:
version: v23.0.0-rc.4 version: v23.0.0-rc.4
channel: test channel: test
context:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker
uses: ./
with:
version: v23.0.0
context: foo
-
name: Check context
run: |
docker context inspect foo

View File

@ -6,8 +6,8 @@
## About ## About
GitHub Action to set up [Docker CE](https://docs.docker.com/engine/). Works on GitHub Action to set up (download and install) [Docker CE](https://docs.docker.com/engine/).
Linux, macOS and Windows. Works on Linux, macOS and Windows.
![Screenshot](.github/setup-docker-action.png) ![Screenshot](.github/setup-docker-action.png)
@ -42,9 +42,10 @@ jobs:
Following inputs can be used as `step.with` keys Following inputs can be used as `step.with` keys
| Name | Type | Default | Description | | Name | Type | Default | Description |
|-----------|--------|----------|---------------------------------------------------------------------------------------------------| |-----------|--------|-----------------------|---------------------------------------------------------------------------------------------------|
| `version` | String | `latest` | Docker CE version (e.g., `v23.0.1`). | | `version` | String | `latest` | Docker CE version (e.g., `v23.0.1`). |
| `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (e.g, `stable`, `edge` or `test`). | | `channel` | String | `stable` | Docker CE [channel](https://download.docker.com/linux/static/) (e.g, `stable`, `edge` or `test`). |
| `context` | String | `setup-docker-action` | Docker context name. |
## Contributing ## Contributing

View File

@ -22,6 +22,7 @@ describe('getInputs', () => {
{ {
version: 'v23.0.1', version: 'v23.0.1',
channel: '', channel: '',
context: '',
} as context.Inputs } as context.Inputs
], ],
[ [
@ -29,10 +30,12 @@ describe('getInputs', () => {
new Map<string, string>([ new Map<string, string>([
['version', 'v23.0.0-rc.4'], ['version', 'v23.0.0-rc.4'],
['channel', 'test'], ['channel', 'test'],
['context', 'foo'],
]), ]),
{ {
version: 'v23.0.0-rc.4', version: 'v23.0.0-rc.4',
channel: 'test', channel: 'test',
context: 'foo',
} as context.Inputs } as context.Inputs
] ]
])( ])(

View File

@ -1,6 +1,6 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions # https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Docker Setup Docker' name: 'Docker Setup Docker'
description: 'Set up Docker' description: 'Set up Docker for use in GitHub Actions by downloading and installing a version of Docker CE'
author: 'docker' author: 'docker'
branding: branding:
icon: 'anchor' icon: 'anchor'
@ -13,6 +13,9 @@ inputs:
channel: channel:
description: 'Docker CE channel. (e.g, stable, edge or test)' description: 'Docker CE channel. (e.g, stable, edge or test)'
required: false required: false
context:
description: 'Docker context name. (default setup-docker-action)'
required: false
runs: runs:
using: 'node16' using: 'node16'

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -3,11 +3,13 @@ import * as core from '@actions/core';
export interface Inputs { export interface Inputs {
version: string; version: string;
channel: string; channel: string;
context: string;
} }
export function getInputs(): Inputs { export function getInputs(): Inputs {
return { return {
version: core.getInput('version'), version: core.getInput('version'),
channel: core.getInput('channel') channel: core.getInput('channel'),
context: core.getInput('context')
}; };
} }

View File

@ -15,10 +15,15 @@ actionsToolkit.run(
const input: context.Inputs = context.getInputs(); const input: context.Inputs = context.getInputs();
const runDir = path.join(os.homedir(), `setup-docker-action-${uuid.v4()}`); const runDir = path.join(os.homedir(), `setup-docker-action-${uuid.v4()}`);
if (input.context == 'default') {
throw new Error(`'default' context cannot be used.`);
}
const install = new Install({ const install = new Install({
runDir: runDir, runDir: runDir,
version: input.version, version: input.version || 'latest',
channel: input.channel channel: input.channel || 'stable',
contextName: input.context || 'setup-docker-action'
}); });
let toolDir; let toolDir;
if (!(await Docker.isAvailable()) || input.version) { if (!(await Docker.isAvailable()) || input.version) {