-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add github action to check exact package versions
- Loading branch information
1 parent
5f1b6c8
commit 7320f55
Showing
6 changed files
with
529 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: 'Check package version lock' | ||
description: Checks all versions are installed with exact version | ||
runs: | ||
using: 'node12' | ||
main: 'check-version-lock.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const core = require('@actions/core'); | ||
const appPackage = require('../../../package.json'); | ||
|
||
const illegalVersionSymbol = ['~', '^', '>', '<']; | ||
|
||
function containsIllegalChar(input) { | ||
return illegalVersionSymbol.some(symbol => input.includes(symbol)); | ||
} | ||
|
||
(async () => { | ||
try { | ||
const dependencies = appPackage.dependencies; | ||
const devDependencies = appPackage.devDependencies; | ||
|
||
const allPackages = [...Object.entries(dependencies), ...Object.entries(devDependencies)]; | ||
|
||
const illegalPackages = allPackages | ||
.filter(([package, version]) => containsIllegalChar(version)) | ||
.map(([package, version]) => ({ package, version })); | ||
|
||
if (illegalPackages.length > 0) { | ||
core.setFailed(` | ||
There are packages with non-exact versions defined. This presents a security risk. | ||
${JSON.stringify(illegalPackages, null, 2)} | ||
`); | ||
} | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Exact versions | ||
on: | ||
push: | ||
branches: [release/stacking] | ||
pull_request: | ||
branches: [release/stacking] | ||
jobs: | ||
check-versions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v1 | ||
|
||
- name: Cache node_modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ hashFiles('**/yarn.lock') }} | ||
|
||
- name: Install dependencies | ||
run: yarn install --ignore-scripts --ignore-optional | ||
|
||
- name: Check exact versions | ||
uses: ./.github/actions/check-version-lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.