Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and configure ESLint and update configuration for Prettier #26

Merged
merged 5 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!src/
49 changes: 49 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:eslint-plugin-jest/recommended',
'eslint-config-prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-jest'],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description'
}
],
'no-console': 'error',
'yoda': 'error',
'prefer-const': [
'error',
{
destructuring: 'all'
}
],
'no-control-regex': 'off',
'no-constant-condition': ['error', {checkLoops: false}]
},
overrides: [
{
files: ['**/*{test,spec}.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'jest/no-standalone-expect': 'off',
'jest/no-conditional-expect': 'off',
'no-console': 'off',

}
}
],
env: {
node: true,
es6: true,
'jest/globals': true
}
};
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/basic-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:
jobs:
call-basic-validation:
name: Basic validation
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: CodeQL analysis

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
schedule:
- cron: '0 3 * * 0'

jobs:
call-codeQL-analysis:
name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
2 changes: 1 addition & 1 deletion .github/workflows/licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ on:
jobs:
call-licensed:
name: Licensed
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
14 changes: 7 additions & 7 deletions .github/workflows/release-new-action-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Update the ${{ env.TAG_NAME }} tag
id: update-major-tag
uses: ./
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
- name: Update the ${{ env.TAG_NAME }} tag
id: update-major-tag
uses: ./
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
2 changes: 1 addition & 1 deletion .licenses/npm/semver.dep.yml

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

7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!.github/
!src/
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: false,
arrowParens: 'avoid'
};
70 changes: 37 additions & 33 deletions __tests__/api-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import * as github from "@actions/github";
import * as apiUtils from "../src/api-utils";
import * as github from '@actions/github';
import * as apiUtils from '../src/api-utils';

const prereleaseData = require("./data/pre-release.json");
const releaseData = require("./data/release.json");
import prereleaseData from './data/pre-release.json';
import releaseData from './data/release.json';

const token = "faketoken";
const token = 'faketoken';
const octokitClient = github.getOctokit(token);

let getReleaseSpy: jest.SpyInstance;

process.env.GITHUB_REPOSITORY = "test/repository";

describe("validateIfReleaseIsPublished", () => {
beforeEach(() => {
getReleaseSpy = jest.spyOn(octokitClient.repos, "getReleaseByTag");
});

it("throw if release is marked as pre-release", async () => {
getReleaseSpy.mockReturnValue(prereleaseData);

expect.assertions(1);
await expect(apiUtils.validateIfReleaseIsPublished("v1.0.0", octokitClient)).rejects.toThrowError(
"The 'v1.0.0' release is marked as pre-release. Updating tags for pre-release is not supported"
);
});

it("validate that release is published", async () => {
getReleaseSpy.mockReturnValue(releaseData);

expect.assertions(1);
await expect(apiUtils.validateIfReleaseIsPublished("v1.1.0", octokitClient)).resolves.not.toThrow();
});

afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});
});
process.env.GITHUB_REPOSITORY = 'test/repository';

describe('validateIfReleaseIsPublished', () => {
beforeEach(() => {
getReleaseSpy = jest.spyOn(octokitClient.repos, 'getReleaseByTag');
});

it('throw if release is marked as pre-release', async () => {
getReleaseSpy.mockReturnValue(prereleaseData);

expect.assertions(1);
await expect(
apiUtils.validateIfReleaseIsPublished('v1.0.0', octokitClient)
).rejects.toThrow(
"The 'v1.0.0' release is marked as pre-release. Updating tags for pre-release is not supported"
);
});

it('validate that release is published', async () => {
getReleaseSpy.mockReturnValue(releaseData);

expect.assertions(1);
await expect(
apiUtils.validateIfReleaseIsPublished('v1.1.0', octokitClient)
).resolves.not.toThrow();
});

afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});
});
138 changes: 81 additions & 57 deletions __tests__/version-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,93 @@
import * as versionUtils from "../src/version-utils";
import * as versionUtils from '../src/version-utils';
import stableSemver from './data/stable-semver.json';
import stableBuildSemver from './data/stable-build-semver.json';
import prereleaseSemver from './data/prerelease-semver.json';
import prereleaseBuildSemver from './data/prerelease-build-semver.json';

