Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
846cac2aa2 | ||
|
|
83d63d1cf1 | ||
|
|
931b62d64f | ||
|
|
16ecd76490 | ||
|
|
2cb2c5573f | ||
|
|
f2de331691 | ||
|
|
27254cb337 | ||
|
|
c8df3474bd | ||
|
|
fe9937dd36 | ||
|
|
8785275da1 |
12
.github/docker-releases.json
vendored
12
.github/docker-releases.json
vendored
@@ -1,8 +1,14 @@
|
|||||||
{
|
{
|
||||||
"latest": {
|
"latest": {
|
||||||
"id": 162600493,
|
"id": 163311279,
|
||||||
"tag_name": "v27.0.2",
|
"tag_name": "v27.0.3",
|
||||||
"html_url": "https://github.com/moby/moby/releases/tag/v27.0.2",
|
"html_url": "https://github.com/moby/moby/releases/tag/v27.0.3",
|
||||||
|
"assets": []
|
||||||
|
},
|
||||||
|
"v27.0.3": {
|
||||||
|
"id": 163311279,
|
||||||
|
"tag_name": "v27.0.3",
|
||||||
|
"html_url": "https://github.com/moby/moby/releases/tag/v27.0.3",
|
||||||
"assets": []
|
"assets": []
|
||||||
},
|
},
|
||||||
"v27.0.2": {
|
"v27.0.2": {
|
||||||
|
|||||||
344
__tests__/buildkit/git.test.ts
Normal file
344
__tests__/buildkit/git.test.ts
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2024 actions-toolkit authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
||||||
|
|
||||||
|
import {Git} from '../../src/buildkit/git';
|
||||||
|
|
||||||
|
import {GitRef, GitURL} from '../../src/types/buildkit/git';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseURL', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
'http://github.com/moby/buildkit',
|
||||||
|
{
|
||||||
|
scheme: 'http',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit'
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://github.com/moby/buildkit',
|
||||||
|
{
|
||||||
|
scheme: 'https',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit'
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://github.com/moby/buildkit#v1.0.0',
|
||||||
|
{
|
||||||
|
scheme: 'http',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit',
|
||||||
|
fragment: {
|
||||||
|
ref: 'v1.0.0',
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://github.com/moby/buildkit#v1.0.0:subdir',
|
||||||
|
{
|
||||||
|
scheme: 'http',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit',
|
||||||
|
fragment: {
|
||||||
|
ref: 'v1.0.0',
|
||||||
|
subdir: 'subdir'
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://foo:bar@github.com/moby/buildkit#v1.0.0',
|
||||||
|
{
|
||||||
|
scheme: 'http',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit',
|
||||||
|
fragment: {
|
||||||
|
ref: 'v1.0.0',
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
username: 'foo',
|
||||||
|
password: 'bar',
|
||||||
|
passwordSet: true
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ssh://git@github.com/moby/buildkit.git',
|
||||||
|
{
|
||||||
|
scheme: 'ssh',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit.git',
|
||||||
|
user: {
|
||||||
|
username: 'git',
|
||||||
|
password: '',
|
||||||
|
passwordSet: false
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ssh://git@github.com:22/moby/buildkit.git',
|
||||||
|
{
|
||||||
|
scheme: 'ssh',
|
||||||
|
host: 'github.com:22',
|
||||||
|
path: '/moby/buildkit.git',
|
||||||
|
user: {
|
||||||
|
username: 'git',
|
||||||
|
password: '',
|
||||||
|
passwordSet: false
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
// TODO: handle SCP-style URLs
|
||||||
|
// [
|
||||||
|
// 'git@github.com:moby/buildkit.git',
|
||||||
|
// {
|
||||||
|
// scheme: 'ssh',
|
||||||
|
// host: 'github.com:22',
|
||||||
|
// path: 'moby/buildkit.git',
|
||||||
|
// user: {
|
||||||
|
// username: 'git',
|
||||||
|
// password: '',
|
||||||
|
// passwordSet: false
|
||||||
|
// }
|
||||||
|
// } as GitURL,
|
||||||
|
// false
|
||||||
|
// ],
|
||||||
|
[
|
||||||
|
'ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git',
|
||||||
|
{
|
||||||
|
scheme: 'ssh',
|
||||||
|
host: 'subdomain.example.hostname:2222',
|
||||||
|
path: '/root/my/really/weird/path/foo.git',
|
||||||
|
user: {
|
||||||
|
username: 'root',
|
||||||
|
password: '',
|
||||||
|
passwordSet: false
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'git://host.xz:1234/path/to/repo.git',
|
||||||
|
{
|
||||||
|
scheme: 'git',
|
||||||
|
host: 'host.xz:1234',
|
||||||
|
path: '/path/to/repo.git',
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ssh://someuser@192.168.0.123:456/~/repo-in-my-home-dir.git',
|
||||||
|
{
|
||||||
|
scheme: 'ssh',
|
||||||
|
host: '192.168.0.123:456',
|
||||||
|
path: '/~/repo-in-my-home-dir.git',
|
||||||
|
user: {
|
||||||
|
username: 'someuser',
|
||||||
|
password: '',
|
||||||
|
passwordSet: false
|
||||||
|
}
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'httpx://github.com/moby/buildkit',
|
||||||
|
{} as GitURL,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'HTTP://github.com/moby/buildkit',
|
||||||
|
{
|
||||||
|
scheme: 'http',
|
||||||
|
host: 'github.com',
|
||||||
|
path: '/moby/buildkit'
|
||||||
|
} as GitURL,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
])('given %p', async (ref: string, expected: GitURL, expectedErr: boolean) => {
|
||||||
|
try {
|
||||||
|
const got = Git.parseURL(ref);
|
||||||
|
expect(got.scheme).toEqual(expected.scheme);
|
||||||
|
expect(got.host).toEqual(expected.host);
|
||||||
|
expect(got.path).toEqual(expected.path);
|
||||||
|
expect(got.fragment).toEqual(expected.fragment);
|
||||||
|
expect(got.user?.username).toEqual(expected.user?.username);
|
||||||
|
expect(got.user?.password).toEqual(expected.user?.password);
|
||||||
|
expect(got.user?.passwordSet).toEqual(expected.user?.passwordSet);
|
||||||
|
} catch (err) {
|
||||||
|
if (!expectedErr) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line jest/no-conditional-expect
|
||||||
|
expect(expectedErr).toBeTruthy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseRef', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
'https://example.com/',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo.git',
|
||||||
|
{
|
||||||
|
remote: 'https://example.com/foo.git',
|
||||||
|
shortName: 'foo'
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo.git#deadbeef',
|
||||||
|
{
|
||||||
|
remote: 'https://example.com/foo.git',
|
||||||
|
shortName: 'foo',
|
||||||
|
commit: 'deadbeef'
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo.git#release/1.2',
|
||||||
|
{
|
||||||
|
remote: 'https://example.com/foo.git',
|
||||||
|
shortName: 'foo',
|
||||||
|
commit: 'release/1.2'
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo.git/',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://example.com/foo.git.bar',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'git://example.com/foo',
|
||||||
|
{
|
||||||
|
remote: 'git://example.com/foo',
|
||||||
|
shortName: 'foo',
|
||||||
|
unencryptedTCP: true
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'github.com/moby/buildkit',
|
||||||
|
{
|
||||||
|
remote: 'github.com/moby/buildkit',
|
||||||
|
shortName: 'buildkit',
|
||||||
|
indistinguishableFromLocal: true
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'custom.xyz/moby/buildkit.git',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://github.com/moby/buildkit',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://github.com/moby/buildkit.git',
|
||||||
|
{
|
||||||
|
remote: 'https://github.com/moby/buildkit.git',
|
||||||
|
shortName: 'buildkit',
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://foo:bar@github.com/moby/buildkit.git',
|
||||||
|
{
|
||||||
|
remote: 'https://foo:bar@github.com/moby/buildkit.git',
|
||||||
|
shortName: 'buildkit',
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
// TODO handle SCP-style URLs
|
||||||
|
// [
|
||||||
|
// 'git@github.com:moby/buildkit',
|
||||||
|
// {
|
||||||
|
// remote: 'git@github.com:moby/buildkit',
|
||||||
|
// shortName: 'buildkit',
|
||||||
|
// } as GitRef
|
||||||
|
// ],
|
||||||
|
// [
|
||||||
|
// 'git@github.com:moby/buildkit.git',
|
||||||
|
// {
|
||||||
|
// remote: 'git@github.com:moby/buildkit',
|
||||||
|
// shortName: 'buildkit',
|
||||||
|
// } as GitRef
|
||||||
|
// ],
|
||||||
|
// [
|
||||||
|
// 'git@bitbucket.org:atlassianlabs/atlassian-docker.git',
|
||||||
|
// {
|
||||||
|
// remote: 'git@bitbucket.org:atlassianlabs/atlassian-docker.git',
|
||||||
|
// shortName: 'atlassian-docker',
|
||||||
|
// } as GitRef
|
||||||
|
// ],
|
||||||
|
[
|
||||||
|
'https://github.com/foo/bar.git#baz/qux:quux/quuz',
|
||||||
|
{
|
||||||
|
remote: 'https://github.com/foo/bar.git',
|
||||||
|
shortName: 'bar',
|
||||||
|
commit: 'baz/qux',
|
||||||
|
subDir: 'quux/quuz',
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://github.com/docker/docker.git#:myfolder',
|
||||||
|
{
|
||||||
|
remote: 'https://github.com/docker/docker.git',
|
||||||
|
shortName: 'docker',
|
||||||
|
subDir: 'myfolder',
|
||||||
|
commit: ''
|
||||||
|
} as GitRef
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'./.git',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'.git',
|
||||||
|
undefined
|
||||||
|
],
|
||||||
|
])('given %p', async (ref: string, expected: GitRef | undefined) => {
|
||||||
|
try {
|
||||||
|
const got = Git.parseRef(ref);
|
||||||
|
expect(got).toEqual(expected);
|
||||||
|
} catch (err) {
|
||||||
|
if (expected) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line jest/no-conditional-expect
|
||||||
|
expect(expected).toBeUndefined();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -23,13 +23,14 @@ import {Bake} from '../../src/buildx/bake';
|
|||||||
import {Context} from '../../src/context';
|
import {Context} from '../../src/context';
|
||||||
|
|
||||||
import {ExecOptions} from '@actions/exec';
|
import {ExecOptions} from '@actions/exec';
|
||||||
import {BakeDefinition, BakeMetadata} from '../../src/types/buildx/bake';
|
import {BakeDefinition} from '../../src/types/buildx/bake';
|
||||||
|
import {BuildMetadata} from '../../src/types/buildx/build';
|
||||||
|
|
||||||
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-inputs-jest');
|
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-inputs-jest');
|
||||||
const tmpName = path.join(tmpDir, '.tmpname-jest');
|
const tmpName = path.join(tmpDir, '.tmpname-jest');
|
||||||
const metadata: BakeMetadata = {
|
const metadata: BuildMetadata = {
|
||||||
app: {
|
app: {
|
||||||
'buildx.build.ref': 'default/default/7frbdw1fmfozgtqavghowsepk'
|
'buildx.build.ref': 'default/default/7frbdw1fmfozgtqavghowsepk'
|
||||||
},
|
},
|
||||||
@@ -57,7 +58,7 @@ describe('resolveMetadata', () => {
|
|||||||
it('matches', async () => {
|
it('matches', async () => {
|
||||||
const bake = new Bake();
|
const bake = new Bake();
|
||||||
fs.writeFileSync(bake.getMetadataFilePath(), JSON.stringify(metadata));
|
fs.writeFileSync(bake.getMetadataFilePath(), JSON.stringify(metadata));
|
||||||
expect(bake.resolveMetadata()).toEqual(metadata as BakeMetadata);
|
expect(bake.resolveMetadata()).toEqual(metadata as BuildMetadata);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,28 @@ describe('apiURL', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isGHES', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
process.env.GITHUB_SERVER_URL = '';
|
||||||
|
});
|
||||||
|
it('should return false when the request domain is github.com', () => {
|
||||||
|
process.env.GITHUB_SERVER_URL = 'https://github.com';
|
||||||
|
expect(GitHub.isGHES).toBe(false);
|
||||||
|
});
|
||||||
|
it('should return false when the request domain ends with ghe.com', () => {
|
||||||
|
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.com';
|
||||||
|
expect(GitHub.isGHES).toBe(false);
|
||||||
|
});
|
||||||
|
it('should return false when the request domain ends with ghe.localhost', () => {
|
||||||
|
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost';
|
||||||
|
expect(GitHub.isGHES).toBe(false);
|
||||||
|
});
|
||||||
|
it('should return true when the request domain is specific to an enterprise', () => {
|
||||||
|
process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com';
|
||||||
|
expect(GitHub.isGHES).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('repository', () => {
|
describe('repository', () => {
|
||||||
it('returns GitHub repository', async () => {
|
it('returns GitHub repository', async () => {
|
||||||
expect(GitHub.repository).toEqual('docker/actions-toolkit');
|
expect(GitHub.repository).toEqual('docker/actions-toolkit');
|
||||||
|
|||||||
113
src/buildkit/git.ts
Normal file
113
src/buildkit/git.ts
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2024 actions-toolkit authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {GitRef, GitURL, GitURLFragment, URLUserInfo} from '../types/buildkit/git';
|
||||||
|
|
||||||
|
export class Git {
|
||||||
|
private static protoRegexp = new RegExp('^[a-zA-Z0-9]+://');
|
||||||
|
private static supportedProtos = {
|
||||||
|
http: {},
|
||||||
|
https: {},
|
||||||
|
ssh: {},
|
||||||
|
git: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://github.com/moby/buildkit/blob/2ec1338fc13f73b43f0b1b4f4678d7cd654bc86c/util/gitutil/git_url.go#L79
|
||||||
|
public static parseURL(remote: string): GitURL {
|
||||||
|
const match = remote.match(Git.protoRegexp);
|
||||||
|
if (match && match.length > 0) {
|
||||||
|
let proto = match[0].toLowerCase();
|
||||||
|
proto = proto.slice(0, proto.lastIndexOf('://'));
|
||||||
|
if (!(proto in Git.supportedProtos)) {
|
||||||
|
throw new Error(`Invalid protocol: ${proto}`);
|
||||||
|
}
|
||||||
|
return Git.fromURL(new URL(remote));
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('Unknown protocol');
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/moby/buildkit/blob/2ec1338fc13f73b43f0b1b4f4678d7cd654bc86c/util/gitutil/git_url.go#L108
|
||||||
|
private static fromURL(url: URL): GitURL {
|
||||||
|
const withoutFragment = new URL(url.toString());
|
||||||
|
withoutFragment.hash = '';
|
||||||
|
|
||||||
|
let user: URLUserInfo | undefined;
|
||||||
|
if (url.username || url.password) {
|
||||||
|
user = {
|
||||||
|
username: url.username,
|
||||||
|
password: url.password,
|
||||||
|
passwordSet: url.password !== ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: handle SCP-style URLs
|
||||||
|
|
||||||
|
return {
|
||||||
|
scheme: url.protocol.slice(0, -1),
|
||||||
|
user: user,
|
||||||
|
host: `${url.hostname}${url.port ? ':' + url.port : ''}`,
|
||||||
|
path: url.pathname,
|
||||||
|
fragment: Git.splitGitFragment(url.hash),
|
||||||
|
remote: withoutFragment.toString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/moby/buildkit/blob/2ec1338fc13f73b43f0b1b4f4678d7cd654bc86c/util/gitutil/git_url.go#L69
|
||||||
|
private static splitGitFragment(fragment: string): GitURLFragment | undefined {
|
||||||
|
if (fragment === '') {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const [ref, subdir] = fragment.slice(1).split(':');
|
||||||
|
return {
|
||||||
|
ref: ref,
|
||||||
|
subdir: subdir
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/moby/buildkit/blob/2ec1338fc13f73b43f0b1b4f4678d7cd654bc86c/util/gitutil/git_ref.go#L52
|
||||||
|
public static parseRef(ref: string): GitRef | undefined {
|
||||||
|
const res: GitRef = {};
|
||||||
|
let remote: GitURL;
|
||||||
|
if (ref.startsWith('./') || ref.startsWith('../')) {
|
||||||
|
throw new Error('Invalid argument');
|
||||||
|
} else if (ref.startsWith('github.com/')) {
|
||||||
|
res.indistinguishableFromLocal = true; // Deprecated
|
||||||
|
remote = Git.fromURL(new URL('https://' + ref));
|
||||||
|
} else {
|
||||||
|
remote = Git.parseURL(ref);
|
||||||
|
if (['http', 'git'].includes(remote.scheme)) {
|
||||||
|
res.unencryptedTCP = true; // Discouraged, but not deprecated
|
||||||
|
}
|
||||||
|
if (['http', 'https'].includes(remote.scheme) && !remote.path.endsWith('.git')) {
|
||||||
|
throw new Error('Invalid argument');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.remote = remote.remote;
|
||||||
|
|
||||||
|
if (res.indistinguishableFromLocal) {
|
||||||
|
res.remote = res.remote.split('://')[1];
|
||||||
|
}
|
||||||
|
if (remote.fragment) {
|
||||||
|
res.commit = remote.fragment.ref;
|
||||||
|
res.subDir = remote.fragment.subdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const repoSplitBySlash = res.remote.split('/');
|
||||||
|
res.shortName = repoSplitBySlash[repoSplitBySlash.length - 1].replace('.git', '');
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,8 @@ import {Exec} from '../exec';
|
|||||||
import {Util} from '../util';
|
import {Util} from '../util';
|
||||||
|
|
||||||
import {ExecOptions} from '@actions/exec';
|
import {ExecOptions} from '@actions/exec';
|
||||||
import {BakeDefinition, BakeMetadata} from '../types/buildx/bake';
|
import {BakeDefinition} from '../types/buildx/bake';
|
||||||
|
import {BuildMetadata} from '../types/buildx/build';
|
||||||
|
|
||||||
export interface BakeOpts {
|
export interface BakeOpts {
|
||||||
buildx?: Buildx;
|
buildx?: Buildx;
|
||||||
@@ -57,7 +58,7 @@ export class Bake {
|
|||||||
return path.join(Context.tmpDir(), this.metadataFilename);
|
return path.join(Context.tmpDir(), this.metadataFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveMetadata(): BakeMetadata | undefined {
|
public resolveMetadata(): BuildMetadata | undefined {
|
||||||
const metadataFile = this.getMetadataFilePath();
|
const metadataFile = this.getMetadataFilePath();
|
||||||
if (!fs.existsSync(metadataFile)) {
|
if (!fs.existsSync(metadataFile)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -66,10 +67,10 @@ export class Bake {
|
|||||||
if (content === 'null') {
|
if (content === 'null') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return <BakeMetadata>JSON.parse(content);
|
return <BuildMetadata>JSON.parse(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveRefs(metadata?: BakeMetadata): Array<string> | undefined {
|
public resolveRefs(metadata?: BuildMetadata): Array<string> | undefined {
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
metadata = this.resolveMetadata();
|
metadata = this.resolveMetadata();
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
@@ -82,7 +83,7 @@ export class Bake {
|
|||||||
refs.push(metadata[key]['buildx.build.ref']);
|
refs.push(metadata[key]['buildx.build.ref']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return refs;
|
return refs.length > 0 ? refs : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDefinition(cmdOpts: BakeCmdOpts, execOptions?: ExecOptions): Promise<BakeDefinition> {
|
public async getDefinition(cmdOpts: BakeCmdOpts, execOptions?: ExecOptions): Promise<BakeDefinition> {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import os from 'os';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated';
|
import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated';
|
||||||
import {internalArtifactTwirpClient} from '@actions/artifact/lib/internal/shared/artifact-twirp-client';
|
import {internalArtifactTwirpClient} from '@actions/artifact/lib/internal/shared/artifact-twirp-client';
|
||||||
import {isGhes} from '@actions/artifact/lib/internal/shared/config';
|
|
||||||
import {getBackendIdsFromToken} from '@actions/artifact/lib/internal/shared/util';
|
import {getBackendIdsFromToken} from '@actions/artifact/lib/internal/shared/util';
|
||||||
import {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
|
import {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
|
||||||
import {InvalidResponseError, NetworkError} from '@actions/artifact';
|
import {InvalidResponseError, NetworkError} from '@actions/artifact';
|
||||||
@@ -67,6 +66,14 @@ export class GitHub {
|
|||||||
return process.env.GITHUB_API_URL || 'https://api.github.com';
|
return process.env.GITHUB_API_URL || 'https://api.github.com';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get isGHES(): boolean {
|
||||||
|
const serverURL = new URL(GitHub.serverURL);
|
||||||
|
const hostname = serverURL.hostname.trimEnd().toUpperCase();
|
||||||
|
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||||
|
const isGHESHost = hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST');
|
||||||
|
return !isGitHubHost && !isGHESHost;
|
||||||
|
}
|
||||||
|
|
||||||
static get repository(): string {
|
static get repository(): string {
|
||||||
return `${github.context.repo.owner}/${github.context.repo.repo}`;
|
return `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||||
}
|
}
|
||||||
@@ -124,7 +131,7 @@ export class GitHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async uploadArtifact(opts: UploadArtifactOpts): Promise<UploadArtifactResponse> {
|
public static async uploadArtifact(opts: UploadArtifactOpts): Promise<UploadArtifactResponse> {
|
||||||
if (isGhes()) {
|
if (GitHub.isGHES) {
|
||||||
throw new Error('@actions/artifact v2.0.0+ is currently not supported on GHES.');
|
throw new Error('@actions/artifact v2.0.0+ is currently not supported on GHES.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
44
src/types/buildkit/git.ts
Normal file
44
src/types/buildkit/git.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2024 actions-toolkit authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface GitURL {
|
||||||
|
scheme: string;
|
||||||
|
host: string;
|
||||||
|
path: string;
|
||||||
|
user?: URLUserInfo;
|
||||||
|
fragment?: GitURLFragment;
|
||||||
|
remote: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GitURLFragment {
|
||||||
|
ref: string;
|
||||||
|
subdir: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GitRef {
|
||||||
|
remote?: string;
|
||||||
|
shortName?: string;
|
||||||
|
commit?: string;
|
||||||
|
subDir?: string;
|
||||||
|
indistinguishableFromLocal?: boolean;
|
||||||
|
unencryptedTCP?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface URLUserInfo {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
passwordSet: boolean;
|
||||||
|
}
|
||||||
@@ -19,10 +19,6 @@ export interface BakeDefinition {
|
|||||||
target: Record<string, Target>;
|
target: Record<string, Target>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BakeMetadata {
|
|
||||||
[target: string]: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Group {
|
export interface Group {
|
||||||
targets: Array<string>;
|
targets: Array<string>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user