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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions apps/cli/lib/dependency-management/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {
getWpCliPharPath,
getWpFilesPath,
} from '../server-files';
import { updateLatestSqliteCommandVersion } from './sqlite-command';
import { areDirectoriesDifferentBySizeAndMtime } from './utils';
import { getWordPressVersionFromInstallation, updateLatestWordPressVersion } from './wordpress';
import { updateLatestWpCliVersion } from './wp-cli';

type VersionReader = () => Promise< semver.SemVer | null >;

Expand Down Expand Up @@ -264,17 +262,9 @@ export async function setupServerFiles() {
}

export async function updateServerFiles() {
const steps: [ string, () => Promise< void > ][] = [
[ 'WordPress version', updateLatestWordPressVersion ],
[ 'WP-CLI', updateLatestWpCliVersion ],
[ 'SQLite integration', updateLatestSqliteCommandVersion ],
];

await Promise.all(
steps.map( ( [ name, step ] ) =>
step().catch( ( error ) => {
console.error( `Failed to update dependency ${ name }:`, error );
} )
)
);
try {
await updateLatestWordPressVersion();
} catch ( error ) {
console.error( 'Failed to update dependency WordPress version:', error );
}
}
60 changes: 0 additions & 60 deletions apps/cli/lib/dependency-management/sqlite-command.ts

This file was deleted.

35 changes: 0 additions & 35 deletions apps/cli/lib/dependency-management/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import { Writable } from 'stream';
import { isErrnoException } from '@studio/common/lib/is-errno-exception';
import ignore from 'ignore';
import { z } from 'zod';

export async function downloadFile( url: string, destinationPath: string ): Promise< void > {
try {
Expand All @@ -25,40 +24,6 @@ export async function downloadFile( url: string, destinationPath: string ): Prom
await response.body.pipeTo( Writable.toWeb( fs.createWriteStream( destinationPath ) ) );
}

const partialGithubReleaseSchema = z.object( {
tag_name: z.string(),
assets: z.array( z.object( { name: z.string(), browser_download_url: z.string() } ) ),
} );

export async function fetchLatestGithubRelease( repo: string ) {
const headers: HeadersInit = {
Accept: 'application/vnd.github.v3+json',
'User-Agent': 'wp-studio-cli',
};

// GitHub API has rate limits:
// - 60 requests/hour for unauthenticated requests
// - 5,000 requests/hour with token authentication
// In CI environments, the IP-based rate limit is shared across runners,
// so we authenticate with GITHUB_TOKEN when available.
if ( process.env.GITHUB_TOKEN ) {
headers.Authorization = `token ${ process.env.GITHUB_TOKEN }`;
}

const response = await fetch( `https://api.github.com/repos/${ repo }/releases/latest`, {
headers,
signal: AbortSignal.timeout( 5000 ),
} );

if ( ! response.ok ) {
throw new Error( `GitHub API request failed: ${ response.status } ${ response.statusText }` );
}

const rawResponse: unknown = await response.json();

return partialGithubReleaseSchema.parse( rawResponse );
}

const IGNORE_PATTERNS = [ '.DS_Store', 'Thumbs.db' ];
const IGNORE_INSTANCE = ignore().add( IGNORE_PATTERNS );

Expand Down
59 changes: 0 additions & 59 deletions apps/cli/lib/dependency-management/wp-cli.ts

This file was deleted.

Loading