Skip to content

Commit 4d91b7f

Browse files
authoredNov 8, 2024··
fix(refactor): use named imports (#879)
Allows better tree shaking while bundling.
1 parent 5343762 commit 4d91b7f

File tree

7 files changed

+77
-36
lines changed

7 files changed

+77
-36
lines changed
 

‎.github/renovate.json

+38
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@
2828
"description": "Use ci semantic type for some deps",
2929
"matchFileNames": [".github/workflows/**"],
3030
"semanticCommitType": "ci"
31+
},
32+
{
33+
"description": "Don't require approval for renovate",
34+
"matchDepNames": [
35+
"ghcr.io/renovatebot/renovate",
36+
"renovatebot/github-action"
37+
],
38+
"dependencyDashboardApproval": false
39+
},
40+
{
41+
"description": "Don't pin renovate updates",
42+
"matchDepNames": ["ghcr.io/renovatebot/renovate"],
43+
"matchFileNames": ["action.yml", "src/docker.ts"],
44+
"pinDigests": false
45+
},
46+
{
47+
"description": "Use feat! semantic type for renovate major",
48+
"matchDepNames": ["ghcr.io/renovatebot/renovate"],
49+
"matchFileNames": ["action.yml", "src/docker.ts"],
50+
"matchUpdateTypes": ["major"],
51+
"commitMessagePrefix": "feat(deps)!:",
52+
"additionalBranchPrefix": "renovate-major"
3153
}
3254
],
3355
"customManagers": [
@@ -46,6 +68,22 @@
4668
"matchStrings": ["renovate-version: (?<currentValue>[^\\s]+)"],
4769
"depNameTemplate": "ghcr.io/renovatebot/renovate",
4870
"datasourceTemplate": "docker"
71+
},
72+
{
73+
"description": "Update renovate version in action.yml",
74+
"customType": "regex",
75+
"fileMatch": ["^action\\.yml$"],
76+
"matchStrings": ["default: '(?<currentValue>[^\\s]+)' # renovate"],
77+
"depNameTemplate": "ghcr.io/renovatebot/renovate",
78+
"datasourceTemplate": "docker"
79+
},
80+
{
81+
"description": "Update renovate version in src/docker.ts",
82+
"customType": "regex",
83+
"fileMatch": ["^src/docker\\.ts$"],
84+
"matchStrings": ["version = '(?<currentValue>[^\\s]+)'; // renovate"],
85+
"depNameTemplate": "ghcr.io/renovatebot/renovate",
86+
"datasourceTemplate": "docker"
4987
}
5088
]
5189
}

‎README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ image as root, do some customization and switch back to a unprivileged user.
132132
Specify volume mounts. Defaults to `/tmp:/tmp`.
133133
The volume mounts are separated through `;`.
134134

135-
This sample will mount `/tmp:/tmp`, `/home:/home` and `/foo:/bar`.
135+
This sample will mount `/tmp:/tmp` and `/foo:/bar`.
136136

137137
```yml
138138
....
@@ -148,7 +148,6 @@ jobs:
148148
token: ${{ secrets.RENOVATE_TOKEN }}
149149
docker-volumes: |
150150
/tmp:/tmp ;
151-
/home:/home ;
152151
/foo:/bar
153152
```
154153

‎action.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ inputs:
2323
required: false
2424
renovate-version:
2525
description: |
26-
Renovate version to use. Defaults to latest.
26+
Renovate version to use.
2727
required: false
28+
default: 'latest'
2829
renovate-image:
2930
description: |
3031
Renovate docker image name.
31-
Defaults to `ghcr.io/renovatebot/renovate`.
3232
required: false
33+
default: ghcr.io/renovatebot/renovate
3334
mount-docker-socket:
3435
description: |
3536
Mount the Docker socket inside the renovate container so that the commands

‎src/docker.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import type { Input } from './input';
2+
import { warning } from '@actions/core';
23

