refactor: convert project to typescript

This commit is contained in:
Jeroen de Bruijn 2020-05-03 18:25:44 +02:00
parent 47a19ef007
commit f13bd58e77
No known key found for this signature in database
GPG key ID: 3A2677A1DF38FF9F
12 changed files with 113 additions and 34 deletions

View file

@ -55,6 +55,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2.1.0
- name: Install project
run: npm ci
- name: Build
run: npm run build
- name: Renovate test
uses: ./
with:

View file

@ -1,3 +1,4 @@
module.exports = {
singleQuote: true,
trailingComma: 'all',
};

View file

@ -15,8 +15,5 @@ inputs:
configured using a Secret.
required: true
runs:
using: docker
image: src/Dockerfile
args:
- ${{ inputs.configurationFile }}
- ${{ inputs.token }}
using: node12
main: dist/index.js

11
package-lock.json generated
View file

@ -4,6 +4,11 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
},
"@babel/code-frame": {
"version": "7.8.3",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz",
@ -308,6 +313,12 @@
"integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==",
"dev": true
},
"@types/node": {
"version": "13.13.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.4.tgz",
"integrity": "sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA==",
"dev": true
},
"@types/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",

View file

@ -3,6 +3,7 @@
"version": "1.0.5",
"description": "GitHub Action to run Renovate self-hosted.",
"private": true,
"main": "dist/index.ts",
"scripts": {
"lint": "concurrently npm:lint-es",
"lint:fix": "concurrently npm:lint-es:fix",
@ -16,7 +17,8 @@
"release:changelog": "standard-version --dry-run --skip.commit=true --skip.tag=true",
"release:commit": "git commit --allow-empty -m \"chore(release): trigger release process [ci release]\"",
"release:message": "chalk -t \"Run {green.bold git push} to publish the release or {red.bold git reset HEAD^} to undo the release.\"",
"release": "run-s release:changelog release:commit release:message"
"release": "run-s release:changelog release:commit release:message",
"build": "tsc"
},
"repository": {
"type": "git",
@ -28,10 +30,13 @@
"url": "https://github.com/renovatebot/github-action/issues"
},
"homepage": "https://github.com/renovatebot/github-action#readme",
"dependencies": {},
"dependencies": {
"@actions/core": "1.2.4"
},
"devDependencies": {
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.3.4",
"@types/node": "13.13.4",
"@typescript-eslint/eslint-plugin": "2.30.0",
"@typescript-eslint/parser": "2.30.0",
"chalk-cli": "4.1.0",

View file

@ -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
View 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;

View file

@ -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

12
src/index.ts Normal file
View file

@ -0,0 +1,12 @@
import * as core from '@actions/core';
import Input from './input';
import Renovate from './renovate';
try {
const input = new Input();
const renovate = new Renovate(input.configurationFile, input.token);
renovate.runDockerContainer();
} catch (error) {
console.log(error);
core.setFailed(error.message);
}

20
src/input.ts Normal file
View 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;

27
src/renovate.ts Normal file
View file

@ -0,0 +1,27 @@
import Docker from './docker';
import child from 'child_process';
class Renovate {
private configurationFileEnv = 'RENOVATE_CONFIG_FILE';
private tokenEnv = 'RENOVATE_CONFIG_FILE';
private docker: Docker;
constructor(private configurationFile: string, private token: string) {
this.docker = new Docker();
}
runDockerContainer(): void {
const commandArguments = [
'--rm',
this.docker.image(),
`--env ${this.configurationFileEnv}='${this.configurationFile}`,
`--env ${this.tokenEnv}='${this.token}`,
];
const command = `docker run ${commandArguments.join(' ')}`;
child.execSync(command, { stdio: 'inherit' });
}
}
export default Renovate;

14
tsconfig.json Normal file
View file

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"outDir": "dist"
},
"include": ["src/**/*.ts", "bin/**/*.ts"],
"exclude": ["node_modules", "**/*.test.ts"]
}