Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8574ca8ecb | |||
| dd6940a77f | |||
| 8ce406f86a |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Cory Sanin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -31,6 +31,8 @@ outputs:
|
|||||||
description: whether a deletion is required or not
|
description: whether a deletion is required or not
|
||||||
destination:
|
destination:
|
||||||
description: destination repo
|
description: destination repo
|
||||||
|
deps:
|
||||||
|
description: which repos to enable while building
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
|
|||||||
24
dist/index.js
vendored
24
dist/index.js
vendored
@@ -41396,6 +41396,7 @@ async function parse(previous, current) {
|
|||||||
build: false,
|
build: false,
|
||||||
move: [],
|
move: [],
|
||||||
delete: [],
|
delete: [],
|
||||||
|
deps: getDepRepo(actions.addRepo),
|
||||||
actions,
|
actions,
|
||||||
};
|
};
|
||||||
// can't delete if there's nothing to delete/no previous success
|
// can't delete if there's nothing to delete/no previous success
|
||||||
@@ -41404,11 +41405,11 @@ async function parse(previous, current) {
|
|||||||
result.delete.push(...parseRepoContents(repo, actions.removeRepo));
|
result.delete.push(...parseRepoContents(repo, actions.removeRepo));
|
||||||
}
|
}
|
||||||
else if (isMove(actions)) {
|
else if (isMove(actions)) {
|
||||||
const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
|
result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
|
||||||
prev && result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving));
|
prev && result.delete.push(...parseRepoContents(prev.repos[actions.addRepo], actions.addRepo));
|
||||||
}
|
}
|
||||||
else if ((result.build = isAdd(actions)) && prev) {
|
else if ((result.build = isAdd(actions)) && prev) {
|
||||||
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo)));
|
result.delete.push(...parseRepoContents(prev.repos[actions.addRepo], actions.addRepo));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -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) {
|
function isDelete(actions) {
|
||||||
return !!(actions.removeRepo && actions.addRepo === null);
|
return !!(actions.removeRepo && actions.addRepo === null);
|
||||||
}
|
}
|
||||||
@@ -41434,6 +41432,19 @@ function isAdd(actions) {
|
|||||||
function isMove(actions) {
|
function isMove(actions) {
|
||||||
return !!(actions.removeRepo && actions.addRepo);
|
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) {
|
async function tryRead(location) {
|
||||||
try {
|
try {
|
||||||
const contents = isUrl(location) ? await (await distribution.get(location)).text() : await promises_namespaceObject.readFile(location, { encoding: 'utf-8' });
|
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('move', diff.move.length > 0);
|
||||||
core.setOutput('delete', diff.delete.length > 0);
|
core.setOutput('delete', diff.delete.length > 0);
|
||||||
core.setOutput('destination', diff.actions.addRepo);
|
core.setOutput('destination', diff.actions.addRepo);
|
||||||
|
core.setOutput('deps', diff.deps);
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=router.js.map
|
//# sourceMappingURL=router.js.map
|
||||||
;// CONCATENATED MODULE: ./lib/src/index.js
|
;// CONCATENATED MODULE: ./lib/src/index.js
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "pkgbase-yaml-parser",
|
"name": "pkgbase-yaml-parser",
|
||||||
"version": "0.0.1",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pkgbase-yaml-parser",
|
"name": "pkgbase-yaml-parser",
|
||||||
"version": "0.0.1",
|
"version": "1.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pkgbase-yaml-parser",
|
"name": "pkgbase-yaml-parser",
|
||||||
"version": "0.0.1",
|
"version": "1.0.1",
|
||||||
"description": "compare Artix `pkgbase.yaml` files",
|
"description": "compare Artix `pkgbase.yaml` files",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"artix",
|
"artix",
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { type PathLike } from 'fs';
|
|
||||||
import fsp from 'fs/promises';
|
import fsp from 'fs/promises';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import ky from 'ky';
|
import ky from 'ky';
|
||||||
import * as YAML from 'yaml';
|
import * as YAML from 'yaml';
|
||||||
|
|
||||||
|
export type DependencyRepo = 'stable' | 'testing' | 'staging';
|
||||||
|
|
||||||
export interface PackageInfo {
|
export interface PackageInfo {
|
||||||
package: string;
|
package: string;
|
||||||
repository: string;
|
repository: string;
|
||||||
@@ -25,6 +26,7 @@ export interface Result {
|
|||||||
build: boolean;
|
build: boolean;
|
||||||
move: PackageInfo[];
|
move: PackageInfo[];
|
||||||
delete: PackageInfo[];
|
delete: PackageInfo[];
|
||||||
|
deps: DependencyRepo;
|
||||||
actions: Actions;
|
actions: Actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +63,7 @@ export async function parse(previous: string, current: string): Promise<Result>
|
|||||||
build: false,
|
build: false,
|
||||||
move: [],
|
move: [],
|
||||||
delete: [],
|
delete: [],
|
||||||
|
deps: getDepRepo(actions.addRepo),
|
||||||
actions,
|
actions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,11 +73,11 @@ export async function parse(previous: string, current: string): Promise<Result>
|
|||||||
result.delete.push(...parseRepoContents(repo, actions.removeRepo));
|
result.delete.push(...parseRepoContents(repo, actions.removeRepo));
|
||||||
}
|
}
|
||||||
else if (isMove(actions)) {
|
else if (isMove(actions)) {
|
||||||
const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
|
result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
|
||||||
prev && result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving));
|
prev && result.delete.push(...parseRepoContents(prev.repos[actions.addRepo], actions.addRepo));
|
||||||
}
|
}
|
||||||
else if ((result.build = isAdd(actions)) && prev) {
|
else if ((result.build = isAdd(actions)) && prev) {
|
||||||
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo)));
|
result.delete.push(...parseRepoContents(prev.repos[actions.addRepo], actions.addRepo));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -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 {
|
function isDelete(actions: Actions): boolean {
|
||||||
return !!(actions.removeRepo && actions.addRepo === null);
|
return !!(actions.removeRepo && actions.addRepo === null);
|
||||||
}
|
}
|
||||||
@@ -107,6 +106,20 @@ function isMove(actions: Actions): boolean {
|
|||||||
return !!(actions.removeRepo && actions.addRepo);
|
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> {
|
export async function tryRead(location: string): Promise<PkgBase | null> {
|
||||||
try {
|
try {
|
||||||
const contents = isUrl(location) ? await (await ky.get(location)).text() : await fsp.readFile(location, { encoding: 'utf-8' });
|
const contents = isUrl(location) ? await (await ky.get(location)).text() : await fsp.readFile(location, { encoding: 'utf-8' });
|
||||||
|
|||||||
@@ -78,4 +78,5 @@ async function doParse() {
|
|||||||
core.setOutput('move', diff.move.length > 0);
|
core.setOutput('move', diff.move.length > 0);
|
||||||
core.setOutput('delete', diff.delete.length > 0);
|
core.setOutput('delete', diff.delete.length > 0);
|
||||||
core.setOutput('destination', diff.actions.addRepo);
|
core.setOutput('destination', diff.actions.addRepo);
|
||||||
|
core.setOutput('deps', diff.deps);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { describe, expect, it } from 'vitest';
|
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', () => {
|
describe('pkgbase parser', () => {
|
||||||
it('can detect an add operation', async () => {
|
it('can detect an add operation', async () => {
|
||||||
@@ -8,6 +8,7 @@ describe('pkgbase parser', () => {
|
|||||||
build: true,
|
build: true,
|
||||||
move: [],
|
move: [],
|
||||||
delete: [],
|
delete: [],
|
||||||
|
deps: 'staging',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: 'system-goblins',
|
addRepo: 'system-goblins',
|
||||||
removeRepo: null,
|
removeRepo: null,
|
||||||
@@ -27,6 +28,7 @@ describe('pkgbase parser', () => {
|
|||||||
build: true,
|
build: true,
|
||||||
move: [],
|
move: [],
|
||||||
delete: [],
|
delete: [],
|
||||||
|
deps: 'stable',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: 'world',
|
addRepo: 'world',
|
||||||
removeRepo: null,
|
removeRepo: null,
|
||||||
@@ -51,8 +53,21 @@ describe('pkgbase parser', () => {
|
|||||||
package: "pidgin",
|
package: "pidgin",
|
||||||
repository: "world",
|
repository: "world",
|
||||||
version: "2.14.14-3",
|
version: "2.14.14-3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"architecture": "x86_64",
|
||||||
|
"package": "libpurple",
|
||||||
|
"repository": "world",
|
||||||
|
"version": "2.14.14-3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"architecture": "x86_64",
|
||||||
|
"package": "finch",
|
||||||
|
"repository": "world",
|
||||||
|
"version": "2.14.14-3",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
deps: 'stable',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: 'world',
|
addRepo: 'world',
|
||||||
removeRepo: null,
|
removeRepo: null,
|
||||||
@@ -78,7 +93,13 @@ describe('pkgbase parser', () => {
|
|||||||
version: "1:7.9.2-1",
|
version: "1:7.9.2-1",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
delete: [],
|
delete: [{
|
||||||
|
"architecture": "x86_64",
|
||||||
|
"package": "opencascade",
|
||||||
|
"repository": "world",
|
||||||
|
"version": "1:7.9.1-1",
|
||||||
|
}],
|
||||||
|
deps: 'stable',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: 'world',
|
addRepo: 'world',
|
||||||
removeRepo: 'world-gremlins',
|
removeRepo: 'world-gremlins',
|
||||||
@@ -116,8 +137,21 @@ describe('pkgbase parser', () => {
|
|||||||
package: "pidgin",
|
package: "pidgin",
|
||||||
repository: "world",
|
repository: "world",
|
||||||
version: "2.14.14-3",
|
version: "2.14.14-3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"architecture": "x86_64",
|
||||||
|
"package": "libpurple",
|
||||||
|
"repository": "world",
|
||||||
|
"version": "2.14.14-3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"architecture": "x86_64",
|
||||||
|
"package": "finch",
|
||||||
|
"repository": "world",
|
||||||
|
"version": "2.14.14-3",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
deps: 'stable',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: 'world',
|
addRepo: 'world',
|
||||||
removeRepo: 'world-gremlins',
|
removeRepo: 'world-gremlins',
|
||||||
@@ -129,7 +163,7 @@ describe('pkgbase parser', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const rDir = 'move-with-dropped';
|
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 () => {
|
it('can detect a delete operation', async () => {
|
||||||
@@ -156,6 +190,7 @@ describe('pkgbase parser', () => {
|
|||||||
version: "3.13.0-2",
|
version: "3.13.0-2",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
deps: 'stable',
|
||||||
actions: {
|
actions: {
|
||||||
addRepo: null,
|
addRepo: null,
|
||||||
removeRepo: 'world',
|
removeRepo: 'world',
|
||||||
@@ -169,4 +204,10 @@ describe('pkgbase parser', () => {
|
|||||||
const rDir = 'remove';
|
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);
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user