Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/targets/sdk-pypi/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { fakeShipContext } from '@profullstack/sh1pt-core/testing';
import { beforeEach, describe, expect, it, vi } from 'vitest';

const { execMock } = vi.hoisted(() => ({
execMock: vi.fn(),
}));

vi.mock('@profullstack/sh1pt-core', async () => ({
...await vi.importActual<typeof import('@profullstack/sh1pt-core')>('@profullstack/sh1pt-core'),
exec: execMock,
}));

import adapter from './index.js';

beforeEach(() => {
vi.clearAllMocks();
});

describe('sdk-pypi target adapter', () => {
it('does not require a token or invoke twine for dry-run shipping', async () => {
const secret = vi.fn(() => undefined);

await expect(adapter.ship(fakeShipContext({
dryRun: true,
secret,
}) as any, {})).resolves.toEqual({
id: 'dry-run',
meta: { repository: 'https://upload.pypi.org/legacy/' },
});

expect(secret).not.toHaveBeenCalled();
expect(execMock).not.toHaveBeenCalled();
});
});
12 changes: 6 additions & 6 deletions packages/targets/sdk-pypi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ export default defineTarget<Config>({
},

async ship(ctx, config) {
const repository = config.repository ?? 'https://upload.pypi.org/legacy/';
if (ctx.dryRun) {
ctx.log('pypi: dry-run — would upload distribution');
return { id: 'dry-run', meta: { repository } };
}

const token = ctx.secret('PYPI_TOKEN');
if (!token) {
throw new Error('PYPI_TOKEN not set. Run: sh1pt secret set PYPI_TOKEN <token>');
}

const repository = config.repository ?? 'https://upload.pypi.org/legacy/';
const repoFlag = config.repository === 'testpypi'
? ['--repository', 'testpypi']
: ['--repository-url', repository];

ctx.log(`pypi: uploading to ${repository}`);
if (ctx.dryRun) {
ctx.log('pypi: dry-run — would upload distribution');
return { id: 'dry-run', meta: { repository } };
}

const { stdout } = await exec(
'twine',
[
Expand Down
Loading