Skip to content

Commit

Permalink
feat: use async fs (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Feb 12, 2024
1 parent 327c2f3 commit 392d12b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/renovate.ts
@@ -1,7 +1,7 @@
import Docker from './docker';
import { Input } from './input';
import { exec } from '@actions/exec';
import fs from 'fs';
import fs from 'fs/promises';
import path from 'path';

class Renovate {
Expand All @@ -11,12 +11,12 @@ class Renovate {
private docker: Docker;

constructor(private input: Input) {
this.validateArguments();

this.docker = new Docker(input);
}

async runDockerContainer(): Promise<void> {
await this.validateArguments();

const dockerArguments = this.input
.toEnvironmentVariables()
.map((e) => `--env ${e.key}`)
Expand All @@ -35,7 +35,7 @@ class Renovate {
if (this.input.mountDockerSocket()) {
dockerArguments.push(
'--volume /var/run/docker.sock:/var/run/docker.sock',
`--group-add ${this.getDockerGroupId()}`,
`--group-add ${await this.getDockerGroupId()}`,
);
}

Expand Down Expand Up @@ -77,9 +77,9 @@ class Renovate {
* The Renovate container needs access to this group in order to have the
* required permissions on the Docker socket.
*/
private getDockerGroupId(): string {
private async getDockerGroupId(): Promise<string> {
const groupFile = '/etc/group';
const groups = fs.readFileSync(groupFile, {
const groups = await fs.readFile(groupFile, {
encoding: 'utf-8',
});

Expand All @@ -97,16 +97,15 @@ class Renovate {
return match.groups.groupId;
}

private validateArguments(): void {
private async validateArguments(): Promise<void> {
if (/\s/.test(this.input.token.value)) {
throw new Error('Token MUST NOT contain whitespace');
}

const configurationFile = this.input.configurationFile();
if (
configurationFile !== null &&
(!fs.existsSync(configurationFile.value) ||
!fs.statSync(configurationFile.value).isFile())
!(await fs.stat(configurationFile.value)).isFile()
) {
throw new Error(
`configuration file '${configurationFile.value}' MUST be an existing file`,
Expand Down

0 comments on commit 392d12b

Please sign in to comment.