Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e5622373a3 | ||
|
aad230bbd9 | ||
|
6d7c94a41e | ||
|
52100c89dd | ||
|
9a42503205 | ||
|
a2e02890a0 | ||
|
59e3d70a23 | ||
|
5220b23112 | ||
|
8d0937e440 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -162,7 +162,7 @@ jobs:
|
|||||||
labels: |
|
labels: |
|
||||||
maintainer=CrazyMax
|
maintainer=CrazyMax
|
||||||
org.opencontainers.image.title=MyCustomTitle
|
org.opencontainers.image.title=MyCustomTitle
|
||||||
org.opencontainers.image.description=Another description
|
org.opencontainers.image.description=this is a "good" example
|
||||||
org.opencontainers.image.vendor=MyCompany
|
org.opencontainers.image.vendor=MyCompany
|
||||||
|
|
||||||
json:
|
json:
|
||||||
|
14
README.md
14
README.md
@@ -404,12 +404,13 @@ attribute.
|
|||||||
| `v1.2.3` | `v{{major}}` | `v1` |
|
| `v1.2.3` | `v{{major}}` | `v1` |
|
||||||
| `v1.2.3` | `{{minor}}` | `2` |
|
| `v1.2.3` | `{{minor}}` | `2` |
|
||||||
| `v1.2.3` | `{{patch}}` | `3` |
|
| `v1.2.3` | `{{patch}}` | `3` |
|
||||||
| `v2.0.8-beta.67` | `{{raw}}` | `2.0.8-beta.67`* |
|
| `v2.0.8-beta.67` | `{{raw}}` | `v2.0.8-beta.67` |
|
||||||
| `v2.0.8-beta.67` | `{{version}}` | `2.0.8-beta.67` |
|
| `v2.0.8-beta.67` | `{{version}}` | `2.0.8-beta.67` |
|
||||||
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | `2.0.8-beta.67`* |
|
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | `2.0.8-beta.67`* |
|
||||||
|
|
||||||
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag because they are updated frequently,
|
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` (or `{{raw}}` if specified) as tag
|
||||||
> and contain many breaking changes that are (by the author's design) not yet fit for public consumption.
|
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
|
||||||
|
> not yet fit for public consumption.
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -446,15 +447,16 @@ custom value through `value` attribute.
|
|||||||
| `v1.2.3` | `{{version}}` | `1.2.3` |
|
| `v1.2.3` | `{{version}}` | `1.2.3` |
|
||||||
| `1.2.3` | `{{major}}.{{minor}}` | `1.2` |
|
| `1.2.3` | `{{major}}.{{minor}}` | `1.2` |
|
||||||
| `1.2.3` | `v{{major}}` | `v1` |
|
| `1.2.3` | `v{{major}}` | `v1` |
|
||||||
| `1.2.3rc2` | `{{raw}}` | `1.2.3rc2`* |
|
| `v1.2.3rc2` | `{{raw}}` | `v1.2.3rc2` |
|
||||||
| `1.2.3rc2` | `{{version}}` | `1.2.3rc2` |
|
| `1.2.3rc2` | `{{version}}` | `1.2.3rc2` |
|
||||||
| `1.2.3rc2` | `{{major}}.{{minor}}` | `1.2.3rc2`* |
|
| `1.2.3rc2` | `{{major}}.{{minor}}` | `1.2.3rc2`* |
|
||||||
| `1.2.3post1` | `{{major}}.{{minor}}` | `1.2.3.post1`* |
|
| `1.2.3post1` | `{{major}}.{{minor}}` | `1.2.3.post1`* |
|
||||||
| `1.2.3beta2` | `{{major}}.{{minor}}` | `1.2.3b2`* |
|
| `1.2.3beta2` | `{{major}}.{{minor}}` | `1.2.3b2`* |
|
||||||
| `1.0dev4` | `{{major}}.{{minor}}` | `1.0.dev4`* |
|
| `1.0dev4` | `{{major}}.{{minor}}` | `1.0.dev4`* |
|
||||||
|
|
||||||
> *dev/pre/post release will only extend `{{version}}` as tag because they are updated frequently,
|
> *dev/pre/post release will only extend `{{version}}` (or `{{raw}}` if specified) as tag
|
||||||
> and contain many breaking changes that are (by the author's design) not yet fit for public consumption.
|
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
|
||||||
|
> not yet fit for public consumption.
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
|
@@ -16,63 +16,54 @@ describe('getInputList', () => {
|
|||||||
it('single line correctly', async () => {
|
it('single line correctly', async () => {
|
||||||
await setInput('foo', 'bar');
|
await setInput('foo', 'bar');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar']);
|
expect(res).toEqual(['bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('multiline correctly', async () => {
|
it('multiline correctly', async () => {
|
||||||
setInput('foo', 'bar\nbaz');
|
setInput('foo', 'bar\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('empty lines correctly', async () => {
|
it('empty lines correctly', async () => {
|
||||||
setInput('foo', 'bar\n\nbaz');
|
setInput('foo', 'bar\n\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('comma correctly', async () => {
|
it('comma correctly', async () => {
|
||||||
setInput('foo', 'bar,baz');
|
setInput('foo', 'bar,baz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('empty result correctly', async () => {
|
it('empty result correctly', async () => {
|
||||||
setInput('foo', 'bar,baz,');
|
setInput('foo', 'bar,baz,');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines correctly', async () => {
|
it('different new lines correctly', async () => {
|
||||||
setInput('foo', 'bar\r\nbaz');
|
setInput('foo', 'bar\r\nbaz');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
expect(res).toEqual(['bar', 'baz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines and comma correctly', async () => {
|
it('different new lines and comma correctly', async () => {
|
||||||
setInput('foo', 'bar\r\nbaz,bat');
|
setInput('foo', 'bar\r\nbaz,bat');
|
||||||
const res = await context.getInputList('foo');
|
const res = await context.getInputList('foo');
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['bar', 'baz', 'bat']);
|
expect(res).toEqual(['bar', 'baz', 'bat']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('multiline and ignoring comma correctly', async () => {
|
it('multiline and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
||||||
const res = await context.getInputList('cache-from', true);
|
const res = await context.getInputList('cache-from', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines and ignoring comma correctly', async () => {
|
it('different new lines and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
||||||
const res = await context.getInputList('cache-from', true);
|
const res = await context.getInputList('cache-from', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -86,7 +77,6 @@ ccccccccc"
|
|||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
@@ -110,7 +100,6 @@ bbbb
|
|||||||
ccc"`
|
ccc"`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
@@ -134,7 +123,6 @@ ccccccccc
|
|||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -148,7 +136,6 @@ ccccccccc"
|
|||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
|
23
__tests__/fixtures/event_tag_v1.2.3rc2.env
Normal file
23
__tests__/fixtures/event_tag_v1.2.3rc2.env
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
GITHUB_ACTION=crazy-maxghaction-dump-context
|
||||||
|
GITHUB_ACTIONS=true
|
||||||
|
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
|
||||||
|
GITHUB_ACTOR=crazy-max
|
||||||
|
GITHUB_API_URL=https://api.github.com
|
||||||
|
GITHUB_BASE_REF=
|
||||||
|
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_6ee180c2-b331-434a-a867-89534cbefd83
|
||||||
|
GITHUB_EVENT_NAME=push
|
||||||
|
#GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
|
||||||
|
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
|
||||||
|
GITHUB_HEAD_REF=
|
||||||
|
GITHUB_JOB=event
|
||||||
|
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_6ee180c2-b331-434a-a867-89534cbefd83
|
||||||
|
GITHUB_REF=refs/tags/v1.2.3rc2
|
||||||
|
GITHUB_REPOSITORY=crazy-max/test-docker-action
|
||||||
|
GITHUB_REPOSITORY_OWNER=crazy-max
|
||||||
|
GITHUB_RETENTION_DAYS=90
|
||||||
|
GITHUB_RUN_ID=325968230
|
||||||
|
GITHUB_RUN_NUMBER=4
|
||||||
|
GITHUB_SERVER_URL=https://github.com
|
||||||
|
GITHUB_SHA=90dd6032fac8bda1b6c4436a2e65de27961ed071
|
||||||
|
GITHUB_WORKFLOW=event
|
||||||
|
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action
|
@@ -168,7 +168,6 @@ describe('transform', () => {
|
|||||||
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const flavor = Transform(inputs);
|
const flavor = Transform(inputs);
|
||||||
console.log(flavor);
|
|
||||||
expect(flavor).toEqual(expected);
|
expect(flavor).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
|
@@ -8,7 +8,6 @@ jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetRespons
|
|||||||
describe('repo', () => {
|
describe('repo', () => {
|
||||||
it('returns GitHub repository', async () => {
|
it('returns GitHub repository', async () => {
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
console.log(repo);
|
|
||||||
expect(repo.name).not.toBeNull();
|
expect(repo.name).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -31,24 +31,33 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isRawStatement', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
['{{ raw }}.{{ version }}', false],
|
||||||
|
['{{ version }},{{raw }.', false],
|
||||||
|
['{{ raw }}', true],
|
||||||
|
['{{ raw}}', true],
|
||||||
|
['{{raw}}', true],
|
||||||
|
])('given %p pattern ', async (pattern: string, expected: boolean) => {
|
||||||
|
expect(Meta.isRawStatement(pattern)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabels: Array<string>) => {
|
const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabels: Array<string>) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const version = meta.version;
|
const version = meta.version;
|
||||||
console.log('version', version);
|
|
||||||
expect(version).toEqual(exVersion);
|
expect(version).toEqual(exVersion);
|
||||||
|
|
||||||
const tags = meta.getTags();
|
const tags = meta.getTags();
|
||||||
console.log('tags', tags);
|
|
||||||
expect(tags).toEqual(exTags);
|
expect(tags).toEqual(exTags);
|
||||||
|
|
||||||
const labels = meta.getLabels();
|
const labels = meta.getLabels();
|
||||||
console.log('labels', labels);
|
|
||||||
expect(labels).toEqual(exLabels);
|
expect(labels).toEqual(exLabels);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1662,6 +1671,67 @@ describe('tag', () => {
|
|||||||
"org.opencontainers.image.licenses=MIT"
|
"org.opencontainers.image.licenses=MIT"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'tag31',
|
||||||
|
'event_tag_v2.0.8-beta.67.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tags: [
|
||||||
|
`type=semver,pattern={{raw}}`
|
||||||
|
]
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
main: 'v2.0.8-beta.67',
|
||||||
|
partial: [],
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:v2.0.8-beta.67',
|
||||||
|
'ghcr.io/user/app:v2.0.8-beta.67'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"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",
|
||||||
|
"org.opencontainers.image.version=v2.0.8-beta.67",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'tag32',
|
||||||
|
'event_tag_v1.2.3rc2.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tags: [
|
||||||
|
`type=pep440,pattern={{raw}}`,
|
||||||
|
`type=pep440,pattern={{major}}.{{minor}}`
|
||||||
|
]
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
main: 'v1.2.3rc2',
|
||||||
|
partial: ['1.2.3rc2'],
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:v1.2.3rc2',
|
||||||
|
'org/app:1.2.3rc2',
|
||||||
|
'ghcr.io/user/app:v1.2.3rc2',
|
||||||
|
'ghcr.io/user/app:1.2.3rc2'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"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",
|
||||||
|
"org.opencontainers.image.version=v1.2.3rc2",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %p with %p event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1921,7 +1991,7 @@ describe('latest', () => {
|
|||||||
labels: [
|
labels: [
|
||||||
"maintainer=CrazyMax",
|
"maintainer=CrazyMax",
|
||||||
"org.opencontainers.image.title=MyCustomTitle",
|
"org.opencontainers.image.title=MyCustomTitle",
|
||||||
"org.opencontainers.image.description=Another description",
|
`org.opencontainers.image.description=this is a "good" example`,
|
||||||
"org.opencontainers.image.vendor=MyCompany",
|
"org.opencontainers.image.vendor=MyCompany",
|
||||||
]
|
]
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
@@ -1945,7 +2015,7 @@ describe('latest', () => {
|
|||||||
"org.opencontainers.image.licenses=MIT",
|
"org.opencontainers.image.licenses=MIT",
|
||||||
"maintainer=CrazyMax",
|
"maintainer=CrazyMax",
|
||||||
"org.opencontainers.image.title=MyCustomTitle",
|
"org.opencontainers.image.title=MyCustomTitle",
|
||||||
"org.opencontainers.image.description=Another description",
|
`org.opencontainers.image.description=this is a "good" example`,
|
||||||
"org.opencontainers.image.vendor=MyCompany"
|
"org.opencontainers.image.vendor=MyCompany"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@@ -3152,13 +3222,11 @@ describe('json', () => {
|
|||||||
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: {}) => {
|
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: {}) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const jsonOutput = meta.getJSON();
|
const jsonOutput = meta.getJSON();
|
||||||
console.log('json', jsonOutput);
|
|
||||||
expect(jsonOutput).toEqual(exJSON);
|
expect(jsonOutput).toEqual(exJSON);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -3459,13 +3527,11 @@ describe('bake', () => {
|
|||||||
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: {}) => {
|
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: {}) => {
|
||||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
const context = github.context();
|
const context = github.context();
|
||||||
console.log(process.env, context);
|
|
||||||
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const bakeFile = meta.getBakeFile();
|
const bakeFile = meta.getBakeFile();
|
||||||
console.log('bakeFile', bakeFile, fs.readFileSync(bakeFile, 'utf8'));
|
|
||||||
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
|
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -99,7 +99,6 @@ describe('transform', () => {
|
|||||||
])('given %p', async (l: string[], expected: Tag[], invalid: boolean) => {
|
])('given %p', async (l: string[], expected: Tag[], invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const tags = Transform(l);
|
const tags = Transform(l);
|
||||||
console.log(tags);
|
|
||||||
expect(tags).toEqual(expected);
|
expect(tags).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
@@ -429,7 +428,6 @@ describe('parse', () => {
|
|||||||
])('given %p event ', async (s: string, expected: Tag, invalid: boolean) => {
|
])('given %p event ', async (s: string, expected: Tag, invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const tag = Parse(s);
|
const tag = Parse(s);
|
||||||
console.log(tag);
|
|
||||||
expect(tag).toEqual(expected);
|
expect(tag).toEqual(expected);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
|
27
dist/index.js
generated
vendored
27
dist/index.js
generated
vendored
@@ -74,6 +74,7 @@ function getInputList(name, ignoreComma) {
|
|||||||
}
|
}
|
||||||
for (let output of sync_1.default(items, {
|
for (let output of sync_1.default(items, {
|
||||||
columns: false,
|
columns: false,
|
||||||
|
relax: true,
|
||||||
relaxColumnCount: true,
|
relaxColumnCount: true,
|
||||||
skipLinesWithEmptyValues: true
|
skipLinesWithEmptyValues: true
|
||||||
})) {
|
})) {
|
||||||
@@ -525,7 +526,12 @@ class Meta {
|
|||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
@@ -551,7 +557,12 @@ class Meta {
|
|||||||
let latest = false;
|
let latest = false;
|
||||||
const pver = pep440.explain(vraw);
|
const pver = pep440.explain(vraw);
|
||||||
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
|
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
|
||||||
vraw = this.setValue(pep440.clean(vraw), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(vraw, tag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vraw = this.setValue(pep440.clean(vraw), tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])({
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])({
|
||||||
@@ -670,6 +681,18 @@ class Meta {
|
|||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
static isRawStatement(pattern) {
|
||||||
|
try {
|
||||||
|
const hp = handlebars.parseWithoutProcessing(pattern);
|
||||||
|
if (hp.body.length == 1 && hp.body[0].type == 'MustacheStatement') {
|
||||||
|
return hp.body[0]['path']['parts'].length == 1 && hp.body[0]['path']['parts'][0] == 'raw';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
setValue(val, tag) {
|
setValue(val, tag) {
|
||||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||||
|
@@ -31,6 +31,7 @@ target "build-validate" {
|
|||||||
inherits = ["node-version"]
|
inherits = ["node-version"]
|
||||||
dockerfile = "./hack/build.Dockerfile"
|
dockerfile = "./hack/build.Dockerfile"
|
||||||
target = "build-validate"
|
target = "build-validate"
|
||||||
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "format" {
|
target "format" {
|
||||||
@@ -44,24 +45,26 @@ target "format-validate" {
|
|||||||
inherits = ["node-version"]
|
inherits = ["node-version"]
|
||||||
dockerfile = "./hack/build.Dockerfile"
|
dockerfile = "./hack/build.Dockerfile"
|
||||||
target = "format-validate"
|
target = "format-validate"
|
||||||
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "vendor-update" {
|
target "vendor-update" {
|
||||||
inherits = ["node-version"]
|
inherits = ["node-version"]
|
||||||
dockerfile = "./hack/vendor.Dockerfile"
|
dockerfile = "./hack/build.Dockerfile"
|
||||||
target = "update"
|
target = "vendor-update"
|
||||||
output = ["."]
|
output = ["."]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "vendor-validate" {
|
target "vendor-validate" {
|
||||||
inherits = ["node-version"]
|
inherits = ["node-version"]
|
||||||
dockerfile = "./hack/vendor.Dockerfile"
|
dockerfile = "./hack/build.Dockerfile"
|
||||||
target = "validate"
|
target = "vendor-validate"
|
||||||
|
output = ["type=cacheonly"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "test" {
|
target "test" {
|
||||||
inherits = ["node-version"]
|
inherits = ["node-version"]
|
||||||
dockerfile = "./hack/test.Dockerfile"
|
dockerfile = "./hack/build.Dockerfile"
|
||||||
target = "test-coverage"
|
target = "test-coverage"
|
||||||
output = ["./coverage"]
|
output = ["./coverage"]
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
# syntax=docker/dockerfile:1.2
|
# syntax=docker/dockerfile:1.3-labs
|
||||||
|
|
||||||
ARG NODE_VERSION
|
ARG NODE_VERSION
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
FROM node:${NODE_VERSION}-alpine AS base
|
||||||
@@ -8,7 +9,22 @@ WORKDIR /src
|
|||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn install
|
yarn install && mkdir /vendor && cp yarn.lock /vendor
|
||||||
|
|
||||||
|
FROM scratch AS vendor-update
|
||||||
|
COPY --from=deps /vendor /
|
||||||
|
|
||||||
|
FROM deps AS vendor-validate
|
||||||
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
|
set -e
|
||||||
|
git add -A
|
||||||
|
cp -rf /vendor/* .
|
||||||
|
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
|
||||||
|
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'
|
||||||
|
git status --porcelain -- yarn.lock
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
EOT
|
||||||
|
|
||||||
FROM deps AS build
|
FROM deps AS build
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
@@ -19,13 +35,16 @@ FROM scratch AS build-update
|
|||||||
COPY --from=build /out /
|
COPY --from=build /out /
|
||||||
|
|
||||||
FROM build AS build-validate
|
FROM build AS build-validate
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
git add -A && cp -rf /out/* .; \
|
set -e
|
||||||
if [ -n "$(git status --porcelain -- dist)" ]; then \
|
git add -A
|
||||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \
|
cp -rf /out/* .
|
||||||
git status --porcelain -- dist; \
|
if [ -n "$(git status --porcelain -- dist)" ]; then
|
||||||
exit 1; \
|
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
||||||
fi
|
git status --porcelain -- dist
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
EOT
|
||||||
|
|
||||||
FROM deps AS format
|
FROM deps AS format
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
@@ -39,4 +58,14 @@ COPY --from=format /out /
|
|||||||
FROM deps AS format-validate
|
FROM deps AS format-validate
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run format-check \
|
yarn run format-check
|
||||||
|
|
||||||
|
FROM deps AS test
|
||||||
|
ENV RUNNER_TEMP=/tmp/github_runner
|
||||||
|
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
||||||
|
RUN --mount=type=bind,target=.,rw \
|
||||||
|
--mount=type=cache,target=/src/node_modules \
|
||||||
|
yarn run test --coverageDirectory=/tmp/coverage
|
||||||
|
|
||||||
|
FROM scratch AS test-coverage
|
||||||
|
COPY --from=test /tmp/coverage /
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1.2
|
|
||||||
ARG NODE_VERSION
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
|
||||||
RUN apk add --no-cache git
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
FROM base AS deps
|
|
||||||
RUN --mount=type=bind,target=.,rw \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
|
||||||
yarn install
|
|
||||||
|
|
||||||
FROM deps AS test
|
|
||||||
ENV RUNNER_TEMP=/tmp/github_runner
|
|
||||||
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
|
||||||
RUN --mount=type=bind,target=.,rw \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
|
||||||
yarn run test --coverageDirectory=/tmp/coverage
|
|
||||||
|
|
||||||
FROM scratch AS test-coverage
|
|
||||||
COPY --from=test /tmp/coverage /
|
|
@@ -1,23 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1.2
|
|
||||||
ARG NODE_VERSION
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
|
||||||
RUN apk add --no-cache git
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
FROM base AS vendored
|
|
||||||
RUN --mount=type=bind,target=.,rw \
|
|
||||||
--mount=type=cache,target=/src/node_modules \
|
|
||||||
yarn install && mkdir /out && cp yarn.lock /out
|
|
||||||
|
|
||||||
FROM scratch AS update
|
|
||||||
COPY --from=vendored /out /
|
|
||||||
|
|
||||||
FROM vendored AS validate
|
|
||||||
RUN --mount=type=bind,target=.,rw \
|
|
||||||
git add -A && cp -rf /out/* .; \
|
|
||||||
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then \
|
|
||||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
|
|
||||||
git status --porcelain -- yarn.lock; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
@@ -48,6 +48,7 @@ export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
|||||||
|
|
||||||
for (let output of csvparse(items, {
|
for (let output of csvparse(items, {
|
||||||
columns: false,
|
columns: false,
|
||||||
|
relax: true,
|
||||||
relaxColumnCount: true,
|
relaxColumnCount: true,
|
||||||
skipLinesWithEmptyValues: true
|
skipLinesWithEmptyValues: true
|
||||||
}) as Array<string[]>) {
|
}) as Array<string[]>) {
|
||||||
|
24
src/meta.ts
24
src/meta.ts
@@ -143,7 +143,11 @@ export class Meta {
|
|||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
|
} else {
|
||||||
|
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||||
latest = true;
|
latest = true;
|
||||||
@@ -171,7 +175,11 @@ export class Meta {
|
|||||||
let latest: boolean = false;
|
let latest: boolean = false;
|
||||||
const pver = pep440.explain(vraw);
|
const pver = pep440.explain(vraw);
|
||||||
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
|
if (pver.is_prerelease || pver.is_postrelease || pver.is_devrelease) {
|
||||||
vraw = this.setValue(pep440.clean(vraw), tag);
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
|
vraw = this.setValue(vraw, tag);
|
||||||
|
} else {
|
||||||
|
vraw = this.setValue(pep440.clean(vraw), tag);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vraw = this.setValue(
|
vraw = this.setValue(
|
||||||
handlebars.compile(tag.attrs['pattern'])({
|
handlebars.compile(tag.attrs['pattern'])({
|
||||||
@@ -307,6 +315,18 @@ export class Meta {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static isRawStatement(pattern: string): boolean {
|
||||||
|
try {
|
||||||
|
const hp = handlebars.parseWithoutProcessing(pattern);
|
||||||
|
if (hp.body.length == 1 && hp.body[0].type == 'MustacheStatement') {
|
||||||
|
return hp.body[0]['path']['parts'].length == 1 && hp.body[0]['path']['parts'][0] == 'raw';
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private setValue(val: string, tag: tcl.Tag): string {
|
private setValue(val: string, tag: tcl.Tag): string {
|
||||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||||
|
Reference in New Issue
Block a user