diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9f93c2..0c5f41a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 5a0d3dd..5b24925 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index eeefcdd..9f393ba 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -22,6 +22,7 @@ describe('getInputs', () => { { version: 'v23.0.1', channel: '', + context: '', } as context.Inputs ], [ @@ -29,10 +30,12 @@ describe('getInputs', () => { new Map([ ['version', 'v23.0.0-rc.4'], ['channel', 'test'], + ['context', 'foo'], ]), { version: 'v23.0.0-rc.4', channel: 'test', + context: 'foo', } as context.Inputs ] ])( diff --git a/action.yml b/action.yml index ec77798..a05ed73 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/src/context.ts b/src/context.ts index 2baf83c..717f379 100644 --- a/src/context.ts +++ b/src/context.ts @@ -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') }; } diff --git a/src/main.ts b/src/main.ts index 033f45a..27649c2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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) {