Skip to content

Commit

Permalink
Explicitly import crypto (#1842)
Browse files Browse the repository at this point in the history
* Explicitly import `crypto`

* Add release notes for 1.11.1

* Fix crypto mock in test

* Fix `crypto` mock

* Lint
  • Loading branch information
joshmgross authored Oct 4, 2024
1 parent 22a72ac commit d14afd7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/cache/src/internal/cacheUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import * as io from '@actions/io'
import * as crypto from 'crypto'
import * as fs from 'fs'
import * as path from 'path'
import * as semver from 'semver'
Expand Down
3 changes: 3 additions & 0 deletions packages/core/RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# @actions/core Releases

### 1.11.1
- Fix uses of `crypto.randomUUID` on Node 18 and earlier [#1842](https://github.com/actions/toolkit/pull/1842)

### 1.11.0
- Add platform info utilities [#1551](https://github.com/actions/toolkit/pull/1551)
- Remove dependency on `uuid` package [#1824](https://github.com/actions/toolkit/pull/1824)
Expand Down
9 changes: 5 additions & 4 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const testEnvVars = {
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
const DELIMITER = `ghadelimiter_${UUID}`

jest.mock('crypto', () => ({
...jest.requireActual('crypto'),
randomUUID: jest.fn(() => UUID)
}))

const TEMP_DIR = path.join(__dirname, '_temp')

describe('@actions/core', () => {
Expand All @@ -66,10 +71,6 @@ describe('@actions/core', () => {
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
}
process.stdout.write = jest.fn()

jest.spyOn(crypto, 'randomUUID').mockImplementation(() => {
return UUID
})
})

afterEach(() => {
Expand Down
18 changes: 9 additions & 9 deletions packages/core/package-lock.json

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

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/core",
"version": "1.11.0",
"version": "1.11.1",
"description": "Actions core lib",
"keywords": [
"github",
Expand Down Expand Up @@ -40,6 +40,6 @@
"@actions/http-client": "^2.0.1"
},
"devDependencies": {
"@types/node": "^12.0.2"
"@types/node": "^16.18.112"
}
}
1 change: 1 addition & 0 deletions packages/core/src/file-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */

import * as crypto from 'crypto'
import * as fs from 'fs'
import * as os from 'os'
import {toCommandValue} from './utils'
Expand Down
1 change: 1 addition & 0 deletions packages/tool-cache/src/tool-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import * as io from '@actions/io'
import * as crypto from 'crypto'
import * as fs from 'fs'
import * as mm from './manifest'
import * as os from 'os'
Expand Down

0 comments on commit d14afd7

Please sign in to comment.