Compare commits

...

5 Commits

Author SHA1 Message Date
CrazyMax
91016a9d0c
Merge 5fe52f9b61 into da5b89b92c 2026-03-20 17:11:21 +01:00
CrazyMax
da5b89b92c
Merge pull request #943 from crazy-max/codeql
Some checks failed
codeql / analyze (push) Failing after 13m29s
test / test (push) Successful in 2m24s
validate / prepare (push) Successful in 56s
validate / validate (push) Successful in 1m6s
ci: update codeql workflow
2026-03-20 16:57:15 +01:00
CrazyMax
b78dc2c156
ci: update codeql workflow
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-20 11:48:51 +01:00
CrazyMax
5fe52f9b61
chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-13 15:04:26 +01:00
CrazyMax
db3673140b
add opt-in skip for missing login credentials
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-13 15:02:51 +01:00
5 changed files with 96 additions and 46 deletions

View File

@ -5,46 +5,41 @@ on:
branches: branches:
- 'master' - 'master'
- 'releases/v*' - 'releases/v*'
paths:
- '.github/workflows/codeql.yml'
- 'dist/**'
- 'src/**'
pull_request: pull_request:
paths:
- '.github/workflows/codeql.yml'
- 'dist/**'
- 'src/**'
permissions: permissions:
actions: read actions: read
contents: read contents: read
security-events: write security-events: write
env:
NODE_VERSION: "24"
jobs: jobs:
analyze: analyze:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language:
- javascript-typescript
steps: steps:
- -
name: Checkout name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
-
name: Enable corepack
run: |
corepack enable
yarn --version
-
name: Set up Node
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- -
name: Initialize CodeQL name: Initialize CodeQL
uses: github/codeql-action/init@v4 uses: github/codeql-action/init@v4
with: with:
languages: ${{ matrix.language }} languages: javascript-typescript
config: | build-mode: none
paths:
- src
-
name: Autobuild
uses: github/codeql-action/autobuild@v4
- -
name: Perform CodeQL Analysis name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4 uses: github/codeql-action/analyze@v4
with: with:
category: "/language:${{matrix.language}}" category: "/language:javascript-typescript"

View File

