Skip to content

Commit 8d7aa94

Browse files
committed
feat: 🎸 implement the angular-versions-actions with dummy data
1 parent 316608a commit 8d7aa94

File tree

9 files changed

+183
-81
lines changed

9 files changed

+183
-81
lines changed

.eslintrc.json

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
11
{
2-
"plugins": ["jest", "@typescript-eslint"],
3-
"extends": ["plugin:github/recommended"],
4-
"parser": "@typescript-eslint/parser",
5-
"parserOptions": {
6-
"ecmaVersion": 9,
7-
"sourceType": "module",
8-
"project": "./tsconfig.json"
9-
},
10-
"rules": {
11-
"eslint-comments/no-use": "off",
12-
"import/no-namespace": "off",
13-
"no-unused-vars": "off",
14-
"@typescript-eslint/no-unused-vars": "error",
15-
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
16-
"@typescript-eslint/no-require-imports": "error",
17-
"@typescript-eslint/array-type": "error",
18-
"@typescript-eslint/await-thenable": "error",
19-
"@typescript-eslint/ban-ts-comment": "error",
20-
"camelcase": "off",
21-
"@typescript-eslint/consistent-type-assertions": "error",
22-
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
23-
"@typescript-eslint/func-call-spacing": ["error", "never"],
24-
"@typescript-eslint/no-array-constructor": "error",
25-
"@typescript-eslint/no-empty-interface": "error",
26-
"@typescript-eslint/no-explicit-any": "error",
27-
"@typescript-eslint/no-extraneous-class": "error",
28-
"@typescript-eslint/no-for-in-array": "error",
29-
"@typescript-eslint/no-inferrable-types": "error",
30-
"@typescript-eslint/no-misused-new": "error",
31-
"@typescript-eslint/no-namespace": "error",
32-
"@typescript-eslint/no-non-null-assertion": "warn",
33-
"@typescript-eslint/no-unnecessary-qualifier": "error",
34-
"@typescript-eslint/no-unnecessary-type-assertion": "error",
35-
"@typescript-eslint/no-useless-constructor": "error",
36-
"@typescript-eslint/no-var-requires": "error",
37-
"@typescript-eslint/prefer-for-of": "warn",
38-
"@typescript-eslint/prefer-function-type": "warn",
39-
"@typescript-eslint/prefer-includes": "error",
40-
"@typescript-eslint/prefer-string-starts-ends-with": "error",
41-
"@typescript-eslint/promise-function-async": "error",
42-
"@typescript-eslint/require-array-sort-compare": "error",
43-
"@typescript-eslint/restrict-plus-operands": "error",
44-
"semi": "off",
45-
"@typescript-eslint/semi": ["error", "never"],
46-
"@typescript-eslint/type-annotation-spacing": "error",
47-
"@typescript-eslint/unbound-method": "error"
48-
},
49-
"env": {
50-
"node": true,
51-
"es6": true,
52-
"jest/globals": true
53-
}
54-
}
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"eslint-comments/no-use": "off",
12+
"import/no-namespace": "off",
13+
"no-unused-vars": "off",
14+
"@typescript-eslint/no-unused-vars": "error",
15+
"@typescript-eslint/explicit-member-accessibility": [
16+
"error",
17+
{"accessibility": "no-public"}
18+
],
19+
"@typescript-eslint/no-require-imports": "error",
20+
"@typescript-eslint/array-type": "error",
21+
"@typescript-eslint/await-thenable": "error",
22+
"@typescript-eslint/ban-ts-comment": "error",
23+
"camelcase": "off",
24+
"@typescript-eslint/consistent-type-assertions": "error",
25+
"@typescript-eslint/explicit-function-return-type": [
26+
"error",
27+
{"allowExpressions": true}
28+
],
29+
"@typescript-eslint/func-call-spacing": ["error", "never"],
30+
"@typescript-eslint/no-array-constructor": "error",
31+
"@typescript-eslint/no-empty-interface": "error",
32+
"@typescript-eslint/no-explicit-any": "error",
33+
"@typescript-eslint/no-extraneous-class": "error",
34+
"@typescript-eslint/no-for-in-array": "error",
35+
"@typescript-eslint/no-inferrable-types": "error",
36+
"@typescript-eslint/no-misused-new": "error",
37+
"@typescript-eslint/no-namespace": "error",
38+
"@typescript-eslint/no-non-null-assertion": "warn",
39+
"@typescript-eslint/no-unnecessary-qualifier": "error",
40+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
41+
"@typescript-eslint/no-useless-constructor": "error",
42+
"@typescript-eslint/no-var-requires": "error",
43+
"@typescript-eslint/prefer-for-of": "warn",
44+
"@typescript-eslint/prefer-function-type": "warn",
45+
"@typescript-eslint/prefer-includes": "error",
46+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
47+
"@typescript-eslint/promise-function-async": "error",
48+
"@typescript-eslint/require-array-sort-compare": "error",
49+
"@typescript-eslint/restrict-plus-operands": "error",
50+
"semi": "off",
51+
"@typescript-eslint/semi": "off",
52+
"@typescript-eslint/type-annotation-spacing": "error",
53+
"@typescript-eslint/unbound-method": "error"
54+
},
55+
"env": {
56+
"node": true,
57+
"es6": true,
58+
"jest/globals": true
59+
}
60+
}

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"printWidth": 80,
33
"tabWidth": 2,
44
"useTabs": false,
5-
"semi": false,
5+
"semi": true,
66
"singleQuote": true,
77
"trailingComma": "none",
88
"bracketSpacing": false,

