mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2026-11-28 11:14:21 +01:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fbe4daab2 | ||
|
|
4bcfe8cded | ||
|
|
03a9076efe | ||
|
|
ba1f8b8e04 | ||
|
|
26ccb9be2d | ||
|
|
b572e07b01 | ||
|
|
4959f8f18c |
No files matched your search
@@ -6,3 +6,9 @@ updates:
|
|||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
cooldown:
|
||||||
|
default-days: 7
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
@@ -16,14 +16,14 @@ The default configuration installs the latest version of OpenTofu CLI and instal
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
```
|
```
|
||||||
|
|
||||||
A specific version of OpenTofu CLI can be installed:
|
A specific version of OpenTofu CLI can be installed:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
tofu_version: 1.6.0
|
tofu_version: 1.6.0
|
||||||
```
|
```
|
||||||
@@ -32,7 +32,7 @@ You can also specify the version in a file (e.g., `.opentofu-version`):
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
tofu_version_file: .opentofu-version
|
tofu_version_file: .opentofu-version
|
||||||
```
|
```
|
||||||
@@ -43,7 +43,7 @@ Credentials for Terraform Cloud ([app.terraform.io](https://app.terraform.io/))
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||||
```
|
```
|
||||||
@@ -52,7 +52,7 @@ Credentials for Terraform Enterprise (TFE) can be configured:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
cli_config_credentials_hostname: 'tofu.example.com'
|
cli_config_credentials_hostname: 'tofu.example.com'
|
||||||
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||||
@@ -62,7 +62,7 @@ The wrapper script installation can be skipped by setting the `tofu_wrapper` var
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
tofu_wrapper: false
|
tofu_wrapper: false
|
||||||
```
|
```
|
||||||
@@ -71,16 +71,27 @@ Caching can be enabled to reduce download time on subsequent workflow runs by st
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
with:
|
with:
|
||||||
cache: true
|
cache: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Validation can be enabled to check the downloaded OpenTofu CLI SHA256 hash against a newline-delimited list of checksums:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: opentofu/setup-opentofu@v2
|
||||||
|
with:
|
||||||
|
checksums: |
|
||||||
|
933b060ab1cf05b106e94af1d370fd14b3006a6845495a67c68734269cc705ad
|
||||||
|
d3d29f51e75a701fc7cf67c0644a8c883a85f36cf1621461988baffd88e7f361
|
||||||
|
```
|
||||||
|
|
||||||
Subsequent steps can access outputs when the wrapper script is installed:
|
Subsequent steps can access outputs when the wrapper script is installed:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
|
|
||||||
- run: tofu init
|
- run: tofu init
|
||||||
|
|
||||||
@@ -107,8 +118,8 @@ defaults:
|
|||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
|
|
||||||
- name: OpenTofu fmt
|
- name: OpenTofu fmt
|
||||||
id: fmt
|
id: fmt
|
||||||
@@ -175,8 +186,8 @@ defaults:
|
|||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: opentofu/setup-opentofu@v1
|
- uses: opentofu/setup-opentofu@v2
|
||||||
|
|
||||||
- name: OpenTofu fmt
|
- name: OpenTofu fmt
|
||||||
id: fmt
|
id: fmt
|
||||||
@@ -275,6 +286,7 @@ The action supports the following inputs:
|
|||||||
named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.
|
named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.
|
||||||
- `cache` - (optional) Whether to use GitHub Actions tool-cache to store and reuse downloaded OpenTofu binaries. Defaults to `false`.
|
- `cache` - (optional) Whether to use GitHub Actions tool-cache to store and reuse downloaded OpenTofu binaries. Defaults to `false`.
|
||||||
- `github_token` - (optional) Override the GitHub token read from the environment variable. Defaults to the value of the `GITHUB_TOKEN` environment variable unless running on Forgejo or Gitea.
|
- `github_token` - (optional) Override the GitHub token read from the environment variable. Defaults to the value of the `GITHUB_TOKEN` environment variable unless running on Forgejo or Gitea.
|
||||||
|
- `checksums` - (optional) A newline-delimited list of valid checksums (SHA256) for the downloaded OpenTofu CLI ZIP. When set, the action will verify the ZIP matches one of the checksums before proceeding. Defaults to `[]`
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ inputs:
|
|||||||
description: 'API token for GitHub to increase the rate limit. Defaults to the GITHUB_TOKEN environment variable unless running on Forgejo/Gitea.'
|
description: 'API token for GitHub to increase the rate limit. Defaults to the GITHUB_TOKEN environment variable unless running on Forgejo/Gitea.'
|
||||||
default: ''
|
default: ''
|
||||||
required: false
|
required: false
|
||||||
|
checksums:
|
||||||
|
description: Newline-delimited list of valid checksums (SHA256 hashes) for the downloaded OpenTofu binary. When set, the action will verify that the binary matches one of these checksums before proceeding.
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
stdout:
|
stdout:
|
||||||
description: 'The STDOUT stream of the call to the `tofu` binary.'
|
description: 'The STDOUT stream of the call to the `tofu` binary.'
|
||||||
|
|||||||
Vendored
+265
-29
@@ -5599,6 +5599,24 @@ class SecureProxyConnectionError extends UndiciError {
|
|||||||
[kSecureProxyConnectionError] = true
|
[kSecureProxyConnectionError] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kMessageSizeExceededError = Symbol.for('undici.error.UND_ERR_WS_MESSAGE_SIZE_EXCEEDED')
|
||||||
|
class MessageSizeExceededError extends UndiciError {
|
||||||
|
constructor (message) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'MessageSizeExceededError'
|
||||||
|
this.message = message || 'Max decompressed message size exceeded'
|
||||||
|
this.code = 'UND_ERR_WS_MESSAGE_SIZE_EXCEEDED'
|
||||||
|
}
|
||||||
|
|
||||||
|
static [Symbol.hasInstance] (instance) {
|
||||||
|
return instance && instance[kMessageSizeExceededError] === true
|
||||||
|
}
|
||||||
|
|
||||||
|
get [kMessageSizeExceededError] () {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
AbortError,
|
AbortError,
|
||||||
HTTPParserError,
|
HTTPParserError,
|
||||||
@@ -5622,7 +5640,8 @@ module.exports = {
|
|||||||
ResponseExceededMaxSizeError,
|
ResponseExceededMaxSizeError,
|
||||||
RequestRetryError,
|
RequestRetryError,
|
||||||
ResponseError,
|
ResponseError,
|
||||||
SecureProxyConnectionError
|
SecureProxyConnectionError,
|
||||||
|
MessageSizeExceededError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5699,6 +5718,10 @@ class Request {
|
|||||||
throw new InvalidArgumentError('upgrade must be a string')
|
throw new InvalidArgumentError('upgrade must be a string')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upgrade && !isValidHeaderValue(upgrade)) {
|
||||||
|
throw new InvalidArgumentError('invalid upgrade header')
|
||||||
|
}
|
||||||
|
|
||||||
if (headersTimeout != null && (!Number.isFinite(headersTimeout) || headersTimeout < 0)) {
|
if (headersTimeout != null && (!Number.isFinite(headersTimeout) || headersTimeout < 0)) {
|
||||||
throw new InvalidArgumentError('invalid headersTimeout')
|
throw new InvalidArgumentError('invalid headersTimeout')
|
||||||
}
|
}
|
||||||
@@ -5993,13 +6016,19 @@ function processHeader (request, key, val) {
|
|||||||
val = `${val}`
|
val = `${val}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.host === null && headerName === 'host') {
|
if (headerName === 'host') {
|
||||||
|
if (request.host !== null) {
|
||||||
|
throw new InvalidArgumentError('duplicate host header')
|
||||||
|
}
|
||||||
if (typeof val !== 'string') {
|
if (typeof val !== 'string') {
|
||||||
throw new InvalidArgumentError('invalid host header')
|
throw new InvalidArgumentError('invalid host header')
|
||||||
}
|
}
|
||||||
// Consumed by Client
|
// Consumed by Client
|
||||||
request.host = val
|
request.host = val
|
||||||
} else if (request.contentLength === null && headerName === 'content-length') {
|
} else if (headerName === 'content-length') {
|
||||||
|
if (request.contentLength !== null) {
|
||||||
|
throw new InvalidArgumentError('duplicate content-length header')
|
||||||
|
}
|
||||||
request.contentLength = parseInt(val, 10)
|
request.contentLength = parseInt(val, 10)
|
||||||
if (!Number.isFinite(request.contentLength)) {
|
if (!Number.isFinite(request.contentLength)) {
|
||||||
throw new InvalidArgumentError('invalid content-length header')
|
throw new InvalidArgumentError('invalid content-length header')
|
||||||
@@ -28716,17 +28745,30 @@ module.exports = {
|
|||||||
|
|
||||||
const { createInflateRaw, Z_DEFAULT_WINDOWBITS } = __nccwpck_require__(8522)
|
const { createInflateRaw, Z_DEFAULT_WINDOWBITS } = __nccwpck_require__(8522)
|
||||||
const { isValidClientWindowBits } = __nccwpck_require__(8625)
|
const { isValidClientWindowBits } = __nccwpck_require__(8625)
|
||||||
|
const { MessageSizeExceededError } = __nccwpck_require__(8707)
|
||||||
|
|
||||||
const tail = Buffer.from([0x00, 0x00, 0xff, 0xff])
|
const tail = Buffer.from([0x00, 0x00, 0xff, 0xff])
|
||||||
const kBuffer = Symbol('kBuffer')
|
const kBuffer = Symbol('kBuffer')
|
||||||
const kLength = Symbol('kLength')
|
const kLength = Symbol('kLength')
|
||||||
|
|
||||||
|
// Default maximum decompressed message size: 4 MB
|
||||||
|
const kDefaultMaxDecompressedSize = 4 * 1024 * 1024
|
||||||
|
|
||||||
class PerMessageDeflate {
|
class PerMessageDeflate {
|
||||||
/** @type {import('node:zlib').InflateRaw} */
|
/** @type {import('node:zlib').InflateRaw} */
|
||||||
#inflate
|
#inflate
|
||||||
|
|
||||||
#options = {}
|
#options = {}
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
#aborted = false
|
||||||
|
|
||||||
|
/** @type {Function|null} */
|
||||||
|
#currentCallback = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Map<string, string>} extensions
|
||||||
|
*/
|
||||||
constructor (extensions) {
|
constructor (extensions) {
|
||||||
this.#options.serverNoContextTakeover = extensions.has('server_no_context_takeover')
|
this.#options.serverNoContextTakeover = extensions.has('server_no_context_takeover')
|
||||||
this.#options.serverMaxWindowBits = extensions.get('server_max_window_bits')
|
this.#options.serverMaxWindowBits = extensions.get('server_max_window_bits')
|
||||||
@@ -28738,6 +28780,11 @@ class PerMessageDeflate {
|
|||||||
// payload of the message.
|
// payload of the message.
|
||||||
// 2. Decompress the resulting data using DEFLATE.
|
// 2. Decompress the resulting data using DEFLATE.
|
||||||
|
|
||||||
|
if (this.#aborted) {
|
||||||
|
callback(new MessageSizeExceededError())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.#inflate) {
|
if (!this.#inflate) {
|
||||||
let windowBits = Z_DEFAULT_WINDOWBITS
|
let windowBits = Z_DEFAULT_WINDOWBITS
|
||||||
|
|
||||||
@@ -28750,13 +28797,37 @@ class PerMessageDeflate {
|
|||||||
windowBits = Number.parseInt(this.#options.serverMaxWindowBits)
|
windowBits = Number.parseInt(this.#options.serverMaxWindowBits)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#inflate = createInflateRaw({ windowBits })
|
try {
|
||||||
|
this.#inflate = createInflateRaw({ windowBits })
|
||||||
|
} catch (err) {
|
||||||
|
callback(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.#inflate[kBuffer] = []
|
this.#inflate[kBuffer] = []
|
||||||
this.#inflate[kLength] = 0
|
this.#inflate[kLength] = 0
|
||||||
|
|
||||||
this.#inflate.on('data', (data) => {
|
this.#inflate.on('data', (data) => {
|
||||||
this.#inflate[kBuffer].push(data)
|
if (this.#aborted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.#inflate[kLength] += data.length
|
this.#inflate[kLength] += data.length
|
||||||
|
|
||||||
|
if (this.#inflate[kLength] > kDefaultMaxDecompressedSize) {
|
||||||
|
this.#aborted = true
|
||||||
|
this.#inflate.removeAllListeners()
|
||||||
|
this.#inflate.destroy()
|
||||||
|
this.#inflate = null
|
||||||
|
|
||||||
|
if (this.#currentCallback) {
|
||||||
|
const cb = this.#currentCallback
|
||||||
|
this.#currentCallback = null
|
||||||
|
cb(new MessageSizeExceededError())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#inflate[kBuffer].push(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.#inflate.on('error', (err) => {
|
this.#inflate.on('error', (err) => {
|
||||||
@@ -28765,16 +28836,22 @@ class PerMessageDeflate {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#currentCallback = callback
|
||||||
this.#inflate.write(chunk)
|
this.#inflate.write(chunk)
|
||||||
if (fin) {
|
if (fin) {
|
||||||
this.#inflate.write(tail)
|
this.#inflate.write(tail)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#inflate.flush(() => {
|
this.#inflate.flush(() => {
|
||||||
|
if (this.#aborted || !this.#inflate) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength])
|
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength])
|
||||||
|
|
||||||
this.#inflate[kBuffer].length = 0
|
this.#inflate[kBuffer].length = 0
|
||||||
this.#inflate[kLength] = 0
|
this.#inflate[kLength] = 0
|
||||||
|
this.#currentCallback = null
|
||||||
|
|
||||||
callback(null, full)
|
callback(null, full)
|
||||||
})
|
})
|
||||||
@@ -28828,6 +28905,10 @@ class ByteParser extends Writable {
|
|||||||
/** @type {Map<string, PerMessageDeflate>} */
|
/** @type {Map<string, PerMessageDeflate>} */
|
||||||
#extensions
|
#extensions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import('./websocket').WebSocket} ws
|
||||||
|
* @param {Map<string, string>|null} extensions
|
||||||
|
*/
|
||||||
constructor (ws, extensions) {
|
constructor (ws, extensions) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@@ -28970,6 +29051,7 @@ class ByteParser extends Writable {
|
|||||||
|
|
||||||
const buffer = this.consume(8)
|
const buffer = this.consume(8)
|
||||||
const upper = buffer.readUInt32BE(0)
|
const upper = buffer.readUInt32BE(0)
|
||||||
|
const lower = buffer.readUInt32BE(4)
|
||||||
|
|
||||||
// 2^31 is the maximum bytes an arraybuffer can contain
|
// 2^31 is the maximum bytes an arraybuffer can contain
|
||||||
// on 32-bit systems. Although, on 64-bit systems, this is
|
// on 32-bit systems. Although, on 64-bit systems, this is
|
||||||
@@ -28977,14 +29059,12 @@ class ByteParser extends Writable {
|
|||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
|
||||||
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/common/globals.h;drc=1946212ac0100668f14eb9e2843bdd846e510a1e;bpv=1;bpt=1;l=1275
|
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/common/globals.h;drc=1946212ac0100668f14eb9e2843bdd846e510a1e;bpv=1;bpt=1;l=1275
|
||||||
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-array-buffer.h;l=34;drc=1946212ac0100668f14eb9e2843bdd846e510a1e
|
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-array-buffer.h;l=34;drc=1946212ac0100668f14eb9e2843bdd846e510a1e
|
||||||
if (upper > 2 ** 31 - 1) {
|
if (upper !== 0 || lower > 2 ** 31 - 1) {
|
||||||
failWebsocketConnection(this.ws, 'Received payload length > 2^31 bytes.')
|
failWebsocketConnection(this.ws, 'Received payload length > 2^31 bytes.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const lower = buffer.readUInt32BE(4)
|
this.#info.payloadLength = lower
|
||||||
|
|
||||||
this.#info.payloadLength = (upper << 8) + lower
|
|
||||||
this.#state = parserStates.READ_DATA
|
this.#state = parserStates.READ_DATA
|
||||||
} else if (this.#state === parserStates.READ_DATA) {
|
} else if (this.#state === parserStates.READ_DATA) {
|
||||||
if (this.#byteOffset < this.#info.payloadLength) {
|
if (this.#byteOffset < this.#info.payloadLength) {
|
||||||
@@ -29014,7 +29094,7 @@ class ByteParser extends Writable {
|
|||||||
} else {
|
} else {
|
||||||
this.#extensions.get('permessage-deflate').decompress(body, this.#info.fin, (error, data) => {
|
this.#extensions.get('permessage-deflate').decompress(body, this.#info.fin, (error, data) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
closeWebSocketConnection(this.ws, 1007, error.message, error.message.length)
|
failWebsocketConnection(this.ws, error.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29618,6 +29698,12 @@ function parseExtensions (extensions) {
|
|||||||
* @param {string} value
|
* @param {string} value
|
||||||
*/
|
*/
|
||||||
function isValidClientWindowBits (value) {
|
function isValidClientWindowBits (value) {
|
||||||
|
// Must have at least one character
|
||||||
|
if (value.length === 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check all characters are ASCII digits
|
||||||
for (let i = 0; i < value.length; i++) {
|
for (let i = 0; i < value.length; i++) {
|
||||||
const byte = value.charCodeAt(i)
|
const byte = value.charCodeAt(i)
|
||||||
|
|
||||||
@@ -29626,7 +29712,9 @@ function isValidClientWindowBits (value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
// Check numeric range: zlib requires windowBits in range 8-15
|
||||||
|
const num = Number.parseInt(value, 10)
|
||||||
|
return num >= 8 && num <= 15
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://nodejs.org/api/intl.html#detecting-internationalization-support
|
// https://nodejs.org/api/intl.html#detecting-internationalization-support
|
||||||
@@ -30104,7 +30192,7 @@ class WebSocket extends EventTarget {
|
|||||||
* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
*/
|
*/
|
||||||
#onConnectionEstablished (response, parsedExtensions) {
|
#onConnectionEstablished (response, parsedExtensions) {
|
||||||
// processResponse is called when the "response’s header list has been received and initialized."
|
// processResponse is called when the "response's header list has been received and initialized."
|
||||||
// once this happens, the connection is open
|
// once this happens, the connection is open
|
||||||
this[kResponse] = response
|
this[kResponse] = response
|
||||||
|
|
||||||
@@ -34306,6 +34394,83 @@ function _unique(values) {
|
|||||||
return Array.from(new Set(values));
|
return Array.from(new Set(values));
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=tool-cache.js.map
|
//# sourceMappingURL=tool-cache.js.map
|
||||||
|
;// CONCATENATED MODULE: ./lib/error-utils.js
|
||||||
|
/**
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*
|
||||||
|
* Normalizes errors (including AggregateError from fetch/undici) into
|
||||||
|
* a single, actionable message for GitHub Actions logs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user-friendly message from any error.
|
||||||
|
* - AggregateError: flattens error.errors so network/download causes are visible.
|
||||||
|
* - Standard Error: returns message; includes cause if present (Node 16+).
|
||||||
|
*
|
||||||
|
* @param {unknown} error - Caught value (Error, AggregateError, or other).
|
||||||
|
* @returns {string} Single-line message suitable for core.setFailed().
|
||||||
|
*/
|
||||||
|
function getErrorMessage (error) {
|
||||||
|
if (error instanceof AggregateError && Array.isArray(error.errors)) {
|
||||||
|
if (error.errors.length === 0) {
|
||||||
|
return 'AggregateError (one or more operations failed)';
|
||||||
|
}
|
||||||
|
const parts = error.errors.map((e) => (e && typeof e.message === 'string' ? e.message : String(e)));
|
||||||
|
const combined = parts.join('; ');
|
||||||
|
return combined || 'AggregateError (one or more operations failed)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (error.cause instanceof Error) {
|
||||||
|
return `${error.message}: ${error.cause.message}`;
|
||||||
|
}
|
||||||
|
return error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a detailed string for logging (e.g. core.debug or core.error).
|
||||||
|
* Includes stack and, for AggregateError, each nested error.
|
||||||
|
*
|
||||||
|
* @param {unknown} error - Caught value.
|
||||||
|
* @returns {string} Multi-line detail string.
|
||||||
|
*/
|
||||||
|
function getErrorDetail (error) {
|
||||||
|
const lines = [];
|
||||||
|
|
||||||
|
if (error instanceof AggregateError && Array.isArray(error.errors)) {
|
||||||
|
lines.push(`AggregateError (${error.errors.length} error(s)):`);
|
||||||
|
error.errors.forEach((e, i) => {
|
||||||
|
lines.push(` [${i + 1}] ${e instanceof Error ? e.message : String(e)}`);
|
||||||
|
if (e instanceof Error && e.stack) {
|
||||||
|
lines.push(e.stack.split('\n').map((l) => ' ' + l).join('\n'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (error.stack) {
|
||||||
|
lines.push('Outer stack:');
|
||||||
|
lines.push(error.stack);
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
lines.push(error.message);
|
||||||
|
if (error.stack) lines.push(error.stack);
|
||||||
|
if (error.cause) {
|
||||||
|
lines.push('Caused by:');
|
||||||
|
lines.push(getErrorDetail(error.cause));
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./lib/releases.js
|
;// CONCATENATED MODULE: ./lib/releases.js
|
||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
@@ -34316,6 +34481,7 @@ function _unique(values) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Build {
|
class Build {
|
||||||
constructor (version, name) {
|
constructor (version, name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -34353,7 +34519,13 @@ async function fetchReleases (githubToken) {
|
|||||||
Accept: 'application/json'
|
Accept: 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const resp = await http.get(url, headers);
|
let resp;
|
||||||
|
try {
|
||||||
|
resp = await http.get(url, headers);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to fetch OpenTofu releases from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (resp.message.statusCode !== HttpCodes.OK) {
|
if (resp.message.statusCode !== HttpCodes.OK) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -34361,8 +34533,21 @@ async function fetchReleases (githubToken) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await resp.readBody();
|
let body;
|
||||||
const releasesMeta = JSON.parse(body);
|
try {
|
||||||
|
body = await resp.readBody();
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to read releases response: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let releasesMeta;
|
||||||
|
try {
|
||||||
|
releasesMeta = JSON.parse(body);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Invalid releases JSON from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
@@ -34436,6 +34621,26 @@ async function getRelease (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: external "stream/promises"
|
||||||
|
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("stream/promises");
|
||||||
|
;// CONCATENATED MODULE: ./lib/util.js
|
||||||
|
/**
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function fileSHA256 (filePath) {
|
||||||
|
const hash = (0,external_crypto_namespaceObject.createHash)('sha256');
|
||||||
|
const fileStream = (0,external_fs_namespaceObject.createReadStream)(filePath);
|
||||||
|
|
||||||
|
await (0,promises_namespaceObject.pipeline)(fileStream, hash);
|
||||||
|
return hash.digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./lib/setup-tofu.js
|
;// CONCATENATED MODULE: ./lib/setup-tofu.js
|
||||||
/**
|
/**
|
||||||
* Copyright (c) HashiCorp, Inc.
|
* Copyright (c) HashiCorp, Inc.
|
||||||
@@ -34455,6 +34660,8 @@ async function getRelease (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// __dirname is not available in ES modules, so we need to construct it ourselves
|
// __dirname is not available in ES modules, so we need to construct it ourselves
|
||||||
const setup_tofu_dirname = (0,external_path_namespaceObject.dirname)((0,external_url_namespaceObject.fileURLToPath)(import.meta.url));
|
const setup_tofu_dirname = (0,external_path_namespaceObject.dirname)((0,external_url_namespaceObject.fileURLToPath)(import.meta.url));
|
||||||
|
|
||||||
@@ -34477,9 +34684,29 @@ function mapOS (os) {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadAndExtractCLI (url) {
|
async function downloadAndExtractCLI (url, checksums) {
|
||||||
core_debug(`Downloading OpenTofu CLI from ${url}`);
|
core_debug(`Downloading OpenTofu CLI from ${url}`);
|
||||||
const pathToCLIZip = await downloadTool(url);
|
let pathToCLIZip;
|
||||||
|
try {
|
||||||
|
pathToCLIZip = await downloadTool(url);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to download OpenTofu from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checksums.length > 0) {
|
||||||
|
let checksum;
|
||||||
|
try {
|
||||||
|
checksum = await fileSHA256(pathToCLIZip);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to calculate the checksum for the OpenTofu CLI zip: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checksums.includes(checksum)) {
|
||||||
|
throw new Error(`Failed to validate OpenTofu CLI zip checksum. Received: ${checksum}. Valid checksums: ${checksums.join(', ')}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!pathToCLIZip) {
|
if (!pathToCLIZip) {
|
||||||
throw new Error(`Unable to download OpenTofu from ${url}`);
|
throw new Error(`Unable to download OpenTofu from ${url}`);
|
||||||
@@ -34488,14 +34715,19 @@ async function downloadAndExtractCLI (url) {
|
|||||||
let pathToCLI;
|
let pathToCLI;
|
||||||
|
|
||||||
core_debug('Extracting OpenTofu CLI zip file');
|
core_debug('Extracting OpenTofu CLI zip file');
|
||||||
if ((0,external_os_namespaceObject.platform)().startsWith('win')) {
|
try {
|
||||||
core_debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
if ((0,external_os_namespaceObject.platform)().startsWith('win')) {
|
||||||
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
core_debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
||||||
await mv(pathToCLIZip, fixedPathToCLIZip);
|
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
||||||
core_debug(`Moved download to ${fixedPathToCLIZip}`);
|
await mv(pathToCLIZip, fixedPathToCLIZip);
|
||||||
pathToCLI = await extractZip(fixedPathToCLIZip);
|
core_debug(`Moved download to ${fixedPathToCLIZip}`);
|
||||||
} else {
|
pathToCLI = await extractZip(fixedPathToCLIZip);
|
||||||
pathToCLI = await extractZip(pathToCLIZip);
|
} else {
|
||||||
|
pathToCLI = await extractZip(pathToCLIZip);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to extract OpenTofu archive: ${cause}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core_debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
core_debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
||||||
@@ -34580,6 +34812,7 @@ async function run () {
|
|||||||
const credentialsToken = getInput('cli_config_credentials_token');
|
const credentialsToken = getInput('cli_config_credentials_token');
|
||||||
const wrapper = getInput('tofu_wrapper') === 'true';
|
const wrapper = getInput('tofu_wrapper') === 'true';
|
||||||
const useCache = getInput('cache') === 'true';
|
const useCache = getInput('cache') === 'true';
|
||||||
|
const checksums = getMultilineInput('checksums');
|
||||||
let githubToken = getInput('github_token');
|
let githubToken = getInput('github_token');
|
||||||
if (
|
if (
|
||||||
githubToken === '' &&
|
githubToken === '' &&
|
||||||
@@ -34635,12 +34868,12 @@ async function run () {
|
|||||||
pathToCLI = cachedPath;
|
pathToCLI = cachedPath;
|
||||||
} else {
|
} else {
|
||||||
core_debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
core_debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
||||||
const extractedPath = await downloadAndExtractCLI(build.url);
|
const extractedPath = await downloadAndExtractCLI(build.url, checksums);
|
||||||
core_debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
core_debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
||||||
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pathToCLI = await downloadAndExtractCLI(build.url);
|
pathToCLI = await downloadAndExtractCLI(build.url, checksums);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install our wrapper
|
// Install our wrapper
|
||||||
@@ -34657,7 +34890,7 @@ async function run () {
|
|||||||
}
|
}
|
||||||
return release;
|
return release;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core_error(error);
|
core_error(getErrorMessage(error));
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34675,11 +34908,14 @@ async function run () {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await setup_tofu();
|
await setup_tofu();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFailed(error.message);
|
const message = getErrorMessage(error);
|
||||||
|
core_debug(getErrorDetail(error));
|
||||||
|
setFailed(message);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Vendored
+105
-18
@@ -2930,6 +2930,24 @@ class SecureProxyConnectionError extends UndiciError {
|
|||||||
[kSecureProxyConnectionError] = true
|
[kSecureProxyConnectionError] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kMessageSizeExceededError = Symbol.for('undici.error.UND_ERR_WS_MESSAGE_SIZE_EXCEEDED')
|
||||||
|
class MessageSizeExceededError extends UndiciError {
|
||||||
|
constructor (message) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'MessageSizeExceededError'
|
||||||
|
this.message = message || 'Max decompressed message size exceeded'
|
||||||
|
this.code = 'UND_ERR_WS_MESSAGE_SIZE_EXCEEDED'
|
||||||
|
}
|
||||||
|
|
||||||
|
static [Symbol.hasInstance] (instance) {
|
||||||
|
return instance && instance[kMessageSizeExceededError] === true
|
||||||
|
}
|
||||||
|
|
||||||
|
get [kMessageSizeExceededError] () {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
AbortError,
|
AbortError,
|
||||||
HTTPParserError,
|
HTTPParserError,
|
||||||
@@ -2953,7 +2971,8 @@ module.exports = {
|
|||||||
ResponseExceededMaxSizeError,
|
ResponseExceededMaxSizeError,
|
||||||
RequestRetryError,
|
RequestRetryError,
|
||||||
ResponseError,
|
ResponseError,
|
||||||
SecureProxyConnectionError
|
SecureProxyConnectionError,
|
||||||
|
MessageSizeExceededError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3030,6 +3049,10 @@ class Request {
|
|||||||
throw new InvalidArgumentError('upgrade must be a string')
|
throw new InvalidArgumentError('upgrade must be a string')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upgrade && !isValidHeaderValue(upgrade)) {
|
||||||
|
throw new InvalidArgumentError('invalid upgrade header')
|
||||||
|
}
|
||||||
|
|
||||||
if (headersTimeout != null && (!Number.isFinite(headersTimeout) || headersTimeout < 0)) {
|
if (headersTimeout != null && (!Number.isFinite(headersTimeout) || headersTimeout < 0)) {
|
||||||
throw new InvalidArgumentError('invalid headersTimeout')
|
throw new InvalidArgumentError('invalid headersTimeout')
|
||||||
}
|
}
|
||||||
@@ -3324,13 +3347,19 @@ function processHeader (request, key, val) {
|
|||||||
val = `${val}`
|
val = `${val}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.host === null && headerName === 'host') {
|
if (headerName === 'host') {
|
||||||
|
if (request.host !== null) {
|
||||||
|
throw new InvalidArgumentError('duplicate host header')
|
||||||
|
}
|
||||||
if (typeof val !== 'string') {
|
if (typeof val !== 'string') {
|
||||||
throw new InvalidArgumentError('invalid host header')
|
throw new InvalidArgumentError('invalid host header')
|
||||||
}
|
}
|
||||||
// Consumed by Client
|
// Consumed by Client
|
||||||
request.host = val
|
request.host = val
|
||||||
} else if (request.contentLength === null && headerName === 'content-length') {
|
} else if (headerName === 'content-length') {
|
||||||
|
if (request.contentLength !== null) {
|
||||||
|
throw new InvalidArgumentError('duplicate content-length header')
|
||||||
|
}
|
||||||
request.contentLength = parseInt(val, 10)
|
request.contentLength = parseInt(val, 10)
|
||||||
if (!Number.isFinite(request.contentLength)) {
|
if (!Number.isFinite(request.contentLength)) {
|
||||||
throw new InvalidArgumentError('invalid content-length header')
|
throw new InvalidArgumentError('invalid content-length header')
|
||||||
@@ -26047,17 +26076,30 @@ module.exports = {
|
|||||||
|
|
||||||
const { createInflateRaw, Z_DEFAULT_WINDOWBITS } = __nccwpck_require__(8522)
|
const { createInflateRaw, Z_DEFAULT_WINDOWBITS } = __nccwpck_require__(8522)
|
||||||
const { isValidClientWindowBits } = __nccwpck_require__(8625)
|
const { isValidClientWindowBits } = __nccwpck_require__(8625)
|
||||||
|
const { MessageSizeExceededError } = __nccwpck_require__(8707)
|
||||||
|
|
||||||
const tail = Buffer.from([0x00, 0x00, 0xff, 0xff])
|
const tail = Buffer.from([0x00, 0x00, 0xff, 0xff])
|
||||||
const kBuffer = Symbol('kBuffer')
|
const kBuffer = Symbol('kBuffer')
|
||||||
const kLength = Symbol('kLength')
|
const kLength = Symbol('kLength')
|
||||||
|
|
||||||
|
// Default maximum decompressed message size: 4 MB
|
||||||
|
const kDefaultMaxDecompressedSize = 4 * 1024 * 1024
|
||||||
|
|
||||||
class PerMessageDeflate {
|
class PerMessageDeflate {
|
||||||
/** @type {import('node:zlib').InflateRaw} */
|
/** @type {import('node:zlib').InflateRaw} */
|
||||||
#inflate
|
#inflate
|
||||||
|
|
||||||
#options = {}
|
#options = {}
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
#aborted = false
|
||||||
|
|
||||||
|
/** @type {Function|null} */
|
||||||
|
#currentCallback = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Map<string, string>} extensions
|
||||||
|
*/
|
||||||
constructor (extensions) {
|
constructor (extensions) {
|
||||||
this.#options.serverNoContextTakeover = extensions.has('server_no_context_takeover')
|
this.#options.serverNoContextTakeover = extensions.has('server_no_context_takeover')
|
||||||
this.#options.serverMaxWindowBits = extensions.get('server_max_window_bits')
|
this.#options.serverMaxWindowBits = extensions.get('server_max_window_bits')
|
||||||
@@ -26069,6 +26111,11 @@ class PerMessageDeflate {
|
|||||||
// payload of the message.
|
// payload of the message.
|
||||||
// 2. Decompress the resulting data using DEFLATE.
|
// 2. Decompress the resulting data using DEFLATE.
|
||||||
|
|
||||||
|
if (this.#aborted) {
|
||||||
|
callback(new MessageSizeExceededError())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.#inflate) {
|
if (!this.#inflate) {
|
||||||
let windowBits = Z_DEFAULT_WINDOWBITS
|
let windowBits = Z_DEFAULT_WINDOWBITS
|
||||||
|
|
||||||
@@ -26081,13 +26128,37 @@ class PerMessageDeflate {
|
|||||||
windowBits = Number.parseInt(this.#options.serverMaxWindowBits)
|
windowBits = Number.parseInt(this.#options.serverMaxWindowBits)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#inflate = createInflateRaw({ windowBits })
|
try {
|
||||||
|
this.#inflate = createInflateRaw({ windowBits })
|
||||||
|
} catch (err) {
|
||||||
|
callback(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.#inflate[kBuffer] = []
|
this.#inflate[kBuffer] = []
|
||||||
this.#inflate[kLength] = 0
|
this.#inflate[kLength] = 0
|
||||||
|
|
||||||
this.#inflate.on('data', (data) => {
|
this.#inflate.on('data', (data) => {
|
||||||
this.#inflate[kBuffer].push(data)
|
if (this.#aborted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.#inflate[kLength] += data.length
|
this.#inflate[kLength] += data.length
|
||||||
|
|
||||||
|
if (this.#inflate[kLength] > kDefaultMaxDecompressedSize) {
|
||||||
|
this.#aborted = true
|
||||||
|
this.#inflate.removeAllListeners()
|
||||||
|
this.#inflate.destroy()
|
||||||
|
this.#inflate = null
|
||||||
|
|
||||||
|
if (this.#currentCallback) {
|
||||||
|
const cb = this.#currentCallback
|
||||||
|
this.#currentCallback = null
|
||||||
|
cb(new MessageSizeExceededError())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#inflate[kBuffer].push(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.#inflate.on('error', (err) => {
|
this.#inflate.on('error', (err) => {
|
||||||
@@ -26096,16 +26167,22 @@ class PerMessageDeflate {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#currentCallback = callback
|
||||||
this.#inflate.write(chunk)
|
this.#inflate.write(chunk)
|
||||||
if (fin) {
|
if (fin) {
|
||||||
this.#inflate.write(tail)
|
this.#inflate.write(tail)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#inflate.flush(() => {
|
this.#inflate.flush(() => {
|
||||||
|
if (this.#aborted || !this.#inflate) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength])
|
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength])
|
||||||
|
|
||||||
this.#inflate[kBuffer].length = 0
|
this.#inflate[kBuffer].length = 0
|
||||||
this.#inflate[kLength] = 0
|
this.#inflate[kLength] = 0
|
||||||
|
this.#currentCallback = null
|
||||||
|
|
||||||
callback(null, full)
|
callback(null, full)
|
||||||
})
|
})
|
||||||
@@ -26159,6 +26236,10 @@ class ByteParser extends Writable {
|
|||||||
/** @type {Map<string, PerMessageDeflate>} */
|
/** @type {Map<string, PerMessageDeflate>} */
|
||||||
#extensions
|
#extensions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import('./websocket').WebSocket} ws
|
||||||
|
* @param {Map<string, string>|null} extensions
|
||||||
|
*/
|
||||||
constructor (ws, extensions) {
|
constructor (ws, extensions) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@@ -26301,6 +26382,7 @@ class ByteParser extends Writable {
|
|||||||
|
|
||||||
const buffer = this.consume(8)
|
const buffer = this.consume(8)
|
||||||
const upper = buffer.readUInt32BE(0)
|
const upper = buffer.readUInt32BE(0)
|
||||||
|
const lower = buffer.readUInt32BE(4)
|
||||||
|
|
||||||
// 2^31 is the maximum bytes an arraybuffer can contain
|
// 2^31 is the maximum bytes an arraybuffer can contain
|
||||||
// on 32-bit systems. Although, on 64-bit systems, this is
|
// on 32-bit systems. Although, on 64-bit systems, this is
|
||||||
@@ -26308,14 +26390,12 @@ class ByteParser extends Writable {
|
|||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
|
||||||
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/common/globals.h;drc=1946212ac0100668f14eb9e2843bdd846e510a1e;bpv=1;bpt=1;l=1275
|
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/common/globals.h;drc=1946212ac0100668f14eb9e2843bdd846e510a1e;bpv=1;bpt=1;l=1275
|
||||||
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-array-buffer.h;l=34;drc=1946212ac0100668f14eb9e2843bdd846e510a1e
|
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-array-buffer.h;l=34;drc=1946212ac0100668f14eb9e2843bdd846e510a1e
|
||||||
if (upper > 2 ** 31 - 1) {
|
if (upper !== 0 || lower > 2 ** 31 - 1) {
|
||||||
failWebsocketConnection(this.ws, 'Received payload length > 2^31 bytes.')
|
failWebsocketConnection(this.ws, 'Received payload length > 2^31 bytes.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const lower = buffer.readUInt32BE(4)
|
this.#info.payloadLength = lower
|
||||||
|
|
||||||
this.#info.payloadLength = (upper << 8) + lower
|
|
||||||
this.#state = parserStates.READ_DATA
|
this.#state = parserStates.READ_DATA
|
||||||
} else if (this.#state === parserStates.READ_DATA) {
|
} else if (this.#state === parserStates.READ_DATA) {
|
||||||
if (this.#byteOffset < this.#info.payloadLength) {
|
if (this.#byteOffset < this.#info.payloadLength) {
|
||||||
@@ -26345,7 +26425,7 @@ class ByteParser extends Writable {
|
|||||||
} else {
|
} else {
|
||||||
this.#extensions.get('permessage-deflate').decompress(body, this.#info.fin, (error, data) => {
|
this.#extensions.get('permessage-deflate').decompress(body, this.#info.fin, (error, data) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
closeWebSocketConnection(this.ws, 1007, error.message, error.message.length)
|
failWebsocketConnection(this.ws, error.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26949,6 +27029,12 @@ function parseExtensions (extensions) {
|
|||||||
* @param {string} value
|
* @param {string} value
|
||||||
*/
|
*/
|
||||||
function isValidClientWindowBits (value) {
|
function isValidClientWindowBits (value) {
|
||||||
|
// Must have at least one character
|
||||||
|
if (value.length === 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check all characters are ASCII digits
|
||||||
for (let i = 0; i < value.length; i++) {
|
for (let i = 0; i < value.length; i++) {
|
||||||
const byte = value.charCodeAt(i)
|
const byte = value.charCodeAt(i)
|
||||||
|
|
||||||
@@ -26957,7 +27043,9 @@ function isValidClientWindowBits (value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
// Check numeric range: zlib requires windowBits in range 8-15
|
||||||
|
const num = Number.parseInt(value, 10)
|
||||||
|
return num >= 8 && num <= 15
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://nodejs.org/api/intl.html#detecting-internationalization-support
|
// https://nodejs.org/api/intl.html#detecting-internationalization-support
|
||||||
@@ -27435,7 +27523,7 @@ class WebSocket extends EventTarget {
|
|||||||
* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
||||||
*/
|
*/
|
||||||
#onConnectionEstablished (response, parsedExtensions) {
|
#onConnectionEstablished (response, parsedExtensions) {
|
||||||
// processResponse is called when the "response’s header list has been received and initialized."
|
// processResponse is called when the "response's header list has been received and initialized."
|
||||||
// once this happens, the connection is open
|
// once this happens, the connection is open
|
||||||
this[kResponse] = response
|
this[kResponse] = response
|
||||||
|
|
||||||
@@ -30883,15 +30971,14 @@ async function checkTofu () {
|
|||||||
setOutput('stderr', stderr.contents);
|
setOutput('stderr', stderr.contents);
|
||||||
setOutput('exitcode', exitCode.toString(10));
|
setOutput('exitcode', exitCode.toString(10));
|
||||||
|
|
||||||
if (exitCode === 0 || exitCode === 2) {
|
if (exitCode === 0) {
|
||||||
// A exitCode of 0 is considered a success
|
|
||||||
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
|
|
||||||
// is passed to plan. This denotes Success with non-empty
|
|
||||||
// diff (changes present).
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A non-zero exitCode is considered an error
|
// Any non-zero exitCode is treated as a failure, including exitCode 2 from
|
||||||
|
// `plan -detailed-exitcode` (success with a non-empty diff). Previously 2 was
|
||||||
|
// treated as success, but that hid the signal users opt into `-detailed-exitcode`
|
||||||
|
// to receive.
|
||||||
setFailed(`OpenTofu exited with code ${exitCode}.`);
|
setFailed(`OpenTofu exited with code ${exitCode}.`);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -4,14 +4,17 @@
|
|||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { setFailed } from '@actions/core';
|
import { setFailed, debug } from '@actions/core';
|
||||||
|
|
||||||
import setup from './lib/setup-tofu.js';
|
import setup from './lib/setup-tofu.js';
|
||||||
|
import { getErrorMessage, getErrorDetail } from './lib/error-utils.js';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await setup();
|
await setup();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFailed(error.message);
|
const message = getErrorMessage(error);
|
||||||
|
debug(getErrorDetail(error));
|
||||||
|
setFailed(message);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*
|
||||||
|
* Normalizes errors (including AggregateError from fetch/undici) into
|
||||||
|
* a single, actionable message for GitHub Actions logs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user-friendly message from any error.
|
||||||
|
* - AggregateError: flattens error.errors so network/download causes are visible.
|
||||||
|
* - Standard Error: returns message; includes cause if present (Node 16+).
|
||||||
|
*
|
||||||
|
* @param {unknown} error - Caught value (Error, AggregateError, or other).
|
||||||
|
* @returns {string} Single-line message suitable for core.setFailed().
|
||||||
|
*/
|
||||||
|
function getErrorMessage (error) {
|
||||||
|
if (error instanceof AggregateError && Array.isArray(error.errors)) {
|
||||||
|
if (error.errors.length === 0) {
|
||||||
|
return 'AggregateError (one or more operations failed)';
|
||||||
|
}
|
||||||
|
const parts = error.errors.map((e) => (e && typeof e.message === 'string' ? e.message : String(e)));
|
||||||
|
const combined = parts.join('; ');
|
||||||
|
return combined || 'AggregateError (one or more operations failed)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (error.cause instanceof Error) {
|
||||||
|
return `${error.message}: ${error.cause.message}`;
|
||||||
|
}
|
||||||
|
return error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a detailed string for logging (e.g. core.debug or core.error).
|
||||||
|
* Includes stack and, for AggregateError, each nested error.
|
||||||
|
*
|
||||||
|
* @param {unknown} error - Caught value.
|
||||||
|
* @returns {string} Multi-line detail string.
|
||||||
|
*/
|
||||||
|
function getErrorDetail (error) {
|
||||||
|
const lines = [];
|
||||||
|
|
||||||
|
if (error instanceof AggregateError && Array.isArray(error.errors)) {
|
||||||
|
lines.push(`AggregateError (${error.errors.length} error(s)):`);
|
||||||
|
error.errors.forEach((e, i) => {
|
||||||
|
lines.push(` [${i + 1}] ${e instanceof Error ? e.message : String(e)}`);
|
||||||
|
if (e instanceof Error && e.stack) {
|
||||||
|
lines.push(e.stack.split('\n').map((l) => ' ' + l).join('\n'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (error.stack) {
|
||||||
|
lines.push('Outer stack:');
|
||||||
|
lines.push(error.stack);
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
lines.push(error.message);
|
||||||
|
if (error.stack) lines.push(error.stack);
|
||||||
|
if (error.cause) {
|
||||||
|
lines.push('Caused by:');
|
||||||
|
lines.push(getErrorDetail(error.cause));
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getErrorMessage, getErrorDetail };
|
||||||
+23
-3
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import { HttpClient, HttpCodes } from '@actions/http-client';
|
import { HttpClient, HttpCodes } from '@actions/http-client';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
import { getErrorMessage } from './error-utils.js';
|
||||||
|
|
||||||
class Build {
|
class Build {
|
||||||
constructor (version, name) {
|
constructor (version, name) {
|
||||||
@@ -44,7 +45,13 @@ async function fetchReleases (githubToken) {
|
|||||||
Accept: 'application/json'
|
Accept: 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
const resp = await http.get(url, headers);
|
let resp;
|
||||||
|
try {
|
||||||
|
resp = await http.get(url, headers);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to fetch OpenTofu releases from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (resp.message.statusCode !== HttpCodes.OK) {
|
if (resp.message.statusCode !== HttpCodes.OK) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -52,8 +59,21 @@ async function fetchReleases (githubToken) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await resp.readBody();
|
let body;
|
||||||
const releasesMeta = JSON.parse(body);
|
try {
|
||||||
|
body = await resp.readBody();
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to read releases response: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let releasesMeta;
|
||||||
|
try {
|
||||||
|
releasesMeta = JSON.parse(body);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Invalid releases JSON from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
|
|||||||
+42
-13
@@ -16,12 +16,15 @@ import {
|
|||||||
error as logError,
|
error as logError,
|
||||||
exportVariable,
|
exportVariable,
|
||||||
getInput,
|
getInput,
|
||||||
|
getMultilineInput,
|
||||||
warning,
|
warning,
|
||||||
addPath
|
addPath
|
||||||
} from '@actions/core';
|
} from '@actions/core';
|
||||||
import { downloadTool, extractZip, find, cacheDir } from '@actions/tool-cache';
|
import { downloadTool, extractZip, find, cacheDir } from '@actions/tool-cache';
|
||||||
import { mv, cp, mkdirP } from '@actions/io';
|
import { mv, cp, mkdirP } from '@actions/io';
|
||||||
import { getRelease } from './releases.js';
|
import { getRelease } from './releases.js';
|
||||||
|
import { getErrorMessage } from './error-utils.js';
|
||||||
|
import { fileSHA256 } from './util.js';
|
||||||
|
|
||||||
// __dirname is not available in ES modules, so we need to construct it ourselves
|
// __dirname is not available in ES modules, so we need to construct it ourselves
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
@@ -45,9 +48,29 @@ function mapOS (os) {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadAndExtractCLI (url) {
|
async function downloadAndExtractCLI (url, checksums) {
|
||||||
debug(`Downloading OpenTofu CLI from ${url}`);
|
debug(`Downloading OpenTofu CLI from ${url}`);
|
||||||
const pathToCLIZip = await downloadTool(url);
|
let pathToCLIZip;
|
||||||
|
try {
|
||||||
|
pathToCLIZip = await downloadTool(url);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to download OpenTofu from ${url}: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checksums.length > 0) {
|
||||||
|
let checksum;
|
||||||
|
try {
|
||||||
|
checksum = await fileSHA256(pathToCLIZip);
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to calculate the checksum for the OpenTofu CLI zip: ${cause}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checksums.includes(checksum)) {
|
||||||
|
throw new Error(`Failed to validate OpenTofu CLI zip checksum. Received: ${checksum}. Valid checksums: ${checksums.join(', ')}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!pathToCLIZip) {
|
if (!pathToCLIZip) {
|
||||||
throw new Error(`Unable to download OpenTofu from ${url}`);
|
throw new Error(`Unable to download OpenTofu from ${url}`);
|
||||||
@@ -56,14 +79,19 @@ async function downloadAndExtractCLI (url) {
|
|||||||
let pathToCLI;
|
let pathToCLI;
|
||||||
|
|
||||||
debug('Extracting OpenTofu CLI zip file');
|
debug('Extracting OpenTofu CLI zip file');
|
||||||
if (platform().startsWith('win')) {
|
try {
|
||||||
debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
if (platform().startsWith('win')) {
|
||||||
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
||||||
await mv(pathToCLIZip, fixedPathToCLIZip);
|
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
||||||
debug(`Moved download to ${fixedPathToCLIZip}`);
|
await mv(pathToCLIZip, fixedPathToCLIZip);
|
||||||
pathToCLI = await extractZip(fixedPathToCLIZip);
|
debug(`Moved download to ${fixedPathToCLIZip}`);
|
||||||
} else {
|
pathToCLI = await extractZip(fixedPathToCLIZip);
|
||||||
pathToCLI = await extractZip(pathToCLIZip);
|
} else {
|
||||||
|
pathToCLI = await extractZip(pathToCLIZip);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const cause = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to extract OpenTofu archive: ${cause}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
||||||
@@ -150,6 +178,7 @@ async function run () {
|
|||||||
const credentialsToken = getInput('cli_config_credentials_token');
|
const credentialsToken = getInput('cli_config_credentials_token');
|
||||||
const wrapper = getInput('tofu_wrapper') === 'true';
|
const wrapper = getInput('tofu_wrapper') === 'true';
|
||||||
const useCache = getInput('cache') === 'true';
|
const useCache = getInput('cache') === 'true';
|
||||||
|
const checksums = getMultilineInput('checksums');
|
||||||
let githubToken = getInput('github_token');
|
let githubToken = getInput('github_token');
|
||||||
if (
|
if (
|
||||||
githubToken === '' &&
|
githubToken === '' &&
|
||||||
@@ -205,12 +234,12 @@ async function run () {
|
|||||||
pathToCLI = cachedPath;
|
pathToCLI = cachedPath;
|
||||||
} else {
|
} else {
|
||||||
debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
||||||
const extractedPath = await downloadAndExtractCLI(build.url);
|
const extractedPath = await downloadAndExtractCLI(build.url, checksums);
|
||||||
debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
||||||
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pathToCLI = await downloadAndExtractCLI(build.url);
|
pathToCLI = await downloadAndExtractCLI(build.url, checksums);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install our wrapper
|
// Install our wrapper
|
||||||
@@ -227,7 +256,7 @@ async function run () {
|
|||||||
}
|
}
|
||||||
return release;
|
return release;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error);
|
logError(getErrorMessage(error));
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getErrorMessage, getErrorDetail } from '../error-utils.js';
|
||||||
|
|
||||||
|
describe('error-utils', () => {
|
||||||
|
describe('getErrorMessage', () => {
|
||||||
|
it('returns message for standard Error', () => {
|
||||||
|
expect(getErrorMessage(new Error('Something failed'))).toBe('Something failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes cause for Error with cause (Node 16+)', () => {
|
||||||
|
const cause = new Error('Network timeout');
|
||||||
|
const err = new Error('Download failed');
|
||||||
|
err.cause = cause;
|
||||||
|
expect(getErrorMessage(err)).toBe('Download failed: Network timeout');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('flattens AggregateError into a single message', () => {
|
||||||
|
const err = new AggregateError(
|
||||||
|
[new Error('ECONNREFUSED'), new Error('getaddrinfo ENOTFOUND')],
|
||||||
|
'AggregateError'
|
||||||
|
);
|
||||||
|
const msg = getErrorMessage(err);
|
||||||
|
expect(msg).toContain('ECONNREFUSED');
|
||||||
|
expect(msg).toContain('getaddrinfo ENOTFOUND');
|
||||||
|
expect(msg).not.toBe('AggregateError');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns fallback for AggregateError with empty errors', () => {
|
||||||
|
const err = new AggregateError([], 'AggregateError');
|
||||||
|
expect(getErrorMessage(err)).toBe('AggregateError (one or more operations failed)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('coerces non-Error to string', () => {
|
||||||
|
expect(getErrorMessage('oops')).toBe('oops');
|
||||||
|
expect(getErrorMessage(123)).toBe('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getErrorDetail', () => {
|
||||||
|
it('includes stack for Error', () => {
|
||||||
|
const err = new Error('test');
|
||||||
|
const detail = getErrorDetail(err);
|
||||||
|
expect(detail).toContain('test');
|
||||||
|
expect(detail).toContain('Error');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes each nested error for AggregateError', () => {
|
||||||
|
const err = new AggregateError(
|
||||||
|
[new Error('A'), new Error('B')],
|
||||||
|
'AggregateError'
|
||||||
|
);
|
||||||
|
const detail = getErrorDetail(err);
|
||||||
|
expect(detail).toContain('A');
|
||||||
|
expect(detail).toContain('B');
|
||||||
|
expect(detail).toContain('2 error(s)');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,6 +14,7 @@ import { join } from 'path';
|
|||||||
// Set up mocks BEFORE dynamic imports
|
// Set up mocks BEFORE dynamic imports
|
||||||
jest.unstable_mockModule('@actions/core', () => ({
|
jest.unstable_mockModule('@actions/core', () => ({
|
||||||
getInput: jest.fn(),
|
getInput: jest.fn(),
|
||||||
|
getMultilineInput: jest.fn(),
|
||||||
setOutput: jest.fn(),
|
setOutput: jest.fn(),
|
||||||
setFailed: jest.fn(),
|
setFailed: jest.fn(),
|
||||||
debug: jest.fn(),
|
debug: jest.fn(),
|
||||||
@@ -41,12 +42,17 @@ jest.unstable_mockModule('../releases.js', () => ({
|
|||||||
Release: jest.fn()
|
Release: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.unstable_mockModule('../util.js', () => ({
|
||||||
|
fileSHA256: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
// Dynamic imports pick up the mocks
|
// Dynamic imports pick up the mocks
|
||||||
const { getInput, warning } = await import('@actions/core');
|
const { getInput, getMultilineInput, warning } = await import('@actions/core');
|
||||||
const tc = await import('@actions/tool-cache');
|
const tc = await import('@actions/tool-cache');
|
||||||
const io = await import('@actions/io');
|
const io = await import('@actions/io');
|
||||||
const { getRelease } = await import('../releases.js');
|
const { getRelease } = await import('../releases.js');
|
||||||
const { default: setup } = await import('../setup-tofu.js');
|
const { default: setup } = await import('../setup-tofu.js');
|
||||||
|
const { fileSHA256 } = await import('../util.js');
|
||||||
|
|
||||||
// Set up global test fixtures
|
// Set up global test fixtures
|
||||||
const fallbackVersion = 'latest';
|
const fallbackVersion = 'latest';
|
||||||
@@ -94,6 +100,13 @@ describe('setup-tofu', () => {
|
|||||||
return defaults[name] || '';
|
return defaults[name] || '';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getMultilineInput.mockImplementation((name) => {
|
||||||
|
const defaults = {
|
||||||
|
checksums: []
|
||||||
|
};
|
||||||
|
return defaults[name] || [];
|
||||||
|
});
|
||||||
|
|
||||||
// Mock environment variables
|
// Mock environment variables
|
||||||
process.env.GITHUB_TOKEN = 'mock-github-token';
|
process.env.GITHUB_TOKEN = 'mock-github-token';
|
||||||
});
|
});
|
||||||
@@ -278,4 +291,53 @@ describe('setup-tofu', () => {
|
|||||||
expect(tc.cacheDir).not.toHaveBeenCalled();
|
expect(tc.cacheDir).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('checksum validation', () => {
|
||||||
|
const mockChecksum = 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6';
|
||||||
|
const mockChecksum2 = 'fcfac0a865b57e0711cb8bae47c8fc70ad93198fa6146a40020ea459715fda83';
|
||||||
|
const mockInvalidChecksum = 'invalidchecksuminvalidchecksuminvalidchecksuminvalidchecksum';
|
||||||
|
fileSHA256.mockResolvedValue(mockChecksum);
|
||||||
|
|
||||||
|
it('should validate checksum when checksums are provided', async () => {
|
||||||
|
getMultilineInput.mockImplementation((name) => {
|
||||||
|
const defaults = {
|
||||||
|
checksums: [mockInvalidChecksum, mockChecksum]
|
||||||
|
|
||||||
|
};
|
||||||
|
return defaults[name] ?? [];
|
||||||
|
});
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
expect(fileSHA256).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not validate checksum when no checksums are provided', async () => {
|
||||||
|
getMultilineInput.mockImplementation((name) => {
|
||||||
|
const defaults = {
|
||||||
|
checksums: []
|
||||||
|
|
||||||
|
};
|
||||||
|
return defaults[name] ?? [];
|
||||||
|
});
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
expect(fileSHA256).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error when checksum validation fails', async () => {
|
||||||
|
fileSHA256.mockResolvedValue(mockInvalidChecksum);
|
||||||
|
|
||||||
|
getMultilineInput.mockImplementation((name) => {
|
||||||
|
const defaults = {
|
||||||
|
checksums: [mockChecksum, mockChecksum2]
|
||||||
|
|
||||||
|
};
|
||||||
|
return defaults[name] ?? [];
|
||||||
|
});
|
||||||
|
await expect(setup()).rejects.toMatchObject(new Error(
|
||||||
|
`Failed to validate OpenTofu CLI zip checksum. Received: ${mockInvalidChecksum}. Valid checksums: ${mockChecksum}, ${mockChecksum2}`));
|
||||||
|
expect(fileSHA256).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenTofu
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createHash } from 'crypto';
|
||||||
|
import { createReadStream } from 'fs';
|
||||||
|
import { pipeline } from 'stream/promises';
|
||||||
|
|
||||||
|
export async function fileSHA256 (filePath) {
|
||||||
|
const hash = createHash('sha256');
|
||||||
|
const fileStream = createReadStream(filePath);
|
||||||
|
|
||||||
|
await pipeline(fileStream, hash);
|
||||||
|
return hash.digest('hex');
|
||||||
|
}
|
||||||
Generated
+36
-36
@@ -597,21 +597,21 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/core": {
|
"node_modules/@emnapi/core": {
|
||||||
"version": "1.8.1",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.9.0.tgz",
|
||||||
"integrity": "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg==",
|
"integrity": "sha512-0DQ98G9ZQZOxfUcQn1waV2yS8aWdZ6kJMbYCJB3oUBecjWYO1fqJ+a1DRfPF3O5JEkwqwP1A9QEN/9mYm2Yd0w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emnapi/wasi-threads": "1.1.0",
|
"@emnapi/wasi-threads": "1.2.0",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/runtime": {
|
"node_modules/@emnapi/runtime": {
|
||||||
"version": "1.8.1",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.9.0.tgz",
|
||||||
"integrity": "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg==",
|
"integrity": "sha512-QN75eB0IH2ywSpRpNddCRfQIhmJYBCJ1x5Lb3IscKAL8bMnVAKnRg8dCoXbHzVLLH7P38N2Z3mtulB7W0J0FKw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
@@ -620,9 +620,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/wasi-threads": {
|
"node_modules/@emnapi/wasi-threads": {
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.0.tgz",
|
||||||
"integrity": "sha512-WI0DdZ8xFSbgMjR1sFsKABJ/C5OnRrjT06JXbZKexJGrDuPTzZdDYfFlsgcCXCyf+suG5QU2e/y1Wo2V/OapLQ==",
|
"integrity": "sha512-N10dEJNSsUx41Z6pZsXU8FjPjpBEplgH24sfkmITrBED1/U2Esum9F3lfLrMjKHHjmi557zQn7kR9R+XWXu5Rg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
@@ -1522,9 +1522,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "25.4.0",
|
"version": "25.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.0.tgz",
|
||||||
"integrity": "sha512-9wLpoeWuBlcbBpOY3XmzSTG3oscB6xjBEEtn+pYXTfhyXhIxC5FsBer2KTopBlvKEiW9l13po9fq+SJY/5lkhw==",
|
"integrity": "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1934,9 +1934,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/anymatch/node_modules/picomatch": {
|
"node_modules/anymatch/node_modules/picomatch": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz",
|
||||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
"integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -2204,9 +2204,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/baseline-browser-mapping": {
|
"node_modules/baseline-browser-mapping": {
|
||||||
"version": "2.10.0",
|
"version": "2.10.7",
|
||||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.7.tgz",
|
||||||
"integrity": "sha512-lIyg0szRfYbiy67j9KN8IyeD7q7hcmqnJ1ddWmNt19ItGpNN64mnllmxUNFIOdOm6by97jlL6wfpTTJrmnjWAA==",
|
"integrity": "sha512-1ghYO3HnxGec0TCGBXiDLVns4eCSx4zJpxnHrlqFQajmhfKMQBzUGDdkMK7fUW7PTHTeLf+j87aTuKuuwWzMGw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -2320,9 +2320,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001777",
|
"version": "1.0.30001778",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001777.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001778.tgz",
|
||||||
"integrity": "sha512-tmN+fJxroPndC74efCdp12j+0rk0RHwV5Jwa1zWaFVyw2ZxAuPeG8ZgWC3Wz7uSjT3qMRQ5XHZ4COgQmsCMJAQ==",
|
"integrity": "sha512-PN7uxFL+ExFJO61aVmP1aIEG4i9whQd4eoSCebav62UwDyp5OHh06zN4jqKSMePVgxHifCw1QJxdRkA1Pisekg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -2577,9 +2577,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/electron-to-chromium": {
|
"node_modules/electron-to-chromium": {
|
||||||
"version": "1.5.307",
|
"version": "1.5.313",
|
||||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.307.tgz",
|
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.313.tgz",
|
||||||
"integrity": "sha512-5z3uFKBWjiNR44nFcYdkcXjKMbg5KXNdciu7mhTPo9tB7NbqSNP2sSnGR+fqknZSCwKkBN+oxiiajWs4dT6ORg==",
|
"integrity": "sha512-QBMrTWEf00GXZmJyx2lbYD45jpI3TUFnNIzJ5BBc8piGUDwMPa1GV6HJWTZVvY/eiN3fSopl7NRbgGp9sZ9LTA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
@@ -3471,10 +3471,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/flatted": {
|
"node_modules/flatted": {
|
||||||
"version": "3.2.9",
|
"version": "3.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz",
|
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz",
|
||||||
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
|
"integrity": "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/for-each": {
|
"node_modules/for-each": {
|
||||||
"version": "0.3.3",
|
"version": "0.3.3",
|
||||||
@@ -5736,9 +5737,9 @@
|
|||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/picomatch": {
|
"node_modules/picomatch": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz",
|
||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -6616,7 +6617,6 @@
|
|||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
|
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
|
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
|
||||||
}
|
}
|
||||||
@@ -6737,9 +6737,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
"node_modules/undici": {
|
||||||
"version": "6.23.0",
|
"version": "6.24.1",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.23.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-6.24.1.tgz",
|
||||||
"integrity": "sha512-VfQPToRA5FZs/qJxLIinmU59u0r7LXqoJkCzinq3ckNJp3vKEh7jTWN589YQ5+aoAC/TGRLyJLCPKcLQbM8r9g==",
|
"integrity": "sha512-sC+b0tB1whOCzbtlx20fx3WgCXwkW627p4EA9uM+/tNNPkSS+eSEld6pAs9nDv7WbY1UUljBMYPtu9BCOrCWKA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.17"
|
"node": ">=18.17"
|
||||||
|
|||||||
+5
-6
@@ -44,14 +44,13 @@ async function checkTofu () {
|
|||||||
setOutput('stderr', stderr.contents);
|
setOutput('stderr', stderr.contents);
|
||||||
setOutput('exitcode', exitCode.toString(10));
|
setOutput('exitcode', exitCode.toString(10));
|
||||||
|
|
||||||
if (exitCode === 0 || exitCode === 2) {
|
if (exitCode === 0) {
|
||||||
// A exitCode of 0 is considered a success
|
|
||||||
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
|
|
||||||
// is passed to plan. This denotes Success with non-empty
|
|
||||||
// diff (changes present).
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A non-zero exitCode is considered an error
|
// Any non-zero exitCode is treated as a failure, including exitCode 2 from
|
||||||
|
// `plan -detailed-exitcode` (success with a non-empty diff). Previously 2 was
|
||||||
|
// treated as success, but that hid the signal users opt into `-detailed-exitcode`
|
||||||
|
// to receive.
|
||||||
setFailed(`OpenTofu exited with code ${exitCode}.`);
|
setFailed(`OpenTofu exited with code ${exitCode}.`);
|
||||||
})();
|
})();
|
||||||
Reference in new issue
Block a user