mirror of
https://github.com/renovatebot/github-action.git
synced 2025-12-16 08:52:35 +00:00
fix(refactor): use named imports (#879)
Allows better tree shaking while bundling.
This commit is contained in:
parent
5343762d53
commit
4d91b7f286
7 changed files with 77 additions and 36 deletions
38
.github/renovate.json
vendored
38
.github/renovate.json
vendored
|
|
@ -28,6 +28,28 @@
|
||||||
"description": "Use ci semantic type for some deps",
|
"description": "Use ci semantic type for some deps",
|
||||||
"matchFileNames": [".github/workflows/**"],
|
"matchFileNames": [".github/workflows/**"],
|
||||||
"semanticCommitType": "ci"
|
"semanticCommitType": "ci"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Don't require approval for renovate",
|
||||||
|
"matchDepNames": [
|
||||||
|
"ghcr.io/renovatebot/renovate",
|
||||||
|
"renovatebot/github-action"
|
||||||
|
],
|
||||||
|
"dependencyDashboardApproval": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Don't pin renovate updates",
|
||||||
|
"matchDepNames": ["ghcr.io/renovatebot/renovate"],
|
||||||
|
"matchFileNames": ["action.yml", "src/docker.ts"],
|
||||||
|
"pinDigests": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Use feat! semantic type for renovate major",
|
||||||
|
"matchDepNames": ["ghcr.io/renovatebot/renovate"],
|
||||||
|
"matchFileNames": ["action.yml", "src/docker.ts"],
|
||||||
|
"matchUpdateTypes": ["major"],
|
||||||
|
"commitMessagePrefix": "feat(deps)!:",
|
||||||
|
"additionalBranchPrefix": "renovate-major"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"customManagers": [
|
"customManagers": [
|
||||||
|
|
@ -46,6 +68,22 @@
|
||||||
"matchStrings": ["renovate-version: (?<currentValue>[^\\s]+)"],
|
"matchStrings": ["renovate-version: (?<currentValue>[^\\s]+)"],
|
||||||
"depNameTemplate": "ghcr.io/renovatebot/renovate",
|
"depNameTemplate": "ghcr.io/renovatebot/renovate",
|
||||||
"datasourceTemplate": "docker"
|
"datasourceTemplate": "docker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Update renovate version in action.yml",
|
||||||
|
"customType": "regex",
|
||||||
|
"fileMatch": ["^action\\.yml$"],
|
||||||
|
"matchStrings": ["default: '(?<currentValue>[^\\s]+)' # renovate"],
|
||||||
|
"depNameTemplate": "ghcr.io/renovatebot/renovate",
|
||||||
|
"datasourceTemplate": "docker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Update renovate version in src/docker.ts",
|
||||||
|
"customType": "regex",
|
||||||
|
"fileMatch": ["^src/docker\\.ts$"],
|
||||||
|
"matchStrings": ["version = '(?<currentValue>[^\\s]+)'; // renovate"],
|
||||||
|
"depNameTemplate": "ghcr.io/renovatebot/renovate",
|
||||||
|
"datasourceTemplate": "docker"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ image as root, do some customization and switch back to a unprivileged user.
|
||||||
Specify volume mounts. Defaults to `/tmp:/tmp`.
|
Specify volume mounts. Defaults to `/tmp:/tmp`.
|
||||||
The volume mounts are separated through `;`.
|
The volume mounts are separated through `;`.
|
||||||
|
|
||||||
This sample will mount `/tmp:/tmp`, `/home:/home` and `/foo:/bar`.
|
This sample will mount `/tmp:/tmp` and `/foo:/bar`.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
....
|
....
|
||||||
|
|
@ -148,7 +148,6 @@ jobs:
|
||||||
token: ${{ secrets.RENOVATE_TOKEN }}
|
token: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
docker-volumes: |
|
docker-volumes: |
|
||||||
/tmp:/tmp ;
|
/tmp:/tmp ;
|
||||||
/home:/home ;
|
|
||||||
/foo:/bar
|
/foo:/bar
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,14 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
renovate-version:
|
renovate-version:
|
||||||
description: |
|
description: |
|
||||||
Renovate version to use. Defaults to latest.
|
Renovate version to use.
|
||||||
required: false
|
required: false
|
||||||
|
default: 'latest'
|
||||||
renovate-image:
|
renovate-image:
|
||||||
description: |
|
description: |
|
||||||
Renovate docker image name.
|
Renovate docker image name.
|
||||||
Defaults to `ghcr.io/renovatebot/renovate`.
|
|
||||||
required: false
|
required: false
|
||||||
|
default: ghcr.io/renovatebot/renovate
|
||||||
mount-docker-socket:
|
mount-docker-socket:
|
||||||
description: |
|
description: |
|
||||||
Mount the Docker socket inside the renovate container so that the commands
|
Mount the Docker socket inside the renovate container so that the commands
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,31 @@
|
||||||
import type { Input } from './input';
|
import type { Input } from './input';
|
||||||
|
import { warning } from '@actions/core';
|
||||||
|
|
||||||
class Docker {
|
export class Docker {
|
||||||
private static readonly image = 'ghcr.io/renovatebot/renovate';
|
private static readonly image = 'ghcr.io/renovatebot/renovate';
|
||||||
|
private static readonly version = 'latest';
|
||||||
|
|
||||||
private readonly dockerImage: string;
|
private readonly dockerImage: string;
|
||||||
private readonly fullTag: string;
|
private readonly fullTag: string;
|
||||||
|
|
||||||
constructor(input: Input) {
|
constructor(input: Input) {
|
||||||
const tag = input.getVersion();
|
let image = input.getDockerImage();
|
||||||
|
let version = input.getVersion();
|
||||||
|
|
||||||
this.dockerImage = input.getDockerImage() ?? Docker.image;
|
if (!image) {
|
||||||
this.fullTag = tag ?? 'latest';
|
warning(`No Docker image specified, using ${Docker.image}`);
|
||||||
|
image = Docker.image;
|
||||||
|
}
|
||||||
|
if (!version) {
|
||||||
|
warning(`No Docker version specified, using ${Docker.version}`);
|
||||||
|
version = Docker.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dockerImage = image;
|
||||||
|
this.fullTag = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
image(): string {
|
image(): string {
|
||||||
return `${this.dockerImage}:${this.fullTag}`;
|
return `${this.dockerImage}:${this.fullTag}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Docker;
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import * as core from '@actions/core';
|
import { Input } from './input';
|
||||||
import Input from './input';
|
import { Renovate } from './renovate';
|
||||||
import Renovate from './renovate';
|
import { setFailed } from '@actions/core';
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -10,7 +10,7 @@ async function run(): Promise<void> {
|
||||||
await renovate.runDockerContainer();
|
await renovate.runDockerContainer();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
core.setFailed(error as Error);
|
setFailed(error as Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
31
src/input.ts
31
src/input.ts
|
|
@ -1,12 +1,12 @@
|
||||||
import * as core from '@actions/core';
|
import { getInput } from '@actions/core';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
interface EnvironmentVariable {
|
export interface EnvironmentVariable {
|
||||||
key: string;
|
key: string;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Input {
|
export class Input {
|
||||||
readonly options = {
|
readonly options = {
|
||||||
envRegex:
|
envRegex:
|
||||||
/^(?:RENOVATE_\w+|LOG_LEVEL|GITHUB_COM_TOKEN|NODE_OPTIONS|(?:HTTPS?|NO)_PROXY|(?:https?|no)_proxy)$/,
|
/^(?:RENOVATE_\w+|LOG_LEVEL|GITHUB_COM_TOKEN|NODE_OPTIONS|(?:HTTPS?|NO)_PROXY|(?:https?|no)_proxy)$/,
|
||||||
|
|
@ -27,7 +27,7 @@ class Input {
|
||||||
private readonly _configurationFile: Readonly<EnvironmentVariable>;
|
private readonly _configurationFile: Readonly<EnvironmentVariable>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const envRegexInput = core.getInput('env-regex');
|
const envRegexInput = getInput('env-regex');
|
||||||
const envRegex = envRegexInput
|
const envRegex = envRegexInput
|
||||||
? new RegExp(envRegexInput)
|
? new RegExp(envRegexInput)
|
||||||
: this.options.envRegex;
|
: this.options.envRegex;
|
||||||
|
|
@ -61,41 +61,39 @@ class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
getDockerImage(): string | null {
|
getDockerImage(): string | null {
|
||||||
return core.getInput('renovate-image') || null;
|
return getInput('renovate-image') || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getVersion(): string | null {
|
getVersion(): string | null {
|
||||||
const version = core.getInput('renovate-version');
|
return getInput('renovate-version') || null;
|
||||||
return !!version && version !== '' ? version : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mountDockerSocket(): boolean {
|
mountDockerSocket(): boolean {
|
||||||
return core.getInput('mount-docker-socket') === 'true';
|
return getInput('mount-docker-socket') === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerSocketHostPath(): string {
|
dockerSocketHostPath(): string {
|
||||||
return core.getInput('docker-socket-host-path') || '/var/run/docker.sock';
|
return getInput('docker-socket-host-path') || '/var/run/docker.sock';
|
||||||
}
|
}
|
||||||
|
|
||||||
getDockerCmdFile(): string | null {
|
getDockerCmdFile(): string | null {
|
||||||
const cmdFile = core.getInput('docker-cmd-file');
|
const cmdFile = getInput('docker-cmd-file');
|
||||||
return !!cmdFile && cmdFile !== '' ? path.resolve(cmdFile) : null;
|
return !!cmdFile && cmdFile !== '' ? path.resolve(cmdFile) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDockerUser(): string | null {
|
getDockerUser(): string | null {
|
||||||
return core.getInput('docker-user') || null;
|
return getInput('docker-user') || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDockerVolumeMounts(): string[] {
|
getDockerVolumeMounts(): string[] {
|
||||||
return core
|
return getInput('docker-volumes')
|
||||||
.getInput('docker-volumes')
|
|
||||||
.split(';')
|
.split(';')
|
||||||
.map((v) => v.trim())
|
.map((v) => v.trim())
|
||||||
.filter((v) => !!v);
|
.filter((v) => !!v);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDockerNetwork(): string {
|
getDockerNetwork(): string {
|
||||||
return core.getInput('docker-network');
|
return getInput('docker-network');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,7 +115,7 @@ class Input {
|
||||||
env: string,
|
env: string,
|
||||||
optional: boolean,
|
optional: boolean,
|
||||||
): EnvironmentVariable {
|
): EnvironmentVariable {
|
||||||
const fromInput = core.getInput(input);
|
const fromInput = getInput(input);
|
||||||
const fromEnv = this._environmentVariables.get(env);
|
const fromEnv = this._environmentVariables.get(env);
|
||||||
|
|
||||||
if (fromInput === '' && fromEnv === undefined && !optional) {
|
if (fromInput === '' && fromEnv === undefined && !optional) {
|
||||||
|
|
@ -136,6 +134,3 @@ class Input {
|
||||||
return { key: env, value: fromEnv !== undefined ? fromEnv : '' };
|
return { key: env, value: fromEnv !== undefined ? fromEnv : '' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Input;
|
|
||||||
export { EnvironmentVariable, Input };
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import Docker from './docker';
|
import { Docker } from './docker';
|
||||||
import { Input } from './input';
|
import { Input } from './input';
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
class Renovate {
|
export class Renovate {
|
||||||
static dockerGroupRegex = /^docker:x:(?<groupId>[1-9][0-9]*):/m;
|
static dockerGroupRegex = /^docker:x:(?<groupId>[1-9][0-9]*):/m;
|
||||||
private configFileMountDir = '/github-action';
|
private configFileMountDir = '/github-action';
|
||||||
|
|
||||||
|
|
@ -126,5 +126,3 @@ class Renovate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Renovate;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue