Export with dep repos
All checks were successful
Unit tests / Unit tests (latest) (push) Successful in -1m59s
Unit tests / Unit tests (lts/hydrogen) (push) Successful in -2m0s
Distribution check / Generated files check (push) Successful in -1m58s
NPM Audit Check / Check NPM audit (push) Successful in -2m10s
Unit tests / Unit tests (lts/*) (push) Successful in -2m0s

This commit is contained in:
2025-11-09 23:57:42 -05:00
parent dd6940a77f
commit 8574ca8ecb
8 changed files with 54 additions and 14 deletions

View File

@@ -31,6 +31,8 @@ outputs:
description: whether a deletion is required or not
destination:
description: destination repo
deps:
description: which repos to enable while building
runs:
using: 'node16'

18
dist/index.js vendored
View File

@@ -41396,6 +41396,7 @@ async function parse(previous, current) {
build: false,
move: [],
delete: [],
deps: getDepRepo(actions.addRepo),
actions,
};
// can't delete if there's nothing to delete/no previous success
@@ -41422,9 +41423,6 @@ function parseRepoContents(repoContents, repository) {
};
});
}
function getDropped(oldPackages, newPackages) {
return oldPackages.filter(p => newPackages.filter(np => np.package === p.package).length === 0);
}
function isDelete(actions) {
return !!(actions.removeRepo && actions.addRepo === null);
}
@@ -41434,6 +41432,19 @@ function isAdd(actions) {
function isMove(actions) {
return !!(actions.removeRepo && actions.addRepo);
}
function getDepRepo(destination) {
const split = (destination || '').split('-');
switch (split[split.length - 1]) {
case 'testing':
case 'gremlins':
return 'testing';
case 'staging':
case 'goblins':
return 'staging';
default:
return 'stable';
}
}
async function tryRead(location) {
try {
const contents = isUrl(location) ? await (await distribution.get(location)).text() : await promises_namespaceObject.readFile(location, { encoding: 'utf-8' });
@@ -41518,6 +41529,7 @@ async function doParse() {
core.setOutput('move', diff.move.length > 0);
core.setOutput('delete', diff.delete.length > 0);
core.setOutput('destination', diff.actions.addRepo);
core.setOutput('deps', diff.deps);
}
//# sourceMappingURL=router.js.map
;// CONCATENATED MODULE: ./lib/src/index.js

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "pkgbase-yaml-parser",
"version": "1.0.0",
"version": "1.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "pkgbase-yaml-parser",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.11.1",

View File

@@ -1,6 +1,6 @@
{
"name": "pkgbase-yaml-parser",
"version": "1.0.0",
"version": "1.0.1",
"description": "compare Artix `pkgbase.yaml` files",
"keywords": [
"artix",

View File

@@ -1,9 +1,10 @@
import { type PathLike } from 'fs';
import fsp from 'fs/promises';
import { URL } from 'url';
import ky from 'ky';
import * as YAML from 'yaml';
export type DependencyRepo = 'stable' | 'testing' | 'staging';
export interface PackageInfo {
package: string;
repository: string;
@@ -25,6 +26,7 @@ export interface Result {
build: boolean;
move: PackageInfo[];
delete: PackageInfo[];
deps: DependencyRepo;
actions: Actions;
}
@@ -61,6 +63,7 @@ export async function parse(previous: string, current: string): Promise<Result>
build: false,
move: [],
delete: [],
deps: getDepRepo(actions.addRepo),
actions,
};
@@ -91,10 +94,6 @@ function parseRepoContents(repoContents: RepoContents, repository: string): Pack
});
}
function getDropped(oldPackages: PackageInfo[], newPackages: PackageInfo[]): PackageInfo[] {
return oldPackages.filter(p => newPackages.filter(np => np.package === p.package).length === 0);
}
function isDelete(actions: Actions): boolean {
return !!(actions.removeRepo && actions.addRepo === null);
}
@@ -107,6 +106,20 @@ function isMove(actions: Actions): boolean {
return !!(actions.removeRepo && actions.addRepo);
}
export function getDepRepo(destination: string): DependencyRepo {
const split = (destination || '').split('-');
switch(split[split.length - 1]) {
case 'testing':
case 'gremlins':
return 'testing';
case 'staging':
case 'goblins':
return 'staging';
default:
return 'stable';
}
}
export async function tryRead(location: string): Promise<PkgBase | null> {
try {
const contents = isUrl(location) ? await (await ky.get(location)).text() : await fsp.readFile(location, { encoding: 'utf-8' });

View File

@@ -78,4 +78,5 @@ async function doParse() {
core.setOutput('move', diff.move.length > 0);
core.setOutput('delete', diff.delete.length > 0);
core.setOutput('destination', diff.actions.addRepo);
core.setOutput('deps', diff.deps);
}

View File

@@ -1,6 +1,6 @@
import path from 'path';
import { describe, expect, it } from 'vitest';
import { parse, type Result } from '../src/pkgbase.js';
import { parse, getDepRepo, type Result } from '../src/pkgbase.js';
describe('pkgbase parser', () => {
it('can detect an add operation', async () => {
@@ -8,6 +8,7 @@ describe('pkgbase parser', () => {
build: true,
move: [],
delete: [],
deps: 'staging',
actions: {
addRepo: 'system-goblins',
removeRepo: null,
@@ -27,6 +28,7 @@ describe('pkgbase parser', () => {
build: true,
move: [],
delete: [],
deps: 'stable',
actions: {
addRepo: 'world',
removeRepo: null,
@@ -65,6 +67,7 @@ describe('pkgbase parser', () => {
"version": "2.14.14-3",
}
],
deps: 'stable',
actions: {
addRepo: 'world',
removeRepo: null,
@@ -96,6 +99,7 @@ describe('pkgbase parser', () => {
"repository": "world",
"version": "1:7.9.1-1",
}],
deps: 'stable',
actions: {
addRepo: 'world',
removeRepo: 'world-gremlins',
@@ -147,6 +151,7 @@ describe('pkgbase parser', () => {
"version": "2.14.14-3",
}
],
deps: 'stable',
actions: {
addRepo: 'world',
removeRepo: 'world-gremlins',
@@ -158,7 +163,7 @@ describe('pkgbase parser', () => {
}
};
const rDir = 'move-with-dropped';
await expect(parse(`https://git.sanin.dev/packages_test/pkgbase-yaml-parser/raw/branch/master/test/resources/${rDir}/pkgbase.old.yaml`, path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);
await expect(parse(`https://git.sanin.dev/packages_infra/pkgbase-yaml-parser/raw/branch/master/test/resources/${rDir}/pkgbase.old.yaml`, path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);
});
it('can detect a delete operation', async () => {
@@ -185,6 +190,7 @@ describe('pkgbase parser', () => {
version: "3.13.0-2",
}
],
deps: 'stable',
actions: {
addRepo: null,
removeRepo: 'world',
@@ -198,4 +204,10 @@ describe('pkgbase parser', () => {
const rDir = 'remove';
await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);
});
it('can handle Arch repos', async () => {
expect(getDepRepo('core')).to.be.equal('stable');
expect(getDepRepo('core-testing')).to.be.equal('testing');
expect(getDepRepo('extra-staging')).to.be.equal('staging');
});
});