Skip to content

Commit

Permalink
Merge pull request #46 from crazy-max/metadata-output
Browse files Browse the repository at this point in the history
Add `metadata` output
  • Loading branch information
crazy-max committed Sep 1, 2021
2 parents 98b5dea + a0a1575 commit dcd8d36
Show file tree
Hide file tree
Showing 10 changed files with 7,899 additions and 72 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -21,6 +21,7 @@ ___
* [Usage](#usage)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)

## Usage
Expand Down Expand Up @@ -88,6 +89,14 @@ Following inputs can be used as `step.with` keys
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false`) |
| `set` | List | List of [targets values to override](https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md#set) (eg: `targetpattern.key=value`) |
### outputs
Following outputs are available
| Name | Type | Description |
|-------------------|---------|---------------------------------------|
| `metadata` | JSON | Build result metadata |
## Keep up-to-date with GitHub Dependabot
Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)
Expand Down
34 changes: 33 additions & 1 deletion __tests__/buildx.test.ts
@@ -1,6 +1,38 @@
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
import * as buildx from '../src/buildx';
import * as exec from '@actions/exec';
import * as buildx from '../src/buildx';
import * as context from '../src/context';

const tmpNameSync = path.join('/tmp/.docker-bake-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
const metadata = `{
"containerimage.config.digest": "sha256:059b68a595b22564a1cbc167af369349fdc2ecc1f7bc092c2235cbf601a795fd",
"containerimage.digest": "sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c"
}`;

jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-bake-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});

jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return tmpNameSync;
});

describe('getMetadata', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
console.log(`metadataFile: ${metadataFile}`);
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getMetadata();
console.log(`metadata: ${expected}`);
expect(expected).toEqual(metadata);
});
});

describe('isAvailable', () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -36,6 +36,10 @@ inputs:
description: "List of targets values to override (eg. targetpattern.key=value)"
required: false

outputs:
metadata:
description: 'Build result metadata'

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

0 comments on commit dcd8d36

Please sign in to comment.