mirror of
https://github.com/renovatebot/github-action.git
synced 2025-12-18 01:42:34 +00:00
refactor: convert project to typescript (#47)
* refactor: convert project to typescript * fix: image as last argument of docker run * ci: remove example as the build can act as example * fix: set tokenEnv to RENOVATE_TOKEN * fix: add trailing single quite to Docker --env arguments * fix: mount volume with config file to Docker container * chore: remove Prettier trailingComma on all This puts it back at the default, which is es5 style. * fix: correct package main to dist/indes.js * fix: use @actions/exec to execute docker child process * fix: use async/await for exec Co-authored-by: Michael Kriese <michael.kriese@visualon.de> * fix: use async/await in the runner Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
47a19ef007
commit
ec8a542458
14 changed files with 160 additions and 61 deletions
|
|
@ -1,5 +0,0 @@
|
|||
FROM renovate/renovate:19.228.2
|
||||
|
||||
COPY entrypoint.sh /usr/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/usr/entrypoint.sh"]
|
||||
15
src/docker.ts
Normal file
15
src/docker.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class Docker {
|
||||
readonly repository = 'renovate/renovate';
|
||||
// renovate: datasource=docker depName=renovate/renovate versioning=docker
|
||||
readonly tag = '19.228.1';
|
||||
|
||||
image(): string {
|
||||
return `${this.repository}:${this.tag}`;
|
||||
}
|
||||
|
||||
version(): string {
|
||||
return this.tag;
|
||||
}
|
||||
}
|
||||
|
||||
export default Docker;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Entrypoint for Docker.
|
||||
|
||||
export RENOVATE_CONFIG_FILE="${GITHUB_WORKSPACE}/${1}"
|
||||
readonly _RENOVATE_TOKEN="${2}"
|
||||
|
||||
# We are running as ubuntu, so no write access to /github/home
|
||||
export HOME=/home/ubuntu
|
||||
|
||||
if [[ ! -f "${RENOVATE_CONFIG_FILE}" ]]; then
|
||||
echo "ERROR: Couldn't find file ${RENOVATE_CONFIG_FILE}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run Renovate.
|
||||
#
|
||||
# Mimic the original ENTRYPOINT of the renovate/renovate Docker container. See
|
||||
# the following link for this entry.
|
||||
# https://github.com/renovatebot/docker-renovate/blob/d3aa0d99931ea7ad7e901a1e538eba0d61268229/Dockerfile#L63
|
||||
|
||||
RENOVATE_TOKEN="${_RENOVATE_TOKEN}" /usr/local/bin/docker-entrypoint.sh
|
||||
17
src/index.ts
Normal file
17
src/index.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import * as core from '@actions/core';
|
||||
import Input from './input';
|
||||
import Renovate from './renovate';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const input = new Input();
|
||||
const renovate = new Renovate(input.configurationFile, input.token);
|
||||
|
||||
await renovate.runDockerContainer();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
20
src/input.ts
Normal file
20
src/input.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
class Input {
|
||||
readonly configurationFile = core.getInput('configurationFile', {
|
||||
required: true,
|
||||
});
|
||||
readonly token = core.getInput('token', { required: true });
|
||||
|
||||
constructor() {
|
||||
this.validate();
|
||||
}
|
||||
|
||||
validate(): void {
|
||||
if (this.token === '') {
|
||||
throw new Error('input.token MUST NOT be empty');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Input;
|
||||
55
src/renovate.ts
Normal file
55
src/renovate.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import Docker from './docker';
|
||||
import { exec } from '@actions/exec';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
class Renovate {
|
||||
private configFileEnv = 'RENOVATE_CONFIG_FILE';
|
||||
private tokenEnv = 'RENOVATE_TOKEN';
|
||||
private configFileMountDir = '/github-action';
|
||||
|
||||
private configFile: string;
|
||||
private docker: Docker;
|
||||
|
||||
constructor(configFile: string, private token: string) {
|
||||
this.configFile = path.resolve(configFile);
|
||||
|
||||
this.validateArguments();
|
||||
|
||||
this.docker = new Docker();
|
||||
}
|
||||
|
||||
async runDockerContainer(): Promise<void> {
|
||||
const commandArguments = [
|
||||
'--rm',
|
||||
`--env ${this.configFileEnv}=${this.configFileMountPath()}`,
|
||||
`--env ${this.tokenEnv}=${this.token}`,
|
||||
`--volume ${this.configFile}:${this.configFileMountPath()}`,
|
||||
this.docker.image(),
|
||||
];
|
||||
const command = `docker run ${commandArguments.join(' ')}`;
|
||||
|
||||
const code = await exec(command);
|
||||
if (code !== 0) {
|
||||
new Error(`'docker run' failed with exit code ${code}.`);
|
||||
}
|
||||
}
|
||||
|
||||
private validateArguments(): void {
|
||||
if (!fs.existsSync(this.configFile)) {
|
||||
throw new Error(
|
||||
`Could not locate configuration file '${this.configFile}'.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private configFileName(): string {
|
||||
return path.basename(this.configFile);
|
||||
}
|
||||
|
||||
private configFileMountPath(): string {
|
||||
return path.join(this.configFileMountDir, this.configFileName());
|
||||
}
|
||||
}
|
||||
|
||||
export default Renovate;
|
||||
Loading…
Add table
Add a link
Reference in a new issue