mirror of
https://github.com/docker/metadata-action.git
synced 2025-06-23 19:27:58 +02:00
Allow to templatize schedule tag (#1)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as dotenv from 'dotenv';
|
||||
import {Inputs} from '../src/context';
|
||||
import * as moment from 'moment';
|
||||
import {getInputs, Inputs} from '../src/context';
|
||||
import * as github from '../src/github';
|
||||
import {Meta} from '../src/meta';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
@ -23,6 +24,10 @@ jest.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => {
|
||||
return '2020-01-10T00:30:00.000Z';
|
||||
});
|
||||
|
||||
jest.mock('moment', () => {
|
||||
return () => jest.requireActual('moment')('2020-01-10T00:30:00.000Z');
|
||||
});
|
||||
|
||||
describe('tags and labels', () => {
|
||||
beforeEach(() => {
|
||||
Object.keys(process.env).forEach(function (key) {
|
||||
@ -38,7 +43,7 @@ describe('tags and labels', () => {
|
||||
'event_null.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
undefined,
|
||||
[],
|
||||
[
|
||||
@ -56,7 +61,7 @@ describe('tags and labels', () => {
|
||||
'event_empty.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
undefined,
|
||||
[],
|
||||
[
|
||||
@ -74,7 +79,7 @@ describe('tags and labels', () => {
|
||||
'event_pull_request.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'pr-2',
|
||||
[
|
||||
'user/app:pr-2'
|
||||
@ -94,7 +99,7 @@ describe('tags and labels', () => {
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'dev',
|
||||
[
|
||||
'user/app:dev'
|
||||
@ -114,7 +119,7 @@ describe('tags and labels', () => {
|
||||
'event_push_defbranch.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'edge',
|
||||
[
|
||||
'user/app:edge'
|
||||
@ -134,7 +139,7 @@ describe('tags and labels', () => {
|
||||
'event_release.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'1.1.1',
|
||||
[
|
||||
'user/app:1.1.1',
|
||||
@ -155,7 +160,7 @@ describe('tags and labels', () => {
|
||||
'event_schedule.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'nightly',
|
||||
[
|
||||
'user/app:nightly'
|
||||
@ -171,11 +176,53 @@ describe('tags and labels', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_schedule.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagSchedule: `{{date 'YYYYMMDD'}}`
|
||||
} as Inputs,
|
||||
'20200110',
|
||||
[
|
||||
'user/app:20200110'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||
"org.opencontainers.image.version=20200110",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_schedule.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagSchedule: `{{date 'YYYYMMDD-HHmmss'}}`
|
||||
} as Inputs,
|
||||
'20200110-003000',
|
||||
[
|
||||
'user/app:20200110-003000'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||
"org.opencontainers.image.version=20200110-003000",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'release1',
|
||||
[
|
||||
'user/app:release1'
|
||||
@ -195,7 +242,7 @@ describe('tags and labels', () => {
|
||||
'event_tag_semver.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'1.1.1',
|
||||
[
|
||||
'user/app:1.1.1',
|
||||
@ -216,7 +263,7 @@ describe('tags and labels', () => {
|
||||
'event_workflow_dispatch.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'edge',
|
||||
[
|
||||
'user/app:edge'
|
||||
@ -236,7 +283,7 @@ describe('tags and labels', () => {
|
||||
'event_pull_request.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'pr-2',
|
||||
[
|
||||
'org/app:pr-2',
|
||||
@ -257,7 +304,7 @@ describe('tags and labels', () => {
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'dev',
|
||||
[
|
||||
'org/app:dev',
|
||||
@ -278,7 +325,7 @@ describe('tags and labels', () => {
|
||||
'event_push_defbranch.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'edge',
|
||||
[
|
||||
'org/app:edge',
|
||||
@ -299,7 +346,7 @@ describe('tags and labels', () => {
|
||||
'event_schedule.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'nightly',
|
||||
[
|
||||
'org/app:nightly',
|
||||
@ -320,7 +367,7 @@ describe('tags and labels', () => {
|
||||
'event_tag_semver.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
},
|
||||
} as Inputs,
|
||||
'1.1.1',
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
@ -344,7 +391,7 @@ describe('tags and labels', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
},
|
||||
} as Inputs,
|
||||
'pr-2',
|
||||
[
|
||||
'org/app:pr-2',
|
||||
@ -368,7 +415,7 @@ describe('tags and labels', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
},
|
||||
} as Inputs,
|
||||
'dev',
|
||||
[
|
||||
'org/app:dev',
|
||||
@ -392,7 +439,7 @@ describe('tags and labels', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
},
|
||||
} as Inputs,
|
||||
'edge',
|
||||
[
|
||||
'org/app:edge',
|
||||
@ -416,7 +463,7 @@ describe('tags and labels', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
},
|
||||
} as Inputs,
|
||||
'nightly',
|
||||
[
|
||||
'org/app:nightly',
|
||||
@ -440,7 +487,7 @@ describe('tags and labels', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
},
|
||||
} as Inputs,
|
||||
'1.1.1',
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
@ -467,7 +514,7 @@ describe('tags and labels', () => {
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
tagEdge: 'dev'
|
||||
},
|
||||
} as Inputs,
|
||||
'edge',
|
||||
[
|
||||
'org/app:edge',
|
||||
@ -492,7 +539,7 @@ describe('tags and labels', () => {
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSha: true,
|
||||
tagEdge: 'dev'
|
||||
},
|
||||
} as Inputs,
|
||||
'master',
|
||||
[
|
||||
'org/app:master',
|
||||
@ -513,24 +560,22 @@ describe('tags and labels', () => {
|
||||
],
|
||||
])('given %p event ', async (envFile, inputs, exVersion, exTags, exLabels) => {
|
||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||
console.log(process.env);
|
||||
|
||||
const context = github.context();
|
||||
console.log(context);
|
||||
console.log(process.env, context);
|
||||
|
||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||
const meta = new Meta(inputs as Inputs, context, repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||
|
||||
const version = meta.version();
|
||||
console.log(version)
|
||||
console.log('version', version);
|
||||
expect(version).toEqual(exVersion);
|
||||
|
||||
const tags = meta.tags();
|
||||
console.log(tags)
|
||||
console.log('tags', tags);
|
||||
expect(tags).toEqual(exTags);
|
||||
|
||||
const labels = meta.labels();
|
||||
console.log(labels)
|
||||
console.log('labels', labels);
|
||||
expect(labels).toEqual(exLabels);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user