zentered / vercel-preview-url

GitHub Action to receive the deployment preview URL from Vercel
https://github.com/zentered/vercel-preview-url#readme
MIT License
27 stars 9 forks source link

Unexpected end of file #139

Closed GCyganek closed 1 year ago

GCyganek commented 1 year ago

Describe the bug Action throws error AxiosError: Unexpected end of file

Run zentered/vercel-preview-url@v1.1.3
  with:
    vercel_team_id: team_x
    vercel_project_id: prj_x
  env:
    VERCEL_TOKEN: ***
Retrieving deployment preview ...
Fetching from: https://api.vercel.com/v6/deployments?projectId=prj_x&teamId=team_x
AxiosError: unexpected end of file
    at Function.AxiosError.from (/home/runner/work/_actions/zentered/vercel-preview-url/v1.1.3/webpack:/vercel-preview-url/node_modules/.pnpm/axios@1.2.1/node_modules/axios/lib/defaults/index.js:137:1)
    at BrotliDecompress.handleStreamError (/home/runner/work/_actions/zentered/vercel-preview-url/v1.1.3/webpack:/vercel-preview-url/node_modules/.pnpm/axios@1.2.1/node_modules/axios/lib/core/Axios.js:26:1)
    at BrotliDecompress.emit (node:events:402:35)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'Z_BUF_ERROR',
  errno: -5,
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function], Blob: null },
    validateStatus: [Function: validateStatus],
    headers: AxiosHeaders {
      Accept: 'application/json, text/plain, */*',
      Authorization: '***',
Error: unexpected end of file
      'Content-Type': 'application/json',
      'User-Agent': 'axios/1.2.1',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    method: 'get',
    url: 'https://api.vercel.com/v6/deployments?projectId=prj_x&teamId=team_x',
    data: undefined
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'api.vercel.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'api.vercel.com',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: null,
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      write: [Function: writeAfterFIN],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 6,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 3746,
      [Symbol(kBytesWritten)]: 347,
      [Symbol(connect-options)]: [Object],
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'GET /v6/deployments?projectId=prj_x&teamId=team_x HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Authorization: ***' +
      'Content-Type: application/json\r\n' +
      'User-Agent: axios/1.2.1\r\n' +
      'Accept-Encoding: gzip, compress, deflate, br\r\n' +
      'Host: api.vercel.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/v6/deployments?projectId=prj_x&teamId=team_x',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 200,
      statusMessage: 'OK',
      client: [TLSSocket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://api.vercel.com/v6/deployments?projectId=prj_x&teamId=team_x',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 32,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'api.vercel.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://api.vercel.com/v6/deployments?projectId=prj_x&teamId=team_x',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      authorization: [Array],
      'content-type': [Array],
      'user-agent': [Array],
      'accept-encoding': [Array],
      host: [Array]
    }
  },
  cause: Error: unexpected end of file
      at BrotliDecoder.zlibOnError [as onerror] (node:zlib:190:17) {
    errno: -5,
    code: 'Z_BUF_ERROR'
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Create monorepo with multiple Vercel projects
  2. Try to run workflow with correct projectId, teamId and vercel token provided
  3. See error

Expected behavior Returned preview URL filtered using projectId and teamId

Additional context I've experimented a bit with your code in vercel.js file changing token, repo, branch and options into hardcoded values, replaced axios witch fetch, run it locally using node and it works fine. My teamId, projectId and token shouldn't be the case of the problem here then. Also, using v1.1.2 it throws Error: no deployments found with the same input data.

PatrickHeneise commented 1 year ago

Could you open a PR with the change from axios to fetch, let's see if that solves the issue.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.1.4 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

PatrickHeneise commented 1 year ago

Let me know if that worked.

GCyganek commented 1 year ago

@PatrickHeneise There is an error with ReferenceError: fetch is not defined probably caused by using node version lower than 18. I guess updating node version in package.json engines object should fix this.

PatrickHeneise commented 1 year ago

Unfortunately not. I didn't think of this as 18 has been LTS for such a long time, but the GitHub Actions runner only runs 12 and 16. I'll try node-fetch in the meantime.

PatrickHeneise commented 1 year ago

@GCyganek new version is deployed, let me know if you get a chance to test this.

GCyganek commented 1 year ago

Thank you for the changes. There are no errors anymore. Unfortunately it still does not work for me in terms of fetching the preview URL. I'm running out of ideas what could be wrong here, but I get "no deployments found" even though when I run locally exact same code, with the same vercel api url and token I get the preview that I want.

Run zentered/vercel-preview-url@v1.1.6
Retrieving deployment preview ...
Fetching from: https://api.vercel.com/v6/deployments?projectId=x&teamId=x
Error: []
Error: no deployments found
    at getDeploymentUrl (file:///home/runner/work/_actions/zentered/vercel-preview-url/v1.1.6/dist/index.js:11762:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at run (file:///home/runner/work/_actions/zentered/vercel-preview-url/v1.1.6/dist/index.js:11796:30)
Error: no deployments found

Do you see anything wrong with this usage?

(...)
jobs:
  vercel_url:
    name: Get Vercel URL
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: vercel-preview-url
        uses: zentered/vercel-preview-url@v1.1.6
        id: vercel_preview_url
        env:
          VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
        with:
          vercel_project_id: 'x'
          vercel_team_id: 'x'
      - name: Retrieve deployment URL
        run: "echo ${{ steps.vercel_preview_url.outputs.preview_url }}"

(...)
PatrickHeneise commented 1 year ago

the job seems fine. Can you run curl -v -H 'Accept: application/json' -H "Authorization: Bearer <YOUR_TOKEN>" https://api.vercel.com/v6/deployments and add the filters one after another to see what you get straight from the API?

GCyganek commented 1 year ago

I tested it like that before opening this issue and it worked fine, tested it again now and results are also correct

PatrickHeneise commented 1 year ago

🤔 I see that the error messages are the same for total deployments and matching deployments, so probably the first call works, but because of the log level, you don't see the message, and the filter fails. I changed the log level and message to be more concise. Only assumption that's left is that there's something wrong with the team id or project id. Have you tried without the team id, just project id?

GCyganek commented 1 year ago

Ohh changing log output helped me realize that there is no problem with the api call, but with the filters.

Run zentered/vercel-preview-url@v1.1.7

Retrieving deployment preview ...
Fetching from: https://api.vercel.com/v6/deployments?projectId=x&teamId=x
Found 20 deployments
Looking for matching deployments repoName/refs/pull/11335/merge
Found 0 matching builds
Error: []
Error: no matching deployments found, please check your filters
    at getDeploymentUrl (file:///home/runner/work/_actions/zentered/vercel-preview-url/v1.1.7/dist/index.js:11762:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at run (file:///home/runner/work/_actions/zentered/vercel-preview-url/v1.1.7/dist/index.js:11798:30)
Error: no matching deployments found, please check your filters

I think the problem is with the GITHUB_REF. It is refs/pull/11335/merge in my case when I run the workflow and that makes the action fail. I run it locally with the branch name instead ("chore/repo/changed-something") and changing it to refs/pull/11335/merge breaks the action

GCyganek commented 1 year ago
image

In my case its refs/pull, not refs/heads (which is deleted in index.js file). Maybe when it's refs/pull we should get branch name using some another github environment variable?

image image
PatrickHeneise commented 1 year ago

I didn't realize, since I primarily tested on the main branch, and unfortunately no-one bothered to open a PR to fix this :(

@dlip https://github.com/dlip/vercel-preview-url/commit/ba293753abbee6691674d8eeb79891f44be40cba @xxidbr9 https://github.com/xxidbr9/vercel-preview-url/commit/69a948cb59e2fe9dc8385101471995581f549275

Let me know if 1.1.8 resolves the issue.

GCyganek commented 1 year ago

It works! Thank you so much

PatrickHeneise commented 1 year ago

Now it doesn't work any more for regular branches, so I'll add one more fix that should cover both cases.

PatrickHeneise commented 1 year ago

Ok, I tested both cases and it seems to work. Thanks for reporting the issue.

smakosh commented 1 year ago

Worth updating the version on the README file to 1.1.9 @PatrickHeneise

PatrickHeneise commented 1 year ago

Thanks. GitHub needs to invent something here. The latest version can be found on the Marketplace "use latest version", but I'd also recommend to run dependabot on actions:

version: 2
updates:
  - package-ecosystem: github-actions
    directory: '/'
    schedule:
      interval: 'monthly'

Will update the readme and check if there's a better way than updating this sample all the time.