From 392d12b0001469ae5c3fe538d747ac1f6f895c3c Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 12 Feb 2024 11:20:31 +0100 Subject: [PATCH] feat: use async fs (#826) --- src/renovate.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/renovate.ts b/src/renovate.ts index 7573984194..ab380e522e 100644 --- a/src/renovate.ts +++ b/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 { @@ -11,12 +11,12 @@ class Renovate { private docker: Docker; constructor(private input: Input) { - this.validateArguments(); - this.docker = new Docker(input); } async runDockerContainer(): Promise { + await this.validateArguments(); + const dockerArguments = this.input .toEnvironmentVariables() .map((e) => `--env ${e.key}`) @@ -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()}`, ); } @@ -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 { const groupFile = '/etc/group'; - const groups = fs.readFileSync(groupFile, { + const groups = await fs.readFile(groupFile, { encoding: 'utf-8', }); @@ -97,7 +97,7 @@ class Renovate { return match.groups.groupId; } - private validateArguments(): void { + private async validateArguments(): Promise { if (/\s/.test(this.input.token.value)) { throw new Error('Token MUST NOT contain whitespace'); } @@ -105,8 +105,7 @@ class Renovate { 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`,