Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(datasource): add debian datasource #30071

Merged
merged 81 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a019ba8
feat(datasource): add debian datasource
oxdev03 Jul 6, 2024
daa1a80
disable failing test
oxdev03 Jul 6, 2024
d57eaba
fix example
oxdev03 Jul 6, 2024
762d116
add missing tests
oxdev03 Jul 7, 2024
8649885
use function for test urls
oxdev03 Jul 7, 2024
0f511de
remove unnecessary trace
oxdev03 Jul 7, 2024
d694b4e
Merge remote-tracking branch 'origin/main' into feat/debian-datasource
oxdev03 Jul 9, 2024
31772b6
remove loose versioning
oxdev03 Jul 9, 2024
7e1ae2d
add ts docs
oxdev03 Jul 9, 2024
db15fa7
Apply suggestions from code review
oxdev03 Jul 9, 2024
0d5cad8
Merge remote-tracking branch 'origin/feat/debian-datasource' into fea…
oxdev03 Jul 9, 2024
b979bd1
fix error
oxdev03 Jul 9, 2024
1abdbb5
split up impl
oxdev03 Jul 9, 2024
b1d309c
Merge branch 'main' into feat/debian-datasource
oxdev03 Jul 25, 2024
7d30942
Merge branch 'main' into feat/debian-datasource
rarkins Jul 26, 2024
4608379
convert to named functions
oxdev03 Aug 5, 2024
c7e543b
deactivate default caching
oxdev03 Aug 5, 2024
021ea95
remove package rules example
oxdev03 Aug 5, 2024
5675c77
remove stale comment
oxdev03 Aug 5, 2024
47c75b5
use debug level instead
oxdev03 Aug 5, 2024
72f8110
Merge remote-tracking branch 'origin/main' into feat/debian-datasource
oxdev03 Aug 5, 2024
8653c8e
Merge remote-tracking branch 'origin/main' into feat/debian-datasource
oxdev03 Aug 5, 2024
403d0cb
parse all package from extracted package index
oxdev03 Aug 6, 2024
976b49c
downloadAndExtractPackage continue with next supported compression in…
oxdev03 Aug 6, 2024
30e479f
validate compressed package checksum using InRelease file
oxdev03 Aug 6, 2024
af252ea
Apply suggestions from code review
oxdev03 Aug 10, 2024
035179f
Apply suggestions from code review
oxdev03 Aug 10, 2024
9ea7160
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
d2fdad7
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
f97ace5
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
3110cb9
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
44e87be
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
8aea126
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
f07f390
Update lib/modules/datasource/deb/index.spec.ts
oxdev03 Aug 10, 2024
df5198c
fix tests
oxdev03 Aug 10, 2024
3297e33
improve description
oxdev03 Aug 10, 2024
1f1d4cc
Apply suggestions from code review
oxdev03 Aug 13, 2024
b816ecd
fix suggestion
oxdev03 Aug 13, 2024
87a037f
Merge remote-tracking branch 'upstream/main' into feat/debian-datasource
oxdev03 Aug 13, 2024
1bdbf77
Merge remote-tracking branch 'upstream/main' into feat/debian-datasource
oxdev03 Aug 17, 2024
2f6fb80
use deb cdn instead
oxdev03 Aug 17, 2024
f0765c4
fix linting issue, add test for parallel lookup, fix lookup for packa…
oxdev03 Aug 17, 2024
0e4707c
fix import order
oxdev03 Aug 17, 2024
2546776
Merge branch 'main' into feat/debian-datasource
secustor Aug 19, 2024
c61dcbd
Merge remote-tracking branch 'upstream/main' into feat/debian-datasource
oxdev03 Aug 19, 2024
02f98af
use type import instead
oxdev03 Aug 19, 2024
7f14478
it should also parse same package with other versions
oxdev03 Aug 20, 2024
7301aa5
Merge branch 'renovatebot:main' into feat/debian-datasource
oxdev03 Aug 20, 2024
d1202eb
Update lib/modules/datasource/deb/release.ts
oxdev03 Aug 20, 2024
b778f25
set registryStrategy to merge
oxdev03 Aug 21, 2024
33f717a
Merge branch 'main' into feat/debian-datasource
oxdev03 Aug 21, 2024
b911784
fix minor review findings
oxdev03 Aug 21, 2024
7664cc7
use util function
oxdev03 Aug 21, 2024
d1b37ec
set cache decorator
oxdev03 Aug 21, 2024
d5f18c1
fix minor review findings
oxdev03 Aug 21, 2024
b911c42
remove support for multiple compression as currently only one exists
oxdev03 Aug 21, 2024
eb4309a
Merge branch 'main' into feat/debian-datasource
oxdev03 Aug 21, 2024
92ff919
remove redundant cache decorator as already covered in getPackageIndex
oxdev03 Aug 21, 2024
de27ef8
Merge branch 'feat/debian-datasource' of https://github.com/oxdev03/r…
oxdev03 Aug 21, 2024
87e67f3
Revert "remove redundant cache decorator as already covered in getPac…
oxdev03 Aug 22, 2024
21a4ef5
Merge branch 'main' into feat/debian-datasource
oxdev03 Aug 22, 2024
8e1463b
Apply suggestions from code review
oxdev03 Aug 22, 2024
97018b1
move vars to describe block
oxdev03 Aug 22, 2024
bb9f352
cleanup cache dir
oxdev03 Aug 22, 2024
5698896
validate http head call using nock options
oxdev03 Aug 24, 2024
ee03bdf
test(regex-manager): Separate arrange/act/assert with spaces (#30972)
zharinov Aug 22, 2024
c3ea33a
fix(deps): update ghcr.io/renovatebot/base-image docker tag to v7.16.…
renovate[bot] Aug 22, 2024
2923d8a
fix(manager/git-submodules): get recorded submodule commit (#30976)
amezin Aug 23, 2024
62d80b1
chore(deps): update dependency mkdocs-material to v9.5.33 (#30981)
renovate[bot] Aug 23, 2024
e914d9a
feat(deps): update ghcr.io/renovatebot/base-image docker tag to v7.17…
renovate[bot] Aug 23, 2024
5f648f3
chore(deps): update github/codeql-action action to v3.26.5 (#30986)
renovate[bot] Aug 23, 2024
80f51c5
chore(deps): update dependency type-fest to v4.25.0 (#30987)
renovate[bot] Aug 24, 2024
2bd4ede
docs(docker): add ghworkflows example for GAR with Workload Identity …
jazzlyn Aug 24, 2024
a1a01a1
chore(deps): update dependency google-github-actions/auth to v2.1.5 (…
renovate[bot] Aug 24, 2024
2cb37e9
chore(deps): update dependency renovatebot/github-action to v40.2.6 (…
renovate[bot] Aug 24, 2024
78399ec
Merge branch 'main' into feat/debian-datasource
oxdev03 Aug 24, 2024
82ec24f
Merge branch 'main' into feat/debian-datasource
oxdev03 Aug 25, 2024
8101e10
Apply suggestions from code review
oxdev03 Aug 26, 2024
bb04503
Merge branch 'renovatebot:main' into feat/debian-datasource
oxdev03 Aug 26, 2024
7d32385
format code
oxdev03 Aug 26, 2024
3d0ed1d
Merge branch 'main' into feat/debian-datasource
secustor Aug 27, 2024
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
2 changes: 2 additions & 0 deletions lib/modules/datasource/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CrateDatasource } from './crate';
import { CustomDatasource } from './custom';
import { DartDatasource } from './dart';
import { DartVersionDatasource } from './dart-version';
import { DebDatasource } from './deb';
import { DenoDatasource } from './deno';
import { DockerDatasource } from './docker';
import { DotnetVersionDatasource } from './dotnet-version';
Expand Down Expand Up @@ -84,6 +85,7 @@ api.set(CrateDatasource.id, new CrateDatasource());
api.set(CustomDatasource.id, new CustomDatasource());
api.set(DartDatasource.id, new DartDatasource());
api.set(DartVersionDatasource.id, new DartVersionDatasource());
api.set(DebDatasource.id, new DebDatasource());
api.set(DenoDatasource.id, new DenoDatasource());
api.set(DockerDatasource.id, new DockerDatasource());
api.set(DotnetVersionDatasource.id, new DotnetVersionDatasource());
Expand Down
1,257 changes: 1,257 additions & 0 deletions lib/modules/datasource/deb/__fixtures__/InRelease

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions lib/modules/datasource/deb/__fixtures__/Packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Package: album
Version: 4.15-1
Installed-Size: 288
Maintainer: Salvo 'LtWorf' Tomaselli <[email protected]>
Architecture: all
Depends: perl:any, imagemagick
Recommends: album-data
Suggests: httpd, jhead, libav-tools
Description: HTML photo album generator with theme support
Homepage: http://marginalhacks.com/Hacks/album
Description-md5: 3eaaefa453087570fb45ac51eeccbe7c
Tag: implemented-in::perl, interface::commandline, interface::web,
role::program, scope::application, use::browsing, use::organizing,
web::application, works-with-format::html, works-with::image,
works-with::image:raster, works-with::text
Section: non-free/web
Priority: optional
Filename: pool/non-free/a/album/album_4.15-1_all.deb
Size: 89962
MD5sum: 7ed9561371bc198dab9f88741b3386ae
SHA256: 336d96db2998e9a80d00fef36ad38756463cfbd516d1f89b97ecdff22f2b6ec1

Package: album-data
Version: 4.05-7.2
Installed-Size: 7936
Maintainer: Salvo 'LtWorf' Tomaselli <[email protected]>
Architecture: all
Depends: album
Description: themes, plugins and translations for album
Homepage: http://marginalhacks.com/Hacks/album
Description-md5: 34adea76df6b2c02712e3838461edbb2
Tag: role::app-data
Section: non-free/web
Priority: optional
Filename: pool/non-free/a/album-data/album-data_4.05-7.2_all.deb
Size: 5469888
MD5sum: bfecda545171260a755ab5b4acd97aa6
SHA256: 8e16c340d46e53752d5916c7f8aca665aa81a78614bcae0ad7b9decf555c114e

Package: album-data
Version: 4.05-7.3
Installed-Size: 7936
Maintainer: Salvo 'LtWorf' Tomaselli <[email protected]>
Architecture: all
Depends: album
Description: themes, plugins and translations for album
Homepage: http://marginalhacks.com/Hacks/album
Description-md5: 34adea76df6b2c02712e3838461edbb2
Tag: role::app-data
Section: non-free/web
Priority: optional
Filename: pool/non-free/a/album-data/album-data_4.05-7.2_all.deb
Size: 5469888
MD5sum: bfecda545171260a755ab5b4acd97aa6
SHA256: 8e16c340d46e53752d5916c7f8aca665aa81a78614bcae0ad7b9decf555c114e

Package: alien-arena-data
Version: 7.71.3+ds-1
Installed-Size: 1918877
Maintainer: Debian Games Team <[email protected]>
Architecture: all
Depends: fonts-freefont-ttf, fonts-aenigma
Enhances: alien-arena (>= 7.71.3+ds), alien-arena-server (>= 7.71.3+ds)
Description: Game data files for Alien Arena
Homepage: https://martianbackup.com
Description-md5: f930829d2a1207940bee317dc2015735
Tag: game::fps, role::app-data, use::gameplaying
Section: non-free/games
Priority: optional
Filename: pool/non-free/a/alien-arena-data/alien-arena-data_7.71.3+ds-1_all.deb
Size: 766655844
MD5sum: 447e0d3a42973dbf3d87df28359501d2
SHA256: a3fdaf2b0b9e969149642300f0781f7cfdd3ed33f49be38afe58e89531a21b70
Binary file not shown.
Binary file added lib/modules/datasource/deb/__fixtures__/Packages2.gz
Binary file not shown.
57 changes: 57 additions & 0 deletions lib/modules/datasource/deb/checksum.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { DirectoryResult } from 'tmp-promise';
import { dir } from 'tmp-promise';
import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import { outputCacheFile } from '../../../util/fs';
import { computeFileChecksum, parseChecksumsFromInRelease } from './checksum';

const fixtureInRelease = Fixtures.getBinary(`InRelease`).toString();

describe('modules/datasource/deb/checksum', () => {
let cacheDir: DirectoryResult | null;

beforeEach(async () => {
const cacheDir = await dir({ unsafeCleanup: true });
GlobalConfig.set({ cacheDir: cacheDir.path });
});

afterEach(async () => {
await cacheDir?.cleanup();
cacheDir = null;
});

describe('parseChecksumsFromInRelease', () => {
it('parses the checksum for the specified package', () => {
const expectedHash =
'bf77b15e68c5bfd7267c76a34172021de8f10f861f41ebda7b39d1390dd4bf9a';
expect(
parseChecksumsFromInRelease(
fixtureInRelease,
'contrib/binary-amd64/Packages.gz',
),
).toBe(expectedHash);

expect(
parseChecksumsFromInRelease(
fixtureInRelease,
'non-existing/binary-amd64/Packages.gz',
),
).toBeNull();
});
});

describe('computeFileChecksum', () => {
it('computes the checksum of a file', async () => {
await outputCacheFile('file.txt', 'bar');

const expectedHash =
'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9';

expect(await computeFileChecksum('file.txt')).toBe(expectedHash);
});

it('should fail if there is an error in the stream', async () => {
await expect(computeFileChecksum('file.txt')).rejects.toThrow();
});
});
});
40 changes: 40 additions & 0 deletions lib/modules/datasource/deb/checksum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createCacheReadStream } from '../../../util/fs';
import { hashStream } from '../../../util/hash';
import { escapeRegExp, newlineRegex, regEx } from '../../../util/regex';

/**
* Parses the SHA256 checksum for a specified package path from the InRelease content.
*
* @param inReleaseContent - content of the InRelease file
* @param packagePath - path of the package file (e.g., 'contrib/binary-amd64/Packages.gz')
* @returns The SHA256 checksum if found, otherwise undefined
*/
export function parseChecksumsFromInRelease(
inReleaseContent: string,
packagePath: string,
): string | null {
const lines = inReleaseContent.split(newlineRegex);
const regex = regEx(
`([a-f0-9]{64})\\s+\\d+\\s+${escapeRegExp(packagePath)}$`,
);

for (const line of lines) {
const match = regex.exec(line);
if (match) {
return match[1];
}
}

return null;
}

/**
* Computes the SHA256 checksum of a specified file.
*
* @param filePath - path of the file
* @returns resolves to the SHA256 checksum
*/
export function computeFileChecksum(filePath: string): Promise<string> {
const stream = createCacheReadStream(filePath);
return hashStream(stream, 'sha256');
}
17 changes: 17 additions & 0 deletions lib/modules/datasource/deb/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { PackageDescription } from './types';

/**
* This specifies the directory where the extracted and downloaded packages files are stored relative to cacheDir.
* The folder will be created automatically if it doesn't exist.
*/
export const cacheSubDir: string = 'deb';

export const requiredPackageKeys: Array<keyof PackageDescription> = [
'Package',
'Version',
];

export const packageKeys: Array<keyof PackageDescription> = [
...requiredPackageKeys,
'Homepage',
];
35 changes: 35 additions & 0 deletions lib/modules/datasource/deb/file.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { DirectoryResult } from 'tmp-promise';
import { dir } from 'tmp-promise';
import upath from 'upath';
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import { extract } from './file';

const fixturePackagesArchivePath = Fixtures.getPath(`Packages.gz`);

describe('modules/datasource/deb/file', () => {
let cacheDir: DirectoryResult | null;
let extractedPackageFile: string;

beforeEach(async () => {
cacheDir = await dir({ unsafeCleanup: true });
GlobalConfig.set({ cacheDir: cacheDir.path });

const extractionFolder = await fs.ensureCacheDir('file');
extractedPackageFile = upath.join(extractionFolder, `package.txt`);
});

afterEach(async () => {
await cacheDir?.cleanup();
cacheDir = null;
});

describe('extract', () => {
it('should throw error for unsupported compression', async () => {
await expect(
extract(fixturePackagesArchivePath, 'xz', extractedPackageFile),
).rejects.toThrow('Unsupported compression standard');
});
});
});
37 changes: 37 additions & 0 deletions lib/modules/datasource/deb/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createUnzip } from 'zlib';
import * as fs from '../../../util/fs';

/**
* Extracts the specified compressed file to the output file.
*
* @param compressedFile - The path to the compressed file.
* @param compression - The compression method used (currently only 'gz' is supported).
* @param outputFile - The path where the extracted content will be stored.
* @throws Will throw an error if the compression method is unknown.
*/
export async function extract(
compressedFile: string,
compression: string,
outputFile: string,
): Promise<void> {
if (compression === 'gz') {
const source = fs.createCacheReadStream(compressedFile);
const destination = fs.createCacheWriteStream(outputFile);
await fs.pipeline(source, createUnzip(), destination);
} else {
throw new Error(`Unsupported compression standard '${compression}'`);
}
}

/**
* Checks if the file exists and retrieves its creation time.
*
* @param filePath - The path to the file.
* @returns The creation time if the file exists, otherwise undefined.
*/
export async function getFileCreationTime(
filePath: string,
): Promise<Date | undefined> {
const stats = await fs.statCacheFile(filePath);
return stats?.ctime;
}
Loading