Skip to content

Commit 0d6e81a

Browse files
init
0 parents  commit 0d6e81a

File tree

11 files changed

+3807
-0
lines changed

11 files changed

+3807
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es6": true
5+
},
6+
"extends": "eslint:recommended"
7+
}

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: test
2+
on: [push]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: Create test folder
12+
run: |
13+
mkdir test
14+
mkdir test2
15+
16+
- name: Create package.json with different versions
17+
run: |
18+
echo '{"version": "1.0.0","name": "my-package"}' > test2/other_name.json
19+
echo '{"version": "1.0.0","name": "my-package"}' > test2/other_name-lock.json
20+
echo '{"version": "1.2.0","name": "my-package"}' > test/package.json
21+
echo '{"version": "1.2.0","name": "my-package"}' > test/package-lock.json
22+
23+
- name: simple without version
24+
uses: ./
25+
id: simpleWithoutVersion
26+
with:
27+
packageJSON: test/package.json
28+
packageJSONLock: test/package-lock.json
29+
30+
- name: diff without version
31+
uses: ./
32+
id: diffWithoutVersion
33+
with:
34+
packageJSON: test2/other_name.json
35+
packageJSONLock: test2/other_name-lock.json
36+
37+
- name: test
38+
if: steps.simpleWithoutVersion.outputs.cacheKey != steps.diffWithoutVersion.outputs.cacheKey
39+
run: |
40+
echo "Received different cache keys for lock files"
41+
exit 1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 codaline.io
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# node-versionless-cache-key
2+
3+
This action generates a cache key out of the package.json and package-lock.json.
4+
5+
The Problem: The package-lock.json contains the package version. If that versions changes the hash of the file changes. To avoid getting a new cache key, when your package version changes this actions strips the version.
6+
7+
It accepts a package.json and package-lock.json file path.
8+
Nothing special is happening. Just replacing the version in package-lock and getting a hash back.
9+
10+
## What is happening
11+
12+
1. reads json files
13+
2. grab package name from package.json
14+
3. search for that package name and its following version key in package-lock.json
15+
4. replaces all whitespaces, tabs and newlines and the version number with empty string
16+
5. Creates and outputs the new version
17+
18+
## Inputs
19+
20+
- **branch**: The name of the branch to check if the current branch is master or a dev-branch. Default `master`.
21+
- **filePath**: The json file path or file name where the `version` field is present. Default `package.json`.
22+
23+
## Outputs
24+
25+
- **version**: The generated version number.
26+
27+
## Example usage
28+
29+
```
30+
uses: codaline-io/[email protected]
31+
with:
32+
branch: feat/dev-branch
33+
filePath: ./package.json
34+
```

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Node versionless cache key'
2+
description: 'Creates a hash of package-lock.json without the package version'
3+
branding:
4+
color: orange
5+
icon: airplay
6+
inputs:
7+
packageJSON:
8+
description: 'Path to package.json'
9+
required: false
10+
default: 'package.json'
11+
packageLockJSON:
12+
description: 'Path to package-lock.json'
13+
required: false
14+
default: 'package-lock.json'
15+
outputs:
16+
cacheKey:
17+
description: 'cache key of package-lock.json without version'
18+
runs:
19+
using: 'node16'
20+
main: 'dist/index.js'

0 commit comments

Comments
 (0)