@ -1,26 +1,27 @@
import {expect, test, vi} from 'vitest'; import {afterEach, beforeEach, expect, test, vi} from 'vitest';
import * as path from 'path';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
import {loginStandard, logout} from '../src/docker.js'; import {loginStandard, logout} from '../src/docker.js';
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner'); beforeEach(() => {
delete process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS;
});
afterEach(() => {
delete process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS;
});
test('loginStandard calls exec', async () => { test('loginStandard calls exec', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment const execSpy = vi.spyOn(Docker, 'getExecOutput').mockResolvedValue({
// @ts-ignore exitCode: 0,
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => { stdout: '',
return { stderr: ''
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
};
}); });
const username = 'dbowie'; const username = 'dbowie';
const password = 'groundcontrol'; const password = 'groundcontrol';
const registry = 'https://ghcr.io'; const registry = 'ghcr.io';
await loginStandard(registry, username, password); await loginStandard(registry, username, password);
@ -30,6 +31,7 @@ test('loginStandard calls exec', async () => {
// we don't want to check env opt // we don't want to check env opt
callfunc[1].env = undefined; callfunc[1].env = undefined;
} }
expect(execSpy).toHaveBeenCalledWith(['login', '--password-stdin', '--username', username, registry], { expect(execSpy).toHaveBeenCalledWith(['login', '--password-stdin', '--username', username, registry], {
input: Buffer.from(password), input: Buffer.from(password),
silent: true, silent: true,
@ -37,27 +39,68 @@ test('loginStandard calls exec', async () => {
}); });
}); });
test('logout calls exec', async () => { test('loginStandard throws if username and password are missing', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment const execSpy = vi.spyOn(Docker, 'getExecOutput');
// @ts-ignore const login = loginStandard('ghcr.io', '', '');
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => { expect(execSpy).not.toHaveBeenCalled();
return { return expect(login).rejects.toThrow('Username and password required');
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
};
}); });
const registry = 'https://ghcr.io'; test('loginStandard throws if username is missing', () => {
const execSpy = vi.spyOn(Docker, 'getExecOutput');
const login = loginStandard('ghcr.io', '', 'groundcontrol');
expect(execSpy).not.toHaveBeenCalled();
return expect(login).rejects.toThrow('Username required');
});
test('loginStandard throws if password is missing', () => {
const execSpy = vi.spyOn(Docker, 'getExecOutput');
const login = loginStandard('ghcr.io', 'dbowie', '');
expect(execSpy).not.toHaveBeenCalled();
return expect(login).rejects.toThrow('Password required');
});
test('loginStandard skips if both credentials are missing and env opt-in is enabled', () => {
process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS = 'true';
const execSpy = vi.spyOn(Docker, 'getExecOutput');
const login = loginStandard('ghcr.io', '', '');
expect(execSpy).not.toHaveBeenCalled();
return expect(login).resolves.toBeUndefined();
});
test('loginStandard skips if username is missing and env opt-in is enabled', () => {
process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS = 'true';
const execSpy = vi.spyOn(Docker, 'getExecOutput');
const login = loginStandard('ghcr.io', '', 'groundcontrol');
expect(execSpy).not.toHaveBeenCalled();
return expect(login).resolves.toBeUndefined();
});
test('loginStandard skips if password is missing and env opt-in is enabled', () => {
process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS = 'true';
const execSpy = vi.spyOn(Docker, 'getExecOutput');
const login = loginStandard('ghcr.io', 'dbowie', '');
expect(execSpy).not.toHaveBeenCalled();
return expect(login).resolves.toBeUndefined();
});
test('logout calls exec', async () => {
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: '',
stderr: ''
});
const registry = 'ghcr.io';
await logout(registry, ''); await logout(registry, '');
expect(execSpy).toHaveBeenCalledTimes(1); expect(execSpy).toHaveBeenCalledTimes(1);
const callfunc = execSpy.mock.calls[0]; const callfunc = execSpy.mock.calls[0];
if (callfunc && callfunc[1]) { if (callfunc && callfunc[1]) {
// we don't want to check env opt // we don't want to check env opt
callfunc[1].env = undefined; callfunc[1].env = undefined;
} }
expect(execSpy).toHaveBeenCalledWith(['logout', registry], { expect(execSpy).toHaveBeenCalledWith(['logout', registry], {
ignoreReturnCode: true ignoreReturnCode: true
}); });

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
import {Util} from '@docker/actions-toolkit/lib/util.js';
import * as aws from './aws.js'; import * as aws from './aws.js';
import * as context from './context.js'; import * as context from './context.js';
@ -34,6 +35,10 @@ export async function logout(registry: string, configDir: string): Promise<void>
} }
export async function loginStandard(registry: string, username: string, password: string, scope?: string): Promise<void> { export async function loginStandard(registry: string, username: string, password: string, scope?: string): Promise<void> {
if ((!username || !password) && skipLoginIfMissingCredsEnabled()) {
core.info(`Skipping login to ${registry}. Username or password is not set and DOCKER_LOGIN_SKIP_IF_MISSING_CREDS is enabled.`);
return;
}
if (!username && !password) { if (!username && !password) {
throw new Error('Username and password required'); throw new Error('Username and password required');
} }
@ -79,3 +84,10 @@ async function loginExec(registry: string, username: string, password: string, s
core.info('Login Succeeded!'); core.info('Login Succeeded!');
}); });
} }
function skipLoginIfMissingCredsEnabled(): boolean {
if (process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS) {
return Util.parseBool(process.env.DOCKER_LOGIN_SKIP_IF_MISSING_CREDS);
}
return false;
}