action.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
name: "Match Angular Versions"
2-
description: "Modifies the package.json with matching dependency versions for a given base Angular version"
3-
author: "GitHub"
1+
name: 'Match Angular Versions'
2+
description: 'Modifies the package.json with matching dependency versions for a given base Angular version'
3+
author: 'GitHub'
44
inputs:
55
angular_version:
6-
description: "The base Angular version used to match the dependency versions"
6+
description: 'The base Angular version used to match the dependency versions'
77
required: true
8+
file_path:
9+
description: 'Path of the package.json file to modify'
10+
required: false
11+
default: './package.json'
812
runs:
9-
using: "node12"
10-
main: "dist/index.js"
13+
using: 'node12'
14+
main: 'dist/index.js'
1115
branding:
12-
icon: "package"
13-
color: "gray-dark"
16+
icon: 'package'
17+
color: 'gray-dark'

src/angular-versions.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {PackageJsonVersion} from './types/package-json-version';
2+
3+
export const versions = new Map<string, PackageJsonVersion>([
4+
[
5+
'8.0.0',
6+
{
7+
dependencies: {
8+
'@angular/animations': 'string',
9+
'@angular/common': 'string',
10+
'@angular/compiler': 'string',
11+
'@angular/core': 'string',
12+
'@angular/forms': 'string',
13+
'@angular/platform-browser': 'string',
14+
'@angular/platform-browser-dynamic': 'string',
15+
'@angular/router': 'string',
16+
rxjs: 'string',
17+
'zone.js': 'string'
18+
}
19+
}
20+
],
21+
[
22+
'9.0.0',
23+
{
24+
dependencies: {
25+
'@angular/animations': 'string',
26+
'@angular/common': 'string',
27+
'@angular/compiler': 'string',
28+
'@angular/core': 'string',
29+
'@angular/forms': 'string',
30+
'@angular/platform-browser': 'string',
31+
'@angular/platform-browser-dynamic': 'string',
32+
'@angular/router': 'string',
33+
rxjs: 'string',
34+
'zone.js': 'string'
35+
}
36+
}
37+
],
38+
[
39+
'10.0.0',
40+
{
41+
dependencies: {
42+
'@angular/animations': 'string',
43+
'@angular/common': 'string',
44+
'@angular/compiler': 'string',
45+
'@angular/core': 'string',
46+
'@angular/forms': 'string',
47+
'@angular/platform-browser': 'string',
48+
'@angular/platform-browser-dynamic': 'string',
49+
'@angular/router': 'string',
50+
rxjs: 'string',
51+
'zone.js': 'string'
52+
}
53+
}
54+
]
55+
]);

src/get-angular-versions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {versions} from './angular-versions';
2+
import {PackageJsonVersion} from './types/package-json-version';
3+
4+
export async function getAngularVersion(
5+
angularVersion: string
6+
): Promise<PackageJsonVersion> {
7+
if (versions.has(angularVersion)) {
8+
return versions.get(angularVersion) as PackageJsonVersion;
9+
} else {
10+
throw new Error(`Angular version ${angularVersion} is not supported`);
11+
}
12+
}

src/main.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
import * as core from '@actions/core'
2-
import {wait} from './wait'
1+
import * as core from '@actions/core';
2+
import * as fs from 'fs';
3+
import {getAngularVersion} from './get-angular-versions';
4+
import {overrideAngularVersions} from './override-angular-versions';
35

46
async function run(): Promise<void> {
57
try {
6-
const ms: string = core.getInput('milliseconds')
7-
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
8+
const angularVersion: string = core.getInput('angular_version');
9+
core.debug(`Finding dependencies for angular version ${angularVersion}`);
810

9-
core.debug(new Date().toTimeString())
10-
await wait(parseInt(ms, 10))
11-
core.debug(new Date().toTimeString())
11+
const versions = await getAngularVersion(angularVersion);
12+
core.debug(`Depedencies found: \nr ${JSON.stringify(versions, null, 2)}`);
1213

13-
core.setOutput('time', new Date().toTimeString())
14+
const filePath: string = core.getInput('file_path');
15+
core.debug(`merging found dependencies with file ${filePath}`);
16+
17+
await overrideAngularVersions(versions, filePath);
18+
19+
core.debug(new Date().toTimeString());
1420
} catch (error) {
15-
core.setFailed(error.message)
21+
core.setFailed(error.message);
1622
}
1723
}
1824

19-
run()
25+
run();

src/override-angular-versions.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {PackageJsonVersion} from './types/package-json-version';
2+
import * as fs from 'fs';
3+
4+
export async function overrideAngularVersions(
5+
angularVersions: PackageJsonVersion,
6+
path: string
7+
): Promise<void> {
8+
try {
9+
const rawData = fs.readFileSync(path);
10+
let packageJson: PackageJsonVersion = JSON.parse(rawData.toString());
11+
packageJson = {...packageJson, ...angularVersions};
12+
fs.writeFileSync(path, JSON.stringify(packageJson));
13+
} catch (error) {}
14+
}

src/types/package-json-version.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface PackageJsonVersion {
2+
dependencies: {
3+
'@angular/animations': string;
4+
'@angular/common': string;
5+
'@angular/compiler': string;
6+
'@angular/core': string;
7+
'@angular/forms': string;
8+
'@angular/platform-browser': string;
9+
'@angular/platform-browser-dynamic': string;
10+
'@angular/router': string;
11+
rxjs: string;
12+
'zone.js': string;
13+
};
14+
}

src/wait.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)