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

Tweaks3 #24

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Use NodeJS 20"
- name: "Use NodeJS 22"
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'yarn'

- name: Install
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: "0"
fetch-depth: 0

- name: "Use NodeJS 20"
- name: "Use NodeJS 22"
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

Expand All @@ -56,10 +56,6 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Set git user"
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor}}@users.noreply.github.com"

echo "Version"
yarn lerna version \
--conventional-commits \
Expand Down
7 changes: 4 additions & 3 deletions packages/conf/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UnitSectionBuilder, UnitSectionSchema } from "./unit.js";
import { implement } from "./utils.js";
import { INI } from "./ini.js";
import { ServiceSectionBuilder, ServiceSectionSchema, type ServiceSection } from "./service.js";
import type { AbstractUnit, Unit } from "./types.js";

/**
* @see https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html
Expand Down Expand Up @@ -59,7 +60,7 @@ export class ContainerSectionBuilder {
}
}

export class Container {
export class Container implements AbstractUnit {
private readonly unitSection: UnitSectionBuilder;
private readonly containerSection: ContainerSectionBuilder;
private readonly installSection: InstallSectionBuilder;
Expand Down Expand Up @@ -169,7 +170,7 @@ export class Container {
/**
* Compare current container with another container
*/
public equals(container: Container) {
return JSON.stringify(this.toObject()) === JSON.stringify(container.toObject());
public equals(container?: Unit) {
return JSON.stringify(this.toObject()) === JSON.stringify(container?.toObject());
}
}
7 changes: 4 additions & 3 deletions packages/conf/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { KillSectionConfig } from "./kill.js";
import { KillSectionBuilder, KillSectionSchema } from "./kill.js";
import type { ResourceSectionConfig } from "./resource.js";
import { ResourceSectionBuilder, ResourceSectionConfigSchema } from "./resource.js";
import type { AbstractUnit, Unit } from "./types.js";

/**
* @see https://manpages.ubuntu.com/manpages/noble/en/man5/systemd.service.5.html
Expand Down Expand Up @@ -1602,7 +1603,7 @@ applyMixins(ServiceSectionBuilder, [
ResourceSectionBuilder,
]);

export class Service {
export class Service implements AbstractUnit {
private readonly unitSection: UnitSectionBuilder;
private readonly serviceSection: ServiceSectionBuilder;
private readonly installSection: InstallSectionBuilder;
Expand Down Expand Up @@ -1694,7 +1695,7 @@ export class Service {
/**
* Compare current service with another service
*/
public equals(service: Service) {
return JSON.stringify(this.toObject()) === JSON.stringify(service.toObject());
public equals(service?: Unit) {
return JSON.stringify(this.toObject()) === JSON.stringify(service?.toObject());
}
}
7 changes: 4 additions & 3 deletions packages/conf/src/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InstallSectionBuilder, InstallSectionSchema } from "./install.js";
import type { UnitSection } from "./unit.js";
import { UnitSectionBuilder, UnitSectionSchema } from "./unit.js";
import { INI } from "./ini.js";
import type { AbstractUnit, Unit } from "./types.js";

/**
* Timer section of a systemd unit file.
Expand Down Expand Up @@ -508,7 +509,7 @@ applyMixins(TimerSectionBuilder, [
ExecSectionBuilder,
]);

export class Timer {
export class Timer implements AbstractUnit {
private readonly unitSection: UnitSectionBuilder;
private readonly timerSection: TimerSectionBuilder;
private readonly installSection: InstallSectionBuilder;
Expand Down Expand Up @@ -606,7 +607,7 @@ export class Timer {
/**
* Compare current timer with another timer
*/
public equals(timer: Timer) {
return JSON.stringify(this.toObject()) === JSON.stringify(timer.toObject());
public equals(timer?: Unit) {
return JSON.stringify(this.toObject()) === JSON.stringify(timer?.toObject());
}
}
6 changes: 6 additions & 0 deletions packages/conf/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ import type { Container } from "./container.js";
import type { Service } from "./service.js";
import type { Timer } from "./timer.js";

export abstract class AbstractUnit {
public abstract toObject(): object;
public abstract toINIString(): string;
public abstract equals(unit?: Unit): boolean;
}

export type Unit = Container | Service | Timer;
8 changes: 2 additions & 6 deletions packages/ctl/src/ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@ export function create(unitName: string, unit: Unit) {
const path = getPath (name, type);

const current = getUnit(name, type);
const currentUnit = current?.toINIString();
const unitString = unit.toINIString();

// TODO use equal instead of !== to compare
if (currentUnit !== unitString) {
// TODO add file mode
writeFileSync(path, unitString);
if (unit.equals(current)) {
writeFileSync(path, unit.toINIString());
}
}

Expand Down
Loading