Skip to content

Commit 7ee88fa

Browse files
committed
feat(yaml-parser): remove actions/cache id path is ~/.npm
* test(yaml-parser): add coverage for actions/cache remove step
1 parent 0cc5d83 commit 7ee88fa

File tree

13 files changed

+301
-14
lines changed

13 files changed

+301
-14
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/cache@v1
14+
with:
15+
path: ~/.npm
16+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
17+
restore-keys: |
18+
${{ runner.os }}-node-
19+
- run: npm ci
20+
- run: npm run build
21+
- run: npx semantic-release
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/cache@v1
14+
with:
15+
path: ~/.npm
16+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
17+
restore-keys: |
18+
${{ runner.os }}-node-
19+
- run: npm ci
20+
- run: npm run build
21+
- run: npx semantic-release
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}

tests/utils/github-action-fixtures/pending-to-add-cache/example2/actual.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ jobs:
1717
with:
1818
node-version: ${{ matrix.node-version }}
1919

20-
- name: Cache node_modules
21-
id: cache-node_modules
22-
uses: actions/cache@v2
23-
with:
24-
path: node_modules
25-
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
26-
2720
- name: npm ci
2821
if: steps.cache-node_modules.outputs.cache-hit != 'true'
2922
run: npm ci

tests/utils/github-action-fixtures/pending-to-add-cache/example2/expected.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ jobs:
1818
node-version: ${{ matrix.node-version }}
1919
cache: npm
2020

21-
- name: Cache node_modules
22-
id: cache-node_modules
23-
uses: actions/cache@v2
24-
with:
25-
path: node_modules
26-
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
27-
2821
- name: npm ci
2922
if: steps.cache-node_modules.outputs.cache-hit != 'true'
3023
run: npm ci

tests/utils/github-action-fixtures/pending-to-add-cache/not-remove-actions-cache-step-node_modules/actual.yml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/utils/github-action-fixtures/pending-to-add-cache/not-remove-actions-cache-step-node_modules/expected.yml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: "12.x"
16+
- uses: actions/cache@v1
17+
with:
18+
path: ~/.npm
19+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
20+
restore-keys: |
21+
${{ runner.os }}-node-
22+
- run: npm ci
23+
- run: npm run build
24+
- run: npx semantic-release
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: "12.x"
16+
cache: npm
17+
- run: npm ci
18+
- run: npm run build
19+
- run: npx semantic-release
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: "12.x"
16+
- uses: actions/cache@v1
17+
with:
18+
path: ~/.npm
19+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
20+
restore-keys: |
21+
${{ runner.os }}-node-
22+
- run: npm ci
23+
- run: npm run build
24+
- run: npx semantic-release
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: "12.x"
16+
cache: npm
17+
- run: npm ci
18+
- run: npm run build
19+
- run: npx semantic-release
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
NPM_TOKEN: ${{ secrets.PROBOTBOT_NPM_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
jobs:
8+
main:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, windows-latest, macOS-latest]
13+
node-version: [10.x, 12.x, 14.x, 15.x]
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
20+
- name: Cache node_modules
21+
id: cache-node_modules
22+
uses: actions/cache@v2
23+
with:
24+
path: ~/.npm
25+
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
26+
27+
- name: npm ci
28+
if: steps.cache-node_modules.outputs.cache-hit != 'true'
29+
run: npm ci
30+
- name: Jest
31+
run: npx --no-install jest
32+
- name: CLI sanity
33+
run: npm run test:cli-sanity
34+
- name: CLI sanity warning
35+
run: npm run test:cli-sanity-warning
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request: null
7+
jobs:
8+
main:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, windows-latest, macOS-latest]
13+
node-version: [10.x, 12.x, 14.x, 15.x]
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
cache: npm
20+
21+
- name: npm ci
22+
if: steps.cache-node_modules.outputs.cache-hit != 'true'
23+
run: npm ci
24+
- name: Jest
25+
run: npx --no-install jest
26+
- name: CLI sanity
27+
run: npm run test:cli-sanity
28+
- name: CLI sanity warning
29+
run: npm run test:cli-sanity-warning

utils/yaml-parser.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@ import prettier from "prettier";
33

44
const { parseDocument } = YAML;
55

6+
/**
7+
* Checks if the job has cache and there is a step using 'bahmutov/npm-install'
8+
* @param {boolean} hasCache
9+
* @param {string[]} stepUses
10+
*
11+
* @return {boolean}
12+
*/
613
const usesBahmutovNpmInstall = (hasCache, stepUses) =>
714
hasCache && stepUses && stepUses.includes("bahmutov/npm-install");
815

16+
/**
17+
* Checks if the job has cache and there is a step using 'actions/cache'
18+
* @param {boolean} hasCache
19+
* @param {string[]} stepUses
20+
* @param {object} stepWith
21+
*
22+
* @return {boolean}
23+
*/
24+
const hasActionCacheStep = (hasCache, stepUses, stepWith) =>
25+
hasCache && stepUses && stepUses.includes("actions/cache") && stepWith && stepWith.get('path') === '~/.npm';
26+
927
/**
1028
* @param {string} cache
1129
*
@@ -38,6 +56,8 @@ export function getAddCacheToSetupNodeFunction(cache) {
3856
if (usesBahmutovNpmInstall(jobHasCache, stepUses)) {
3957
step.set("run", "npm ci");
4058
step.delete("uses")
59+
} else if (hasActionCacheStep(jobHasCache, stepUses, stepWith)) {
60+
steps.deleteIn([steps.items.indexOf(step)])
4161
} else if (
4262
stepUses &&
4363
stepUses.includes("actions/setup-node") &&

0 commit comments

Comments
 (0)