Skip to content

Commit

Permalink
feat(yaml-parser): remove actions/cache id path is ~/.npm
Browse files Browse the repository at this point in the history
* test(yaml-parser): add coverage for actions/cache remove step
  • Loading branch information
oscard0m committed Jul 18, 2021
1 parent 0cc5d83 commit 7ee88fa
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
Expand Down

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "12.x"
cache: npm
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "12.x"
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "12.x"
cache: npm
- run: npm ci
- run: npm run build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test
on:
push:
branches:
- "main"
pull_request:
jobs:
main:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [10.x, 12.x, 14.x, 15.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: ~/.npm
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
- name: Jest
run: npx --no-install jest
- name: CLI sanity
run: npm run test:cli-sanity
- name: CLI sanity warning
run: npm run test:cli-sanity-warning
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test
on:
push:
branches:
- "main"
pull_request: null
jobs:
main:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [10.x, 12.x, 14.x, 15.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
- name: Jest
run: npx --no-install jest
- name: CLI sanity
run: npm run test:cli-sanity
- name: CLI sanity warning
run: npm run test:cli-sanity-warning
20 changes: 20 additions & 0 deletions utils/yaml-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ import prettier from "prettier";

const { parseDocument } = YAML;

/**
* Checks if the job has cache and there is a step using 'bahmutov/npm-install'
* @param {boolean} hasCache
* @param {string[]} stepUses
*
* @return {boolean}
*/
const usesBahmutovNpmInstall = (hasCache, stepUses) =>
hasCache && stepUses && stepUses.includes("bahmutov/npm-install");

/**
* Checks if the job has cache and there is a step using 'actions/cache'
* @param {boolean} hasCache
* @param {string[]} stepUses
* @param {object} stepWith
*
* @return {boolean}
*/
const hasActionCacheStep = (hasCache, stepUses, stepWith) =>
hasCache && stepUses && stepUses.includes("actions/cache") && stepWith && stepWith.get('path') === '~/.npm';

/**
* @param {string} cache
*
Expand Down Expand Up @@ -38,6 +56,8 @@ export function getAddCacheToSetupNodeFunction(cache) {
if (usesBahmutovNpmInstall(jobHasCache, stepUses)) {
step.set("run", "npm ci");
step.delete("uses")
} else if (hasActionCacheStep(jobHasCache, stepUses, stepWith)) {
steps.deleteIn([steps.items.indexOf(step)])
} else if (
stepUses &&
stepUses.includes("actions/setup-node") &&
Expand Down

0 comments on commit 7ee88fa

Please sign in to comment.