diff --git a/.prettierrc.json b/.prettierrc.json index d8339f6..c308ef6 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -6,6 +6,5 @@ "singleQuote": true, "trailingComma": "none", "bracketSpacing": false, - "arrowParens": "avoid", - "parser": "typescript" + "arrowParens": "avoid" } diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index d5c5846..07ad579 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -2,26 +2,22 @@ import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; +import {fileURLToPath} from 'node:url'; -import {Builder} from '@docker/actions-toolkit/lib/buildx/builder'; -import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx'; -import {Build} from '@docker/actions-toolkit/lib/buildx/build'; -import {Context} from '@docker/actions-toolkit/lib/context'; -import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; -import {GitHub} from '@docker/actions-toolkit/lib/github'; -import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; +import {Builder} from '@docker/actions-toolkit/lib/buildx/builder.js'; +import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js'; +import {Build} from '@docker/actions-toolkit/lib/buildx/build.js'; +import {Context} from '@docker/actions-toolkit/lib/context.js'; +import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js'; +import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js'; -import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder'; -import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github'; +import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder.js'; + +import * as context from '../src/context.js'; const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-')); const tmpName = path.join(tmpDir, '.tmpname-vi'); -import * as context from '../src/context'; - -import repoFixture from './fixtures/github-repo.json'; -vi.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise => { - return >(repoFixture as unknown); -}); +const testDir = path.dirname(fileURLToPath(import.meta.url)); vi.spyOn(Context, 'tmpDir').mockImplementation((): string => { if (!fs.existsSync(tmpDir)) { @@ -346,7 +342,7 @@ ccc`], new Map([ ['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'], ['tag', 'localhost:5000/name/app:latest'], - ['secret-files', `MY_SECRET=${path.join(__dirname, 'fixtures', 'secret.txt')}`], + ['secret-files', `MY_SECRET=${path.join(testDir, 'fixtures', 'secret.txt')}`], ['file', './test/Dockerfile'], ['builder', 'builder-git-context-2'], ['network', 'host'], diff --git a/__tests__/fixtures/github-repo.json b/__tests__/fixtures/github-repo.json deleted file mode 100644 index faf700c..0000000 --- a/__tests__/fixtures/github-repo.json +++ /dev/null @@ -1,362 +0,0 @@ -{ - "id": 1296269, - "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", - "name": "Hello-World", - "full_name": "octocat/Hello-World", - "owner": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "followers_url": "https://api.github.com/users/octocat/followers", - "following_url": "https://api.github.com/users/octocat/following{/other_user}", - "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", - "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", - "organizations_url": "https://api.github.com/users/octocat/orgs", - "repos_url": "https://api.github.com/users/octocat/repos", - "events_url": "https://api.github.com/users/octocat/events{/privacy}", - "received_events_url": "https://api.github.com/users/octocat/received_events", - "type": "User", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/octocat/Hello-World", - "description": "This your first repo!", - "fork": false, - "url": "https://api.github.com/repos/octocat/Hello-World", - "archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", - "assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}", - "blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", - "branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}", - "collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", - "comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}", - "commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}", - "compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", - "contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}", - "contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors", - "deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments", - "downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads", - "events_url": "http://api.github.com/repos/octocat/Hello-World/events", - "forks_url": "http://api.github.com/repos/octocat/Hello-World/forks", - "git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", - "git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", - "git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", - "git_url": "git:github.com/octocat/Hello-World.git", - "issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", - "issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}", - "issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}", - "keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}", - "labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}", - "languages_url": "http://api.github.com/repos/octocat/Hello-World/languages", - "merges_url": "http://api.github.com/repos/octocat/Hello-World/merges", - "milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}", - "notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", - "pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}", - "releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}", - "ssh_url": "git@github.com:octocat/Hello-World.git", - "stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers", - "statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}", - "subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers", - "subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription", - "tags_url": "http://api.github.com/repos/octocat/Hello-World/tags", - "teams_url": "http://api.github.com/repos/octocat/Hello-World/teams", - "trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", - "clone_url": "https://github.com/octocat/Hello-World.git", - "mirror_url": "git:git.example.com/octocat/Hello-World", - "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks", - "svn_url": "https://svn.github.com/octocat/Hello-World", - "homepage": "https://github.com", - "language": null, - "forks_count": 9, - "stargazers_count": 80, - "watchers_count": 80, - "size": 108, - "default_branch": "master", - "open_issues_count": 0, - "is_template": true, - "topics": [ - "octocat", - "atom", - "electron", - "api" - ], - "has_issues": true, - "has_projects": true, - "has_wiki": true, - "has_pages": false, - "has_downloads": true, - "archived": false, - "disabled": false, - "visibility": "public", - "pushed_at": "2011-01-26T19:06:43Z", - "created_at": "2011-01-26T19:01:12Z", - "updated_at": "2011-01-26T19:14:43Z", - "permissions": { - "pull": true, - "triage": true, - "push": false, - "maintain": false, - "admin": false - }, - "allow_rebase_merge": true, - "template_repository": null, - "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", - "allow_squash_merge": true, - "delete_branch_on_merge": true, - "allow_merge_commit": true, - "subscribers_count": 42, - "network_count": 0, - "license": { - "key": "mit", - "name": "MIT License", - "spdx_id": "MIT", - "url": "https://api.github.com/licenses/mit", - "node_id": "MDc6TGljZW5zZW1pdA==" - }, - "organization": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "followers_url": "https://api.github.com/users/octocat/followers", - "following_url": "https://api.github.com/users/octocat/following{/other_user}", - "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", - "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", - "organizations_url": "https://api.github.com/users/octocat/orgs", - "repos_url": "https://api.github.com/users/octocat/repos", - "events_url": "https://api.github.com/users/octocat/events{/privacy}", - "received_events_url": "https://api.github.com/users/octocat/received_events", - "type": "Organization", - "site_admin": false - }, - "parent": { - "id": 1296269, - "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", - "name": "Hello-World", - "full_name": "octocat/Hello-World", - "owner": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "followers_url": "https://api.github.com/users/octocat/followers", - "following_url": "https://api.github.com/users/octocat/following{/other_user}", - "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", - "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", - "organizations_url": "https://api.github.com/users/octocat/orgs", - "repos_url": "https://api.github.com/users/octocat/repos", - "events_url": "https://api.github.com/users/octocat/events{/privacy}", - "received_events_url": "https://api.github.com/users/octocat/received_events", - "type": "User", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/octocat/Hello-World", - "description": "This your first repo!", - "fork": false, - "url": "https://api.github.com/repos/octocat/Hello-World", - "archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", - "assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}", - "blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", - "branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}", - "collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", - "comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}", - "commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}", - "compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", - "contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}", - "contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors", - "deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments", - "downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads", - "events_url": "http://api.github.com/repos/octocat/Hello-World/events", - "forks_url": "http://api.github.com/repos/octocat/Hello-World/forks", - "git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", - "git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", - "git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", - "git_url": "git:github.com/octocat/Hello-World.git", - "issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", - "issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}", - "issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}", - "keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}", - "labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}", - "languages_url": "http://api.github.com/repos/octocat/Hello-World/languages", - "merges_url": "http://api.github.com/repos/octocat/Hello-World/merges", - "milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}", - "notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", - "pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}", - "releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}", - "ssh_url": "git@github.com:octocat/Hello-World.git", - "stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers", - "statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}", - "subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers", - "subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription", - "tags_url": "http://api.github.com/repos/octocat/Hello-World/tags", - "teams_url": "http://api.github.com/repos/octocat/Hello-World/teams", - "trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", - "clone_url": "https://github.com/octocat/Hello-World.git", - "mirror_url": "git:git.example.com/octocat/Hello-World", - "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks", - "svn_url": "https://svn.github.com/octocat/Hello-World", - "homepage": "https://github.com", - "language": null, - "forks_count": 9, - "stargazers_count": 80, - "watchers_count": 80, - "size": 108, - "default_branch": "master", - "open_issues_count": 0, - "is_template": true, - "topics": [ - "octocat", - "atom", - "electron", - "api" - ], - "has_issues": true, - "has_projects": true, - "has_wiki": true, - "has_pages": false, - "has_downloads": true, - "archived": false, - "disabled": false, - "visibility": "public", - "pushed_at": "2011-01-26T19:06:43Z", - "created_at": "2011-01-26T19:01:12Z", - "updated_at": "2011-01-26T19:14:43Z", - "permissions": { - "admin": false, - "push": false, - "pull": true - }, - "allow_rebase_merge": true, - "template_repository": null, - "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", - "allow_squash_merge": true, - "delete_branch_on_merge": true, - "allow_merge_commit": true, - "subscribers_count": 42, - "network_count": 0 - }, - "source": { - "id": 1296269, - "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", - "name": "Hello-World", - "full_name": "octocat/Hello-World", - "owner": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "followers_url": "https://api.github.com/users/octocat/followers", - "following_url": "https://api.github.com/users/octocat/following{/other_user}", - "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", - "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", - "organizations_url": "https://api.github.com/users/octocat/orgs", - "repos_url": "https://api.github.com/users/octocat/repos", - "events_url": "https://api.github.com/users/octocat/events{/privacy}", - "received_events_url": "https://api.github.com/users/octocat/received_events", - "type": "User", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/octocat/Hello-World", - "description": "This your first repo!", - "fork": false, - "url": "https://api.github.com/repos/octocat/Hello-World", - "archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", - "assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}", - "blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", - "branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}", - "collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", - "comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}", - "commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}", - "compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", - "contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}", - "contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors", - "deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments", - "downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads", - "events_url": "http://api.github.com/repos/octocat/Hello-World/events", - "forks_url": "http://api.github.com/repos/octocat/Hello-World/forks", - "git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", - "git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", - "git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", - "git_url": "git:github.com/octocat/Hello-World.git", - "issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", - "issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}", - "issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}", - "keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}", - "labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}", - "languages_url": "http://api.github.com/repos/octocat/Hello-World/languages", - "merges_url": "http://api.github.com/repos/octocat/Hello-World/merges", - "milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}", - "notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", - "pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}", - "releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}", - "ssh_url": "git@github.com:octocat/Hello-World.git", - "stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers", - "statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}", - "subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers", - "subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription", - "tags_url": "http://api.github.com/repos/octocat/Hello-World/tags", - "teams_url": "http://api.github.com/repos/octocat/Hello-World/teams", - "trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", - "clone_url": "https://github.com/octocat/Hello-World.git", - "mirror_url": "git:git.example.com/octocat/Hello-World", - "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks", - "svn_url": "https://svn.github.com/octocat/Hello-World", - "homepage": "https://github.com", - "language": null, - "forks_count": 9, - "stargazers_count": 80, - "watchers_count": 80, - "size": 108, - "default_branch": "master", - "open_issues_count": 0, - "is_template": true, - "topics": [ - "octocat", - "atom", - "electron", - "api" - ], - "has_issues": true, - "has_projects": true, - "has_wiki": true, - "has_pages": false, - "has_downloads": true, - "archived": false, - "disabled": false, - "visibility": "public", - "pushed_at": "2011-01-26T19:06:43Z", - "created_at": "2011-01-26T19:01:12Z", - "updated_at": "2011-01-26T19:14:43Z", - "permissions": { - "admin": false, - "push": false, - "pull": true - }, - "allow_rebase_merge": true, - "template_repository": null, - "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", - "allow_squash_merge": true, - "delete_branch_on_merge": true, - "allow_merge_commit": true, - "subscribers_count": 42, - "network_count": 0 - } -} diff --git a/__tests__/setup.unit.ts b/__tests__/setup.unit.ts index 6d4b96a..b2ace6c 100644 --- a/__tests__/setup.unit.ts +++ b/__tests__/setup.unit.ts @@ -14,6 +14,7 @@ process.env = Object.assign({}, process.env, { }); const require = createRequire(import.meta.url); +type RequireCacheEntry = NonNullable<(typeof require.cache)[string]>; const githubMock = { context: { @@ -225,7 +226,7 @@ const githubMock = { vi.mock('@actions/github', () => githubMock); vi.doMock(require.resolve('@docker/actions-toolkit/node_modules/@actions/github'), () => githubMock); -for (const mod of ['@actions/github', '@docker/actions-toolkit/node_modules/@actions/github']) { +for (const mod of ['@docker/actions-toolkit/node_modules/@actions/github']) { try { const resolved = require.resolve(mod); require.cache[resolved] = { @@ -235,7 +236,7 @@ for (const mod of ['@actions/github', '@docker/actions-toolkit/node_modules/@act exports: githubMock, children: [], paths: [] - } as unknown as NodeModule; + } as RequireCacheEntry; } catch { // Ignore unresolved optional paths; vi.mock handles module-level mocking. } diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index f1690e7..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,58 +0,0 @@ -/* eslint-disable @typescript-eslint/no-require-imports */ -const {defineConfig, globalIgnores} = require('eslint/config'); -const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat'); -const typescriptEslint = require('@typescript-eslint/eslint-plugin'); -const vitestPlugin = require('@vitest/eslint-plugin'); -const prettier = require('eslint-plugin-prettier'); -const globals = require('globals'); -const tsParser = require('@typescript-eslint/parser'); -const js = require('@eslint/js'); -const {FlatCompat} = require('@eslint/eslintrc'); - -// __dirname and __filename exist natively in CommonJS -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all -}); - -module.exports = defineConfig([ - globalIgnores(['dist/**/*', 'coverage/**/*', 'node_modules/**/*']), - { - // prettier-ignore - extends: fixupConfigRules( - compat.extends( - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:@vitest/legacy-recommended', - 'plugin:prettier/recommended' - ) - ), - - plugins: { - '@typescript-eslint': fixupPluginRules(typescriptEslint), - '@vitest': fixupPluginRules(vitestPlugin), - prettier: fixupPluginRules(prettier) - }, - - languageOptions: { - globals: { - ...globals.node, - ...vitestPlugin.environments.env.globals - }, - parser: tsParser, - ecmaVersion: 'latest', - sourceType: 'module' - }, - - rules: { - '@typescript-eslint/no-require-imports': [ - 'error', - { - allowAsImport: true - } - ] - } - } -]); diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..530d49b --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,52 @@ +import {defineConfig} from 'eslint/config'; +import js from '@eslint/js'; +import tseslint from '@typescript-eslint/eslint-plugin'; +import vitest from '@vitest/eslint-plugin'; +import globals from 'globals'; +import eslintConfigPrettier from 'eslint-config-prettier/flat'; +import eslintPluginPrettier from 'eslint-plugin-prettier'; + +export default defineConfig([ + { + ignores: ['.yarn/**/*', 'coverage/**/*', 'dist/**/*'] + }, + js.configs.recommended, + ...tseslint.configs['flat/recommended'], + eslintConfigPrettier, + { + languageOptions: { + globals: { + ...globals.node + } + } + }, + { + files: ['__tests__/**'], + ...vitest.configs.recommended, + languageOptions: { + globals: { + ...globals.node, + ...vitest.environments.env.globals + } + }, + rules: { + ...vitest.configs.recommended.rules, + 'vitest/no-conditional-expect': 'error', + 'vitest/no-disabled-tests': 0 + } + }, + { + plugins: { + prettier: eslintPluginPrettier + }, + rules: { + 'prettier/prettier': 'error', + '@typescript-eslint/no-require-imports': [ + 'error', + { + allowAsImport: true + } + ] + } + } +]); diff --git a/package.json b/package.json index 2cb6d5d..f736f75 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,12 @@ { "name": "docker-build-push", "description": "Build and push Docker images", + "type": "module", "main": "src/main.ts", "scripts": { "build": "ncc build --source-map --minify --license licenses.txt", - "lint": "yarn run prettier && yarn run eslint", - "format": "yarn run prettier:fix && yarn run eslint:fix", - "eslint": "eslint --max-warnings=0 .", - "eslint:fix": "eslint --fix .", - "prettier": "prettier --check \"./**/*.ts\"", - "prettier:fix": "prettier --write \"./**/*.ts\"", + "lint": "eslint --max-warnings=0 .", + "format": "eslint --fix .", "test": "vitest run" }, "repository": { @@ -31,8 +28,6 @@ "handlebars": "^4.7.7" }, "devDependencies": { - "@eslint/compat": "^2.0.0", - "@eslint/eslintrc": "^3.3.3", "@eslint/js": "^9.39.2", "@types/node": "^20.19.27", "@typescript-eslint/eslint-plugin": "^8.50.0", @@ -43,8 +38,8 @@ "eslint": "^9.39.2", "eslint-config-prettier": "^10.1.8", "eslint-plugin-prettier": "^5.5.4", + "globals": "^17.3.0", "prettier": "^3.7.4", - "ts-node": "^10.9.2", "typescript": "^5.9.3", "vitest": "^4.0.18" } diff --git a/src/context.ts b/src/context.ts index bd31d66..9d04b7c 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,11 +1,11 @@ import * as core from '@actions/core'; import * as handlebars from 'handlebars'; -import {Build} from '@docker/actions-toolkit/lib/buildx/build'; -import {Context} from '@docker/actions-toolkit/lib/context'; -import {GitHub} from '@docker/actions-toolkit/lib/github'; -import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; -import {Util} from '@docker/actions-toolkit/lib/util'; +import {Build} from '@docker/actions-toolkit/lib/buildx/build.js'; +import {Context} from '@docker/actions-toolkit/lib/context.js'; +import {GitHub} from '@docker/actions-toolkit/lib/github.js'; +import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js'; +import {Util} from '@docker/actions-toolkit/lib/util.js'; export interface Inputs { 'add-hosts': string[]; diff --git a/src/main.ts b/src/main.ts index bf57647..92b1905 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,23 +1,23 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as stateHelper from './state-helper'; import * as core from '@actions/core'; import * as actionsToolkit from '@docker/actions-toolkit'; -import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx'; -import {History as BuildxHistory} from '@docker/actions-toolkit/lib/buildx/history'; -import {Context} from '@docker/actions-toolkit/lib/context'; -import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; -import {Exec} from '@docker/actions-toolkit/lib/exec'; -import {GitHub} from '@docker/actions-toolkit/lib/github'; -import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; -import {Util} from '@docker/actions-toolkit/lib/util'; +import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js'; +import {History as BuildxHistory} from '@docker/actions-toolkit/lib/buildx/history.js'; +import {Context} from '@docker/actions-toolkit/lib/context.js'; +import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js'; +import {Exec} from '@docker/actions-toolkit/lib/exec.js'; +import {GitHub} from '@docker/actions-toolkit/lib/github.js'; +import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js'; +import {Util} from '@docker/actions-toolkit/lib/util.js'; -import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder'; -import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker'; -import {UploadArtifactResponse} from '@docker/actions-toolkit/lib/types/github'; +import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder.js'; +import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker.js'; +import {UploadArtifactResponse} from '@docker/actions-toolkit/lib/types/github.js'; -import * as context from './context'; +import * as context from './context.js'; +import * as stateHelper from './state-helper.js'; actionsToolkit.run( // main diff --git a/src/state-helper.ts b/src/state-helper.ts index 88dac0c..11935b0 100644 --- a/src/state-helper.ts +++ b/src/state-helper.ts @@ -1,8 +1,8 @@ import * as core from '@actions/core'; -import {Build} from '@docker/actions-toolkit/lib/buildx/build'; +import {Build} from '@docker/actions-toolkit/lib/buildx/build.js'; -import {Inputs} from './context'; +import {Inputs} from './context.js'; export const tmpDir = process.env['STATE_tmpDir'] || ''; diff --git a/tsconfig.json b/tsconfig.json index 9720dc0..be1cc9f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,8 @@ { "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", "esModuleInterop": true, - "target": "es6", - "module": "commonjs", - "strict": true, "newLine": "lf", "outDir": "./lib", "rootDir": "./src", @@ -12,11 +11,7 @@ "resolveJsonModule": true, "useUnknownInCatchVariables": false, }, - "exclude": [ - "./__mocks__/**/*", - "./__tests__/**/*", - "./lib/**/*", - "node_modules", - "jest.config.ts" + "include": [ + "src/**/*.ts" ] } diff --git a/yarn.lock b/yarn.lock index 397463a..f6278e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -322,15 +322,6 @@ __metadata: languageName: node linkType: hard -"@cspotcode/source-map-support@npm:^0.8.0": - version: 0.8.1 - resolution: "@cspotcode/source-map-support@npm:0.8.1" - dependencies: - "@jridgewell/trace-mapping": "npm:0.3.9" - checksum: 10/b6e38a1712fab242c86a241c229cf562195aad985d0564bd352ac404be583029e89e93028ffd2c251d2c407ecac5fb0cbdca94a2d5c10f29ac806ede0508b3ff - languageName: node - linkType: hard - "@docker/actions-toolkit@npm:0.62.1": version: 0.62.1 resolution: "@docker/actions-toolkit@npm:0.62.1" @@ -560,20 +551,6 @@ __metadata: languageName: node linkType: hard -"@eslint/compat@npm:^2.0.0": - version: 2.0.0 - resolution: "@eslint/compat@npm:2.0.0" - dependencies: - "@eslint/core": "npm:^1.0.0" - peerDependencies: - eslint: ^8.40 || 9 - peerDependenciesMeta: - eslint: - optional: true - checksum: 10/b1f63053ac643d47ce44d354a65e095e2b59f6b6aee4d6ca08cfa3b0800fc784bbd6895494ba726479faf9591e8e2887dc13c7a776f0d9627f0fdbf7faa34fdb - languageName: node - linkType: hard - "@eslint/config-array@npm:^0.21.1": version: 0.21.1 resolution: "@eslint/config-array@npm:0.21.1" @@ -603,16 +580,7 @@ __metadata: languageName: node linkType: hard -"@eslint/core@npm:^1.0.0": - version: 1.0.0 - resolution: "@eslint/core@npm:1.0.0" - dependencies: - "@types/json-schema": "npm:^7.0.15" - checksum: 10/0e2fc001ec3a12a9d6cd5de8eaf6c9eb1deec892777fed04e59eae0f3073c69988451eda32623524db76adaa7075747a8de5aa39b91b9084c711db452194eae9 - languageName: node - linkType: hard - -"@eslint/eslintrc@npm:^3.3.1, @eslint/eslintrc@npm:^3.3.3": +"@eslint/eslintrc@npm:^3.3.1": version: 3.3.3 resolution: "@eslint/eslintrc@npm:3.3.3" dependencies: @@ -705,13 +673,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/resolve-uri@npm:^3.0.3": - version: 3.0.5 - resolution: "@jridgewell/resolve-uri@npm:3.0.5" - checksum: 10/66da0c14dfaebd3481ac363306eefa45aca6779f8635df7337b97c18873853a7e2946d79104fad3e2ab832fe438ebabcaa2091e55e069a81b35001fa6738f532 - languageName: node - linkType: hard - "@jridgewell/resolve-uri@npm:^3.1.0": version: 3.1.1 resolution: "@jridgewell/resolve-uri@npm:3.1.1" @@ -719,13 +680,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/sourcemap-codec@npm:^1.4.10": - version: 1.4.11 - resolution: "@jridgewell/sourcemap-codec@npm:1.4.11" - checksum: 10/591ca7f7884a51643e713b1b623c6c7d751bdc78d61b6cda1dcf7de1287e7f0530514c3f2c7d443273ddc8687637a95cd19f5d8986b32e2349d0f7310623df40 - languageName: node - linkType: hard - "@jridgewell/sourcemap-codec@npm:^1.4.14": version: 1.4.15 resolution: "@jridgewell/sourcemap-codec@npm:1.4.15" @@ -740,16 +694,6 @@ __metadata: languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:0.3.9": - version: 0.3.9 - resolution: "@jridgewell/trace-mapping@npm:0.3.9" - dependencies: - "@jridgewell/resolve-uri": "npm:^3.0.3" - "@jridgewell/sourcemap-codec": "npm:^1.4.10" - checksum: 10/83deafb8e7a5ca98993c2c6eeaa93c270f6f647a4c0dc00deb38c9cf9b2d3b7bf15e8839540155247ef034a052c0ec4466f980bf0c9e2ab63b97d16c0cedd3ff - languageName: node - linkType: hard - "@jridgewell/trace-mapping@npm:^0.3.31": version: 0.3.31 resolution: "@jridgewell/trace-mapping@npm:0.3.31" @@ -1336,34 +1280,6 @@ __metadata: languageName: node linkType: hard -"@tsconfig/node10@npm:^1.0.7": - version: 1.0.8 - resolution: "@tsconfig/node10@npm:1.0.8" - checksum: 10/b8d5fffbc6b17ef64ef74f7fdbccee02a809a063ade785c3648dae59406bc207f70ea2c4296f92749b33019fa36a5ae716e42e49cc7f1bbf0fd147be0d6b970a - languageName: node - linkType: hard - -"@tsconfig/node12@npm:^1.0.7": - version: 1.0.9 - resolution: "@tsconfig/node12@npm:1.0.9" - checksum: 10/a01b2400ab3582b86b589c6d31dcd0c0656f333adecde85d6d7d4086adb059808b82692380bb169546d189bf771ae21d02544a75b57bd6da4a5dd95f8567bec9 - languageName: node - linkType: hard - -"@tsconfig/node14@npm:^1.0.0": - version: 1.0.1 - resolution: "@tsconfig/node14@npm:1.0.1" - checksum: 10/976345e896c0f059867f94f8d0f6ddb8b1844fb62bf36b727de8a9a68f024857e5db97ed51d3325e23e0616a5e48c034ff51a8d595b3fe7e955f3587540489be - languageName: node - linkType: hard - -"@tsconfig/node16@npm:^1.0.2": - version: 1.0.2 - resolution: "@tsconfig/node16@npm:1.0.2" - checksum: 10/ca94d3639714672bbfd55f03521d3f56bb6a25479bd425da81faf21f13e1e9d15f40f97377dedbbf477a5841c5b0c8f4cd1b391f33553d750b9202c54c2c07aa - languageName: node - linkType: hard - "@types/chai@npm:^5.2.2": version: 5.2.3 resolution: "@types/chai@npm:5.2.3" @@ -1807,13 +1723,6 @@ __metadata: languageName: node linkType: hard -"acorn-walk@npm:^8.1.1": - version: 8.2.0 - resolution: "acorn-walk@npm:8.2.0" - checksum: 10/e69f7234f2adfeb16db3671429a7c80894105bd7534cb2032acf01bb26e6a847952d11a062d071420b43f8d82e33d2e57f26fe87d9cce0853e8143d8910ff1de - languageName: node - linkType: hard - "acorn@npm:^8.15.0": version: 8.15.0 resolution: "acorn@npm:8.15.0" @@ -1823,15 +1732,6 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.4.1": - version: 8.7.0 - resolution: "acorn@npm:8.7.0" - bin: - acorn: bin/acorn - checksum: 10/0c437f0beffd4309a8ee327cecdc555e50a3d8e30534d079b1eba81ea6bd64c15119e7974a8f077eac4bd1c0dd122196ef08d3ee60b2efd7fee00e18e9a46b7d - languageName: node - linkType: hard - "agent-base@npm:^7.0.2, agent-base@npm:^7.1.0, agent-base@npm:^7.1.1": version: 7.1.1 resolution: "agent-base@npm:7.1.1" @@ -1923,13 +1823,6 @@ __metadata: languageName: node linkType: hard -"arg@npm:^4.1.0": - version: 4.1.3 - resolution: "arg@npm:4.1.3" - checksum: 10/969b491082f20cad166649fa4d2073ea9e974a4e5ac36247ca23d2e5a8b3cb12d60e9ff70a8acfe26d76566c71fd351ee5e6a9a6595157eb36f92b1fd64e1599 - languageName: node - linkType: hard - "argparse@npm:^2.0.1": version: 2.0.1 resolution: "argparse@npm:2.0.1" @@ -2253,13 +2146,6 @@ __metadata: languageName: node linkType: hard -"create-require@npm:^1.1.0": - version: 1.1.1 - resolution: "create-require@npm:1.1.1" - checksum: 10/a9a1503d4390d8b59ad86f4607de7870b39cad43d929813599a23714831e81c520bddf61bcdd1f8e30f05fd3a2b71ae8538e946eb2786dc65c2bbc520f692eff - languageName: node - linkType: hard - "cross-spawn@npm:^7.0.0, cross-spawn@npm:^7.0.6": version: 7.0.6 resolution: "cross-spawn@npm:7.0.6" @@ -2335,21 +2221,12 @@ __metadata: languageName: node linkType: hard -"diff@npm:^4.0.1": - version: 4.0.2 - resolution: "diff@npm:4.0.2" - checksum: 10/ec09ec2101934ca5966355a229d77afcad5911c92e2a77413efda5455636c4cf2ce84057e2d7715227a2eeeda04255b849bd3ae3a4dd22eb22e86e76456df069 - languageName: node - linkType: hard - "docker-build-push@workspace:.": version: 0.0.0-use.local resolution: "docker-build-push@workspace:." dependencies: "@actions/core": "npm:^1.11.1" "@docker/actions-toolkit": "npm:0.62.1" - "@eslint/compat": "npm:^2.0.0" - "@eslint/eslintrc": "npm:^3.3.3" "@eslint/js": "npm:^9.39.2" "@types/node": "npm:^20.19.27" "@typescript-eslint/eslint-plugin": "npm:^8.50.0" @@ -2360,9 +2237,9 @@ __metadata: eslint: "npm:^9.39.2" eslint-config-prettier: "npm:^10.1.8" eslint-plugin-prettier: "npm:^5.5.4" + globals: "npm:^17.3.0" handlebars: "npm:^4.7.7" prettier: "npm:^3.7.4" - ts-node: "npm:^10.9.2" typescript: "npm:^5.9.3" vitest: "npm:^4.0.18" languageName: unknown @@ -3012,6 +2889,13 @@ __metadata: languageName: node linkType: hard +"globals@npm:^17.3.0": + version: 17.3.0 + resolution: "globals@npm:17.3.0" + checksum: 10/44ba2b7db93eb6a2531dfba09219845e21f2e724a4f400eb59518b180b7d5bcf7f65580530e3d3023d7dc2bdbacf5d265fd87c393f567deb9a2b0472b51c9d5e + languageName: node + linkType: hard + "gopd@npm:^1.2.0": version: 1.2.0 resolution: "gopd@npm:1.2.0" @@ -3527,13 +3411,6 @@ __metadata: languageName: node linkType: hard -"make-error@npm:^1.1.1": - version: 1.3.6 - resolution: "make-error@npm:1.3.6" - checksum: 10/b86e5e0e25f7f777b77fabd8e2cbf15737972869d852a22b7e73c17623928fccb826d8e46b9951501d3f20e51ad74ba8c59ed584f610526a48f8ccf88aaec402 - languageName: node - linkType: hard - "make-fetch-happen@npm:^13.0.0": version: 13.0.1 resolution: "make-fetch-happen@npm:13.0.1" @@ -4626,44 +4503,6 @@ __metadata: languageName: node linkType: hard -"ts-node@npm:^10.9.2": - version: 10.9.2 - resolution: "ts-node@npm:10.9.2" - dependencies: - "@cspotcode/source-map-support": "npm:^0.8.0" - "@tsconfig/node10": "npm:^1.0.7" - "@tsconfig/node12": "npm:^1.0.7" - "@tsconfig/node14": "npm:^1.0.0" - "@tsconfig/node16": "npm:^1.0.2" - acorn: "npm:^8.4.1" - acorn-walk: "npm:^8.1.1" - arg: "npm:^4.1.0" - create-require: "npm:^1.1.0" - diff: "npm:^4.0.1" - make-error: "npm:^1.1.1" - v8-compile-cache-lib: "npm:^3.0.1" - yn: "npm:3.1.1" - peerDependencies: - "@swc/core": ">=1.2.50" - "@swc/wasm": ">=1.2.50" - "@types/node": "*" - typescript: ">=2.7" - peerDependenciesMeta: - "@swc/core": - optional: true - "@swc/wasm": - optional: true - bin: - ts-node: dist/bin.js - ts-node-cwd: dist/bin-cwd.js - ts-node-esm: dist/bin-esm.js - ts-node-script: dist/bin-script.js - ts-node-transpile-only: dist/bin-transpile.js - ts-script: dist/bin-script-deprecated.js - checksum: 10/a91a15b3c9f76ac462f006fa88b6bfa528130dcfb849dd7ef7f9d640832ab681e235b8a2bc58ecde42f72851cc1d5d4e22c901b0c11aa51001ea1d395074b794 - languageName: node - linkType: hard - "tslib@npm:^1.10.0": version: 1.14.1 resolution: "tslib@npm:1.14.1" @@ -4819,13 +4658,6 @@ __metadata: languageName: node linkType: hard -"v8-compile-cache-lib@npm:^3.0.1": - version: 3.0.1 - resolution: "v8-compile-cache-lib@npm:3.0.1" - checksum: 10/88d3423a52b6aaf1836be779cab12f7016d47ad8430dffba6edf766695e6d90ad4adaa3d8eeb512cc05924f3e246c4a4ca51e089dccf4402caa536b5e5be8961 - languageName: node - linkType: hard - "vite@npm:^6.0.0 || ^7.0.0": version: 7.3.1 resolution: "vite@npm:7.3.1" @@ -5058,13 +4890,6 @@ __metadata: languageName: node linkType: hard -"yn@npm:3.1.1": - version: 3.1.1 - resolution: "yn@npm:3.1.1" - checksum: 10/2c487b0e149e746ef48cda9f8bad10fc83693cd69d7f9dcd8be4214e985de33a29c9e24f3c0d6bcf2288427040a8947406ab27f7af67ee9456e6b84854f02dd6 - languageName: node - linkType: hard - "yocto-queue@npm:^0.1.0": version: 0.1.0 resolution: "yocto-queue@npm:0.1.0"