describe("isStableSemverVersion", () => {
it("validate if a version is stable", () => {
const semverVersion = require("./data/stable-semver.json");
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeTruthy();
});

it("validate if a version with build metadata is stable", () => {
const semverVersion = require("./data/stable-build-semver.json");
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeTruthy();
});
describe('isStableSemverVersion', () => {
it('validate if a version is stable', () => {
expect(
versionUtils.isStableSemverVersion(stableSemver as any)
).toBeTruthy();
});

it("validate if a pre-release version is not stable", () => {
const semverVersion = require("./data/prerelease-semver.json");
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeFalsy();
});
it('validate if a version with build metadata is stable', () => {
expect(
versionUtils.isStableSemverVersion(stableBuildSemver as any)
).toBeTruthy();
});

it("validate if a pre-release version with build metadata is not stable", () => {
const semverVersion = require("./data/prerelease-build-semver.json");
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeFalsy();
});
it('validate if a pre-release version is not stable', () => {
expect(
versionUtils.isStableSemverVersion(prereleaseSemver as any)
).toBeFalsy();
});

it('validate if a pre-release version with build metadata is not stable', () => {
expect(
versionUtils.isStableSemverVersion(prereleaseBuildSemver as any)
).toBeFalsy();
});
});

describe("validateSemverVersionFromTag", () => {
it("validate a tag containing an valid semantic version", () => {
expect(() => versionUtils.validateSemverVersionFromTag("1.0.0")).not.toThrow();
});
describe('validateSemverVersionFromTag', () => {
it('validate a tag containing an valid semantic version', () => {
IvanZosimov marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
versionUtils.validateSemverVersionFromTag('1.0.0')
).not.toThrow();
});

it("validate a tag containing an valid semantic version with 'v' prefix", () => {
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0")).not.toThrow();
});
it("validate a tag containing an valid semantic version with 'v' prefix", () => {
IvanZosimov marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
versionUtils.validateSemverVersionFromTag('v1.0.0')
).not.toThrow();
});

it("validate a tag containing an valid semantic version with build metadata", () => {
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0+20130313144700")).not.toThrow();
});
it('validate a tag containing an valid semantic version with build metadata', () => {
IvanZosimov marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
versionUtils.validateSemverVersionFromTag('v1.0.0+20130313144700')
).not.toThrow();
});

it("throw when a tag contains an invalid semantic version", () => {
expect(() => versionUtils.validateSemverVersionFromTag("1.0.0invalid")).toThrowError(
"The '1.0.0invalid' doesn't satisfy semantic versioning specification"
);
});
it('throw when a tag contains an invalid semantic version', () => {
expect(() =>
versionUtils.validateSemverVersionFromTag('1.0.0invalid')
).toThrow(
"The '1.0.0invalid' doesn't satisfy semantic versioning specification"
);
});

it("throw when a tag contains an valid unstable semantic version", () => {
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0-beta.1")).toThrowError(
"It is not allowed to specify pre-release version to update the major tag"
);
});
it('throw when a tag contains an valid unstable semantic version', () => {
IvanZosimov marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
versionUtils.validateSemverVersionFromTag('v1.0.0-beta.1')
).toThrow(
'It is not allowed to specify pre-release version to update the major tag'
);
});

it("throw when a tag contains an valid unstable semantic version with build metadata", () => {
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0-beta.1+20130313144700")).toThrowError(
"It is not allowed to specify pre-release version to update the major tag"
);
});
it('throw when a tag contains an valid unstable semantic version with build metadata', () => {
IvanZosimov marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
versionUtils.validateSemverVersionFromTag('v1.0.0-beta.1+20130313144700')
).toThrow(
'It is not allowed to specify pre-release version to update the major tag'
);
});
});

describe("getMajorTagFromFullTag", () => {
describe("get a valid major tag from full tag", () => {
it.each([
["1.0.0", "1"],
["v1.0.0", "v1"],
["v1.0.0-beta.1", "v1"],
["v1.0.0+20130313144700", "v1"],
] as [string, string][])("%s -> %s", (sourceTag: string, expectedMajorTag: string) => {
const resultantMajorTag = versionUtils.getMajorTagFromFullTag(sourceTag);
expect(resultantMajorTag).toBe(expectedMajorTag);
});
});
});
describe('getMajorTagFromFullTag', () => {
describe('get a valid major tag from full tag', () => {
it.each([
['1.0.0', '1'],
['v1.0.0', 'v1'],
['v1.0.0-beta.1', 'v1'],
['v1.0.0+20130313144700', 'v1']
] as [string, string][])(
'%s -> %s',
(sourceTag: string, expectedMajorTag: string) => {
const resultantMajorTag =
versionUtils.getMajorTagFromFullTag(sourceTag);
expect(resultantMajorTag).toBe(expectedMajorTag);
}
);
});
});