Skip to content

Commit

Permalink
Code improvements (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
caponetto authored Apr 17, 2021
1 parent 811eacb commit 70f68e1
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 124 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"prettier/prettier": ["error", {"endOfLine": "auto"}]
},
"plugins": ["@typescript-eslint", "jest"]
Expand Down
70 changes: 53 additions & 17 deletions __tests__/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
import {getLatestArtifactFile, matchRule, validateSize, run} from '../src/app'
import {WorkflowArgs} from '../src/WorkflowArgs'
import {getLatestArtifact, matchRule, run, validateSize} from '../src/app'

describe('Get latest artifact', () => {
it('should throw an error due to invalid name', async () => {
await expect(
getLatestArtifactFile({
getLatestArtifact({
name: 'invalid',
owner: 'caponetto',
repo: 'vscode-diff-viewer'
repository: {
owner: 'caponetto',
name: 'vscode-diff-viewer'
}
})
).rejects.toThrowError()
})
it('should throw an error due to invalid owner', async () => {
await expect(
getLatestArtifactFile({
getLatestArtifact({
name: 'artifact-name',
owner: 'invalid-owner-12345',
repo: 'vscode-diff-viewer'
repository: {
owner: 'invalid-owner-12345',
name: 'vscode-diff-viewer'
}
})
).rejects.toThrowError()
})
it('should throw an error due to invalid repository', async () => {
await expect(
getLatestArtifactFile({
getLatestArtifact({
name: 'artifact-name',
owner: 'caponetto',
repo: 'invalid-repo-12345'
repository: {
owner: 'caponetto',
name: 'invalid-repo-12345'
}
})
).rejects.toThrowError()
})
it('should find the expected artifact - Part of the name', async () => {
const name = 'vscode_diff_viewer'
const file = await getLatestArtifactFile({
const file = await getLatestArtifact({
name: name,
owner: 'caponetto',
repo: 'vscode-diff-viewer'
repository: {
owner: 'caponetto',
name: 'vscode-diff-viewer'
}
})
expect(file.name).toMatch(name)
})
it('should find the expected artifact - Wildcard', async () => {
const file = await getLatestArtifactFile({
const file = await getLatestArtifact({
name: 'vscode_diff_viewer*.vsix',
owner: 'caponetto',
repo: 'vscode-diff-viewer'
repository: {
owner: 'caponetto',
name: 'vscode-diff-viewer'
}
})
expect(file.name).toMatch('vscode_diff_viewer')
})
Expand Down Expand Up @@ -87,3 +96,30 @@ describe('Match rule', () => {
expect(matchRule('StartABCDEnd', '*Start*End*')).toBeTruthy()
})
})

describe('App run flow', () => {
const testArtifactPath = '__tests__/resources/vscode_diff_viewer_1.1.2.zip'
const testReleasedArtifactName = 'vscode_diff_viewer*.vsix'
const testRepository = {
owner: 'caponetto',
name: 'vscode-diff-viewer'
}
it('should pass without errors', async () => {
await run({
releasedArtifactName: testReleasedArtifactName,
artifactPath: testArtifactPath,
maxIncreasePercentage: 70,
repository: testRepository
})
})
it('should throw an error', async () => {
await expect(
run({
releasedArtifactName: testReleasedArtifactName,
artifactPath: testArtifactPath,
maxIncreasePercentage: 10,
repository: testRepository
})
).rejects.toThrowError()
})
})
53 changes: 53 additions & 0 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {join} from 'path'
import * as inputs from '../src/inputs'

describe('Resolve path', () => {
it('should return a valid path - Full path', async () => {
const expected = '__tests__/resources/vscode_diff_viewer_1.1.2.zip'
const path = await inputs.resolvePath(
'__tests__/resources/vscode_diff_viewer_1.1.2.zip'
)
expect(path).toMatch(expected)
})
it('should return a valid path - Full path with wildcard', async () => {
const expected = join(
'__tests__',
'resources',
'vscode_diff_viewer_1.1.2.zip'
)
const path = await inputs.resolvePath(
'__tests__/resources/vscode_diff_viewer_*.zip'
)
expect(path).toMatch(expected)
})
it('should return a valid path - Any folder', async () => {
const expected = join(
'__tests__',
'resources',
'vscode_diff_viewer_1.1.2.zip'
)
const path = await inputs.resolvePath('**/vscode_diff_viewer_1.1.2.zip')
expect(path).toMatch(expected)
})
it('should return a valid path - Any folder with wildcard', async () => {
const expected = join(
'__tests__',
'resources',
'vscode_diff_viewer_1.1.2.zip'
)
const path = await inputs.resolvePath('**/vscode_diff_viewer_*.zip')
expect(path).toMatch(expected)
})
it('should not find any path - Invalid full path', async () => {
const path = await inputs.resolvePath(
'__tests__/resources/vscode_diff_viewer_1.1.2.tar.gz'
)
expect(path).toBeUndefined()
})
it('should not find any path - Invalid path with wildcard', async () => {
const path = await inputs.resolvePath(
'__tests__/resources/vscode_diff_viewer_*.tar.gz'
)
expect(path).toBeUndefined()
})
})
24 changes: 0 additions & 24 deletions __tests__/integration.test.ts

This file was deleted.

7 changes: 6 additions & 1 deletion licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
│ ├─ repository: https://github.com/actions/toolkit
│ ├─ path: /home/guilherme/dev/caponetto/less-is-more/node_modules/@actions/github
│ └─ licenseFile: /home/guilherme/dev/caponetto/less-is-more/node_modules/@actions/github/README.md
├─ @actions/[email protected]
│ ├─ licenses: MIT
│ ├─ repository: https://github.com/actions/toolkit
│ ├─ path: /home/guilherme/dev/caponetto/less-is-more/node_modules/@actions/glob
│ └─ licenseFile: /home/guilherme/dev/caponetto/less-is-more/node_modules/@actions/glob/LICENSE.md
├─ @actions/[email protected]
│ ├─ licenses: MIT
│ ├─ repository: https://github.com/actions/http-client
Expand Down Expand Up @@ -2898,7 +2903,7 @@
│ ├─ url: lukeed.com
│ ├─ path: /home/guilherme/dev/caponetto/less-is-more/node_modules/kleur
│ └─ licenseFile: /home/guilherme/dev/caponetto/less-is-more/node_modules/kleur/license
├─ [email protected].4
├─ [email protected].5
│ ├─ licenses: MIT
│ ├─ repository: https://github.com/caponetto/less-is-more
│ ├─ publisher: Guilherme H. Caponetto
Expand Down
19 changes: 12 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "less-is-more",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",
"author": "Guilherme H. Caponetto",
"keywords": [
Expand Down Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@actions/core": "1.2.6",
"@actions/github": "4.0.0",
"@actions/glob": "0.1.1",
"@octokit/core": "^3.4.0"
},
"devDependencies": {
Expand Down
8 changes: 0 additions & 8 deletions src/WorkflowArgs.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface Artifact {
name: string
repository?: RepositoryInfo
size?: number
}

export type SizeCheckResult =
| 'decreased'
| 'same'
| 'increase_allowed'
| 'increase_not_allowed'

export interface WorkflowArgs {
releasedArtifactName: string
artifactPath: string
maxIncreasePercentage: number
repository: RepositoryInfo
token?: string
}

export interface RepositoryInfo {
owner: string
name: string
}
Loading

0 comments on commit 70f68e1

Please sign in to comment.