context input

This commit is contained in:
CrazyMax 2023-03-10 01:58:55 +01:00
parent 3dcc76c352
commit e4a53ed864
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
6 changed files with 48 additions and 10 deletions

View File

@ -50,3 +50,27 @@ jobs:
with:
version: v23.0.0-rc.4
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
GitHub Action to set up [Docker CE](https://docs.docker.com/engine/). Works on
Linux, macOS and Windows.
GitHub Action to set up (download and install) [Docker CE](https://docs.docker.com/engine/).
Works on Linux, macOS and Windows.
![Screenshot](.github/setup-docker-action.png)
@ -41,10 +41,11 @@ jobs:
Following inputs can be used as `step.with` keys
| Name | Type | Default | Description |
|-----------|--------|----------|---------------------------------------------------------------------------------------------------|
| `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`). |
| Name | Type | Default | Description |
|-----------|--------|-----------------------|---------------------------------------------------------------------------------------------------|
| `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`). |
| `context` | String | `setup-docker-action` | Docker context name. |
## Contributing

View File

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

View File

@ -1,6 +1,6 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
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'
branding:
icon: 'anchor'
@ -13,6 +13,9 @@ inputs:
channel:
description: 'Docker CE channel. (e.g, stable, edge or test)'
required: false
context:
description: 'Docker context name. (default setup-docker-action)'
required: false
runs:
using: 'node16'

View File

@ -3,11 +3,13 @@ import * as core from '@actions/core';
export interface Inputs {
version: string;
channel: string;
context: string;
}
export function getInputs(): Inputs {
return {
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 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({
runDir: runDir,
version: input.version,
channel: input.channel
version: input.version || 'latest',
channel: input.channel || 'stable',
contextName: input.context || 'setup-docker-action'
});
let toolDir;
if (!(await Docker.isAvailable()) || input.version) {