Skip to content

Commit

Permalink
fix(php): use github for latest composer release
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Dec 11, 2024
1 parent c23e372 commit 170c9b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
11 changes: 3 additions & 8 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,13 @@ https://github.com/containerbase/php-prebuild/releases/8.3.2/php-8.3.2-jammy-x86
Composer releases are downloaded from:

- `https://github.com/containerbase/composer-prebuild/releases`
- `https://getcomposer.org/versions`

The first url is used for downloads.
The last url is only used when `latest` or nothing is passed as version.
Then we try to find the latest version from getcomposer.org.

Samples:

```txt
https://github.com/containerbase/composer-prebuild/releases/2.7.7/composer-2.7.7.tar.xz.sha512
https://github.com/containerbase/composer-prebuild/releases/2.7.7/composer-2.7.7.tar.xz
https://getcomposer.org/versions
https://github.com/containerbase/composer-prebuild/releases/download/2.7.7/composer-2.7.7.tar.xz.sha512
https://github.com/containerbase/composer-prebuild/releases/download/2.7.7/composer-2.7.7.tar.xz
https://github.com/containerbase/composer-prebuild/releases/latest/download/version
```

## `powershell`
Expand Down
16 changes: 2 additions & 14 deletions src/cli/tools/php/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { join } from 'node:path';
import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';
import { execa } from 'execa';
import { inject, injectable } from 'inversify';
import { z } from 'zod';
import { BaseInstallService } from '../../install-tool/base-install.service';
import { ToolVersionResolver } from '../../install-tool/tool-version-resolver';
import {
Expand All @@ -12,7 +11,6 @@ import {
HttpService,
PathService,
} from '../../services';
import { semverSort } from '../../utils';

@injectable()
export class ComposerInstallService extends BaseInstallService {
Expand Down Expand Up @@ -62,20 +60,10 @@ export class ComposerVersionResolver extends ToolVersionResolver {

async resolve(version: string | undefined): Promise<string | undefined> {
if (!isNonEmptyStringAndNotWhitespace(version) || version === 'latest') {
const meta = ComposerVersionsSchema.parse(
await this.http.getJson('https://getcomposer.org/versions'),
return await this.http.get(
`https://github.com/containerbase/${this.tool}-prebuild/releases/latest/download/version`,
);
// we know that the latest version is the first entry, so search for first lts
return meta;
}
return version;
}
}

const ComposerVersionsSchema = z
.object({
stable: z.array(z.object({ version: z.string() })),
})
.transform(({ stable }) => {
return semverSort(stable.map((v) => v.version)).pop();
});

0 comments on commit 170c9b3

Please sign in to comment.