From 4df2cf43f82fad062e75de3a1becb30e4fcae4a4 Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Fri, 27 Oct 2017 11:25:09 -0700 Subject: [PATCH 1/2] Adding a test to check for the current year in the license and source header --- LICENSE | 2 +- modules/primer-core/index.scss | 2 +- modules/primer-css/index.scss | 2 +- modules/primer-marketing/index.scss | 2 +- modules/primer-product/index.scss | 2 +- package.json | 3 +- script/test-docs | 2 +- tests/test-for-current-year.js | 31 +++++++++++++++++++ .../app/templates/LICENSE | 2 +- tools/stylelint-config-primer/LICENSE | 2 +- tools/stylelint-selector-no-utility/LICENSE | 2 +- 11 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 tests/test-for-current-year.js diff --git a/LICENSE b/LICENSE index 5715c136..61c8a4cf 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 GitHub Inc. +Copyright (c) 2017 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/modules/primer-core/index.scss b/modules/primer-core/index.scss index b032019c..855188ba 100644 --- a/modules/primer-core/index.scss +++ b/modules/primer-core/index.scss @@ -2,7 +2,7 @@ * Primer-core * http://primercss.io * - * Released under MIT license. Copyright 2015 GitHub, Inc. + * Released under MIT license. Copyright (c) 2017 GitHub Inc. */ // Primer master file diff --git a/modules/primer-css/index.scss b/modules/primer-css/index.scss index d317a111..5adfaa75 100644 --- a/modules/primer-css/index.scss +++ b/modules/primer-css/index.scss @@ -2,7 +2,7 @@ * Primer * http://primercss.io * - * Released under MIT license. Copyright 2015 GitHub, Inc. + * Released under MIT license. Copyright (c) 2017 GitHub Inc. */ // Primer master file diff --git a/modules/primer-marketing/index.scss b/modules/primer-marketing/index.scss index e288c932..93c2d0b4 100755 --- a/modules/primer-marketing/index.scss +++ b/modules/primer-marketing/index.scss @@ -2,7 +2,7 @@ * Primer-marketing * http://primercss.io * - * Released under MIT license. Copyright 2015 GitHub, Inc. + * Released under MIT license. Copyright (c) 2017 GitHub Inc. */ // Primer master file diff --git a/modules/primer-product/index.scss b/modules/primer-product/index.scss index acddbdb0..ef581818 100644 --- a/modules/primer-product/index.scss +++ b/modules/primer-product/index.scss @@ -2,7 +2,7 @@ * Primer-product * http://primercss.io * - * Released under MIT license. Copyright 2015 GitHub, Inc. + * Released under MIT license. Copyright (c) 2017 GitHub Inc. */ // Primer master file diff --git a/package.json b/package.json index be728a7c..0ba93cdb 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "release": "script/release", "bump": "lerna publish --exact --skip-npm --since \"v$(npm info primer-css version)\"", "new-module": "script/new-module", - "test": "lerna run test" + "test": "npm run test-all-modules && lerna run test", + "test-all-modules": "ava --verbose tests/test-*.js" }, "devDependencies": { "@storybook/addon-options": "^3.2.6", diff --git a/script/test-docs b/script/test-docs index 955fe988..81c18e46 100755 --- a/script/test-docs +++ b/script/test-docs @@ -1,3 +1,3 @@ #!/bin/bash set -e -$(dirname $0)/npm-run ava --verbose $(dirname $0)/../tests/modules/test-*.js +$(dirname $0)/npm-run ava --verbose $(dirname $0)/../tests/modules/test-document-styles.js diff --git a/tests/test-for-current-year.js b/tests/test-for-current-year.js new file mode 100644 index 00000000..b20394b4 --- /dev/null +++ b/tests/test-for-current-year.js @@ -0,0 +1,31 @@ +const test = require("ava") +const fs = require("fs-extra") +const globby = require("globby") + +const year = (new Date()).getFullYear() + +test(`LICENSE files have the current year ${year}`, t => { + return globby(["**/LICENSE", "!**/node_modules/**/LICENSE"]) + .then(paths => { + t.plan(paths.length) + return paths.map(path => { + const license = fs.readFileSync(path, "utf8") + return t.regex(license, new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`), `The license "${path}" does not include the current year ${year}`) + }) + }) +}) + +test(`Source header copyrights have the current year ${year}`, t => { + return globby(["**/*.css", "**/*.scss", "!**/node_modules/**", "!**/build/**"]) + .then(paths => { + t.plan(paths.length) + return paths.map(path => { + const source = fs.readFileSync(path, "utf8") + if (source.match(/Copyright \(c\)/)) { + return t.regex(source, new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`), `The source's header "${path}" does not include the current year ${year}`) + } else { + return t.true(true) + } + }) + }) +}) diff --git a/tools/generator-primer-module/app/templates/LICENSE b/tools/generator-primer-module/app/templates/LICENSE index 5715c136..61c8a4cf 100644 --- a/tools/generator-primer-module/app/templates/LICENSE +++ b/tools/generator-primer-module/app/templates/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 GitHub Inc. +Copyright (c) 2017 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/tools/stylelint-config-primer/LICENSE b/tools/stylelint-config-primer/LICENSE index 5715c136..61c8a4cf 100644 --- a/tools/stylelint-config-primer/LICENSE +++ b/tools/stylelint-config-primer/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 GitHub Inc. +Copyright (c) 2017 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/tools/stylelint-selector-no-utility/LICENSE b/tools/stylelint-selector-no-utility/LICENSE index 5715c136..61c8a4cf 100644 --- a/tools/stylelint-selector-no-utility/LICENSE +++ b/tools/stylelint-selector-no-utility/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 GitHub Inc. +Copyright (c) 2017 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From de420d9bb79eb180fe5ec4a4b88e7ecb70cbc46a Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Fri, 27 Oct 2017 11:28:00 -0700 Subject: [PATCH 2/2] abstracting out year regex --- tests/test-for-current-year.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test-for-current-year.js b/tests/test-for-current-year.js index b20394b4..8d678007 100644 --- a/tests/test-for-current-year.js +++ b/tests/test-for-current-year.js @@ -3,6 +3,7 @@ const fs = require("fs-extra") const globby = require("globby") const year = (new Date()).getFullYear() +const yearRegex = new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`) test(`LICENSE files have the current year ${year}`, t => { return globby(["**/LICENSE", "!**/node_modules/**/LICENSE"]) @@ -10,7 +11,7 @@ test(`LICENSE files have the current year ${year}`, t => { t.plan(paths.length) return paths.map(path => { const license = fs.readFileSync(path, "utf8") - return t.regex(license, new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`), `The license "${path}" does not include the current year ${year}`) + return t.regex(license, yearRegex, `The license "${path}" does not include the current year ${year}`) }) }) }) @@ -22,7 +23,7 @@ test(`Source header copyrights have the current year ${year}`, t => { return paths.map(path => { const source = fs.readFileSync(path, "utf8") if (source.match(/Copyright \(c\)/)) { - return t.regex(source, new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`), `The source's header "${path}" does not include the current year ${year}`) + return t.regex(source, yearRegex, `The source's header "${path}" does not include the current year ${year}`) } else { return t.true(true) }