3-
class Docker {
4+
export class Docker {
45
private static readonly image = 'ghcr.io/renovatebot/renovate';
6+
private static readonly version = 'latest';
57

68
private readonly dockerImage: string;
79
private readonly fullTag: string;
810

911
constructor(input: Input) {
10-
const tag = input.getVersion();
12+
let image = input.getDockerImage();
13+
let version = input.getVersion();
1114

12-
this.dockerImage = input.getDockerImage() ?? Docker.image;
13-
this.fullTag = tag ?? 'latest';
15+
if (!image) {
16+
warning(`No Docker image specified, using ${Docker.image}`);
17+
image = Docker.image;
18+
}
19+
if (!version) {
20+
warning(`No Docker version specified, using ${Docker.version}`);
21+
version = Docker.version;
22+
}
23+
24+
this.dockerImage = image;
25+
this.fullTag = version;
1426
}
1527

1628
image(): string {
1729
return `${this.dockerImage}:${this.fullTag}`;
1830
}
1931
}
20-
21-
export default Docker;

‎src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as core from '@actions/core';
2-
import Input from './input';
3-
import Renovate from './renovate';
1+
import { Input } from './input';
2+
import { Renovate } from './renovate';
3+
import { setFailed } from '@actions/core';
44

55
async function run(): Promise<void> {
66
try {
@@ -10,7 +10,7 @@ async function run(): Promise<void> {
1010
await renovate.runDockerContainer();
1111
} catch (error) {
1212
console.error(error);
13-
core.setFailed(error as Error);
13+
setFailed(error as Error);
1414
}
1515
}
1616

‎src/input.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as core from '@actions/core';
1+
import { getInput } from '@actions/core';
22
import path from 'path';
33

4-
interface EnvironmentVariable {
4+
export interface EnvironmentVariable {
55
key: string;
66
value: string;
77
}
88

9-
class Input {
9+
export class Input {
1010
readonly options = {
1111
envRegex:
1212
/^(?:RENOVATE_\w+|LOG_LEVEL|GITHUB_COM_TOKEN|NODE_OPTIONS|(?:HTTPS?|NO)_PROXY|(?:https?|no)_proxy)$/,
@@ -27,7 +27,7 @@ class Input {
2727
private readonly _configurationFile: Readonly<EnvironmentVariable>;
2828

2929
constructor() {
30-
const envRegexInput = core.getInput('env-regex');
30+
const envRegexInput = getInput('env-regex');
3131
const envRegex = envRegexInput
3232
? new RegExp(envRegexInput)
3333
: this.options.envRegex;
@@ -61,41 +61,39 @@ class Input {
6161
}
6262

6363
getDockerImage(): string | null {
64-
return core.getInput('renovate-image') || null;
64+
return getInput('renovate-image') || null;
6565
}
6666

6767
getVersion(): string | null {
68-
const version = core.getInput('renovate-version');
69-
return !!version && version !== '' ? version : null;
68+
return getInput('renovate-version') || null;
7069
}
7170

7271
mountDockerSocket(): boolean {
73-
return core.getInput('mount-docker-socket') === 'true';
72+
return getInput('mount-docker-socket') === 'true';
7473
}
7574

7675
dockerSocketHostPath(): string {
77-
return core.getInput('docker-socket-host-path') || '/var/run/docker.sock';
76+
return getInput('docker-socket-host-path') || '/var/run/docker.sock';
7877
}
7978

8079
getDockerCmdFile(): string | null {
81-
const cmdFile = core.getInput('docker-cmd-file');
80+
const cmdFile = getInput('docker-cmd-file');
8281
return !!cmdFile && cmdFile !== '' ? path.resolve(cmdFile) : null;
8382
}
8483

8584
getDockerUser(): string | null {
86-
return core.getInput('docker-user') || null;
85+
return getInput('docker-user') || null;
8786
}
8887

8988
getDockerVolumeMounts(): string[] {
90-
return core
91-
.getInput('docker-volumes')
89+
return getInput('docker-volumes')
9290
.split(';')
9391
.map((v) => v.trim())
9492
.filter((v) => !!v);
9593
}
9694

9795
getDockerNetwork(): string {
98-
return core.getInput('docker-network');
96+
return getInput('docker-network');
9997
}
10098

10199
/**
@@ -117,7 +115,7 @@ class Input {
117115
env: string,
118116
optional: boolean,
119117
): EnvironmentVariable {
120-
const fromInput = core.getInput(input);
118+
const fromInput = getInput(input);
121119
const fromEnv = this._environmentVariables.get(env);
122120

123121
if (fromInput === '' && fromEnv === undefined && !optional) {
@@ -136,6 +134,3 @@ class Input {
136134
return { key: env, value: fromEnv !== undefined ? fromEnv : '' };
137135
}
138136
}
139-
140-
export default Input;
141-
export { EnvironmentVariable, Input };

‎src/renovate.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Docker from './docker';
1+
import { Docker } from './docker';
22
import { Input } from './input';
33
import { exec } from '@actions/exec';
44
import fs from 'fs/promises';
55
import path from 'path';
66

7-
class Renovate {
7+
export class Renovate {
88
static dockerGroupRegex = /^docker:x:(?<groupId>[1-9][0-9]*):/m;
99
private configFileMountDir = '/github-action';
1010

@@ -126,5 +126,3 @@ class Renovate {
126126
}
127127
}
128128
}
129-
130-
export default Renovate;

0 commit comments

Comments
 (0)
Please sign in to comment.