Skip to content

Commit

Permalink
Use folder-hash instead of hash-files. (#45)
Browse files Browse the repository at this point in the history
* Use folder-hash instead of hash-files.

* Fix indentation in jest.config.js

* awaits in separate lines
  • Loading branch information
mgr0dzicki authored Apr 30, 2023
1 parent 3dda482 commit ca4682c
Show file tree
Hide file tree
Showing 11 changed files with 7,850 additions and 2,562 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
test-build:
name: Check if the source files build successfully and match dist/ directory
name: Build the action and run TypeScript tests
runs-on: ubuntu-latest
steps:
- name: Checkout the action
Expand All @@ -24,7 +24,7 @@ jobs:
-u does_not_matter -p ${{ secrets.GITHUB_TOKEN }} -e does_not_m@ter.com
- name: Install dependencies
run: npm ci
- name: Rebuild the action
- name: Rebuild the action and run tests
run: npm run all
- name: Compare the expected and actual src/ directories
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
RUSTC=$(rustc --version | sed -e 's/\s\+/-/g')
SEMVER_CHECKS=$(cargo semver-checks --version | sed -e 's/\s\+/-/g')
echo "KEY=testprefix-testkey-linux-$RUSTC-$SEMVER_CHECKS-da39a3ee5e6b4b0d3255bfef95601890afd80709-semver-checks-rustdoc" >> $GITHUB_OUTPUT
echo "KEY=testprefix-testkey-linux-$RUSTC-$SEMVER_CHECKS-d41d8cd98f00b204e9800998ecf8427e-semver-checks-rustdoc" >> $GITHUB_OUTPUT
- name: Download saved cache
uses: actions/cache/restore@v3
with:
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
RUSTC=$(rustc --version | sed -e 's/\s\+/-/g')
SEMVER_CHECKS=$(cargo semver-checks --version | sed -e 's/\s\+/-/g')
echo "KEY=testprefix-test-cache-exists-default-d45618ed191f0a73-linux-$RUSTC-$SEMVER_CHECKS-da39a3ee5e6b4b0d3255bfef95601890afd80709-semver-checks-rustdoc" >> $GITHUB_OUTPUT
echo "KEY=testprefix-test-cache-exists-default-d45618ed191f0a73-linux-$RUSTC-$SEMVER_CHECKS-d41d8cd98f00b204e9800998ecf8427e-semver-checks-rustdoc" >> $GITHUB_OUTPUT
- name: Download saved cache
uses: actions/cache/restore@v3
with:
Expand Down
25 changes: 25 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as fs from "fs";
import { join } from "path";
import * as crypto from "crypto";

import { hashFiles } from "../src/utils";
import { hashElement } from "folder-hash";

test("test hashFiles on ** pattern", async () => {
const tmpDir = await fs.promises.mkdtemp("cargo-semver-checks-action-test");
await fs.promises.writeFile(join(tmpDir, "Cargo.lock"), "test1");
await fs.promises.mkdir(join(tmpDir, "inner"));
await fs.promises.writeFile(join(tmpDir, "inner", "Cargo.lock"), "test2");

const hashAll = await hashFiles([join(tmpDir, "**", "Cargo.lock")]);

const hashNodeOuter = await hashElement(join(tmpDir, "Cargo.lock"));
const hashNodeInner = await hashElement(join(tmpDir, "inner", "Cargo.lock"));

await fs.promises.rm(tmpDir, { recursive: true });

const hasher = crypto.createHash("md5");
hasher.update(hashNodeOuter.hash);
hasher.update(hashNodeInner.hash);
expect(hashAll).toBe(hasher.digest("hex"));
});
16 changes: 4 additions & 12 deletions dist/index.js

Large diffs are not rendered by default.

347 changes: 151 additions & 196 deletions dist/licenses.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
Loading

0 comments on commit ca4682c

Please sign in to comment.