Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First deploy of branch fails #116

Open
micahjon opened this issue Feb 10, 2021 · 10 comments
Open

First deploy of branch fails #116

micahjon opened this issue Feb 10, 2021 · 10 comments

Comments

@micahjon
Copy link

micahjon commented Feb 10, 2021

Is this action supposed to work when deploying a new branch for the first time (ideally diffing against a different branch)? Or does it only compare commits within the same branch?

We're running into an issue where it fails every time we deploy a branch for the first time. Subsequent deploys to the same branch (which is no longer a new branch at that point) work just fine.

Thanks!

undefined Exception: { "error": "404/HttpError", "from": "undefined/Error", "message": "There was an error getting change files for repo:test-repo owner:test-owner base:0000000000000000000000000000000000000000 head:e966d6f2925816a0d97d45fa30b52840cfe3e79f", "payload": { "name": "HttpError", "status": 404, "headers": { "access-control-allow-origin": "*", "access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset", "connection": "close", "content-encoding": "gzip", "content-security-policy": "default-src 'none'", "content-type": "application/json; charset=utf-8", "date": "Wed, 10 Feb 2021 17:22:47 GMT", "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "server": "GitHub.com", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "transfer-encoding": "chunked", "vary": "Accept-Encoding, Accept, X-Requested-With", "x-content-type-options": "nosniff", "x-frame-options": "deny", "x-github-media-type": "github.v3; format=json", "x-github-request-id": "BBB8:50DF:1FD85:51579:60241667", "x-ratelimit-limit": "1000", "x-ratelimit-remaining": "999", "x-ratelimit-reset": "1612981367", "x-ratelimit-used": "1", "x-xss-protection": "1; mode=block" }, "request": { "method": "GET", "url": "https://api.github.com/repos/test-owner/test-repo/compare/0000000000000000000000000000000000000000...e966d6f2925816a0d97d45fa30b52840cfe3e79f", "headers": { "accept": "application/vnd.github.v3+json", "user-agent": "octokit.js/16.43.1 Node.js/12.13.1 (Linux 4.15; x64)", "authorization": "token [REDACTED]" }, "request": {} }, "documentation_url": "https://docs.github.com/rest/reference/repos#compare-two-commits" } }

@shaunaa126
Copy link

I see this exact same error too. Another action that does a similar thing also has the same behavior: jitterbit/get-changed-files#10

Any resolution to the issue?

@micahjon
Copy link
Author

micahjon commented Mar 3, 2021

@shaunaa126 , what we ended up doing is using git diff to get a list of all the files that been changed/added/removed. Not nearly as granular, but it will reliably diff any two commits.

name: Get changed files
id: getfile
run: |
  if [[ is_the_first_deployment ]]; then
      export DIFF=$( git diff --name-only origin/name-of-some-branch ${{ github.sha }} )
      echo "Diff between origin/name-of-some-branch and ${{ github.sha }} "
  else
      export DIFF=$( git diff --name-only ${{ github.event.before }} ${{ github.sha }} )
      echo "Diff between ${{ github.event.before }} and ${{ github.sha }} "
  fi

  echo "::set-output name=files::$( echo "$DIFF" | sed ':a;N;$!ba;s/\n/%0A/g' )"

How you set the is_the_first_deployment flag and branch name to diff off of is up to you. We have a unique use case where we can hard code the branch name.

Later on you can parse this string in JavaScript:

const allFiles = `${{ steps.getfile.outputs.files }}`
  .split('\n')
  .map(str => str.trim())
  .filter(Boolean);

@shaunaa126
Copy link

Thank you for this @micahjon

@z0ph
Copy link

z0ph commented Mar 26, 2021

Same error here.

@shaunaa126
Copy link

Same error here.

Switched to a working action: jitterbit/get-changed-files@v1

I also got the same error using that action as well: #116 (comment)

@z0ph
Copy link

z0ph commented Mar 30, 2021

Finally got the same error with commitid: 0000000000000000000000000000000000000000

@Jolg42
Copy link

Jolg42 commented Jan 13, 2022

I also got into this and was so confused because it was working on one project but not another one and I found out how to handle it:

It seems the source code is here https://github.com/jitterbit/get-changed-files/blob/master/src/main.ts#L28-L36
The code handles 2 different events from GitHub Actions push & pull_request.

  • When creating a new branch for a PR, push will be triggered immediately before the PR gets created
  • The GitHub API / GitHub context base commit is then 0000000000000000000000000000000000000000
  • The get-changed-files action needs to have a non 0/empty base commit to be able to diff
  • Defining both push (and specify the branches) and pull_request solves the problem
    Example
on:
  push:
    branches:
      # Push events our default branch
      - main
      # Push events to branches matching refs/heads/renovate/...
      - 'renovate/**'
  pull_request:
    paths-ignore:
      - '*.md'
      - 'renovate.json'

It makes sense to me as a new branch does not have a base / reference where it's from, it's "floating" around, it's when creating the PR that the base branch is selected.

A solution could be to always diff on the default branch, another could be to document this ⬆️

Originally posted by @Jolg42 in Ana06/get-changed-files#12 (comment)

davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
davorpa added a commit to davorpa/free-programming-books that referenced this issue Jan 15, 2022
This action fails on first commit for push events.

Apply some of proposals seen in their issue thread: trilom/file-changes-action#116
@davorpa
Copy link

davorpa commented Jan 17, 2022

I also got into this and was so confused because it was working on one project but not another one and I found out how to handle it:

It seems the source code is here jitterbit/get-changed-files@master/src/main.ts#L28-L36 The code handles 2 different events from GitHub Actions push & pull_request.

  • When creating a new branch for a PR, push will be triggered immediately before the PR gets created
  • The GitHub API / GitHub context base commit is then 0000000000000000000000000000000000000000
  • The get-changed-files action needs to have a non 0/empty base commit to be able to diff
  • Defining both push (and specify the branches) and pull_request solves the problem
    Example
on:
  push:
    branches:
      # Push events our default branch
      - main
      # Push events to branches matching refs/heads/renovate/...
      - 'renovate/**'
  pull_request:
    paths-ignore:
      - '*.md'
      - 'renovate.json'

It makes sense to me as a new branch does not have a base / reference where it's from, it's "floating" around, it's when creating the PR that the base branch is selected.

A solution could be to always diff on the default branch, another could be to document this arrow_up

Originally posted by @Jolg42 in Ana06/get-changed-files#12 (comment)

As you can see in test made above it doesn't work for me setting branches if any git feature workflows are adopted, especially if in you fork a repo and enable GitHub Actions

@Jolg42
Copy link

Jolg42 commented Jan 19, 2022

@davorpa I didn't check in detail, the problem might be similar but different here 🤔

I thought this trilom/file-changes-action was a fork of https://github.com/jitterbit/get-changed-files but it seems it's not.

I can recommend you to try out https://github.com/Ana06/get-changed-files, it's the one I'm currently using since a few months.

@adecchi-2inno
Copy link

Same error here. Any workaround ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants