-
This is part of the script we used on GitLab to get the list of migration files we want to run:
This generated us a list such as:
At the moment I can’t find a way to retrieve the list of files changes between the target branch and the source branch, during workflow run. |
Beta Was this translation helpful? Give feedback.
Replies: 17 comments
-
My colleague wrote a response in this thread, could you give their suggestion a try?
Please use below command to get the changed files in the push commit, please refer to this link for more details. git diff-tree --no-commit-id --name-only -r ${{ github.sha }} |
Beta Was this translation helpful? Give feedback.
-
I tried this Check pushed file changes with git diff-tree in GitHub Actions from the same thread because I need the list of changed files between multiple commits:
So, in this case, I’ll need the 3 SQL files from migration-1, 2, and 3. I’m obviously doing something wrong because I’m getting this message from the action: |
Beta Was this translation helpful? Give feedback.
-
That log looks like you try to analyze the repository without first running |
Beta Was this translation helpful? Give feedback.
-
Thanks, I definitely miss checkout here. My current workflow looks like this:
but the output is similar: EDIT |
Beta Was this translation helpful? Give feedback.
-
@airtower-luna @github-support I made some progress. What I’m missing here, why it doesn’t work with v2? 🤔 I dug into the v2 repo. Is that possible that when I first run the runner my host had no git installed, checkout@v2 downloaded git 2.17, and even if I installed 2.27 later, checkout still works with the old git? Switching back to v2 after v1 reports the same error like before. |
Beta Was this translation helpful? Give feedback.
-
Hi @akoskm, All of your steps are executed in container ‘my-container’ on self-hosted runner. Is the git initailized in the container? Typically the error is due to not found the .git dir, or lack of permission. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Edit I ended up removing the runner, switching between checkout v1 and checkout v2 bricked my work folder. I also removed the container section. After reinstalling the runner, checkout v1 was still thinking that I’m running v1, switching to v2 detected git 2.27 properly. In the meantime, I deleted manually everything from my work folder _work. Now I can run git commands during the workflow. @airtower-luna unfortunately, checkout in combination with fetch-depth, still returns the files changed in the current commit: while the list of changed files between the target branch and the current commit is the following: Original post below Summary
No, git (2.27) is initialized on the machine that hosts the self-hosted runner. When I remove the container I get other errors:
Would it help to uninstall the runner from the machine that hosts the self-hosted runner and reinstall it? |
Beta Was this translation helpful? Give feedback.
-
That makes sense, when given one commit ID The next problem will be to get the commit ID before the push. From looking at context documentation I think |
Beta Was this translation helpful? Give feedback.
-
Because I want to run the migrations only on branch
So the environment variable that was ready to use in GitLab CI
Thanks @github-support, @airtower-luna, @weide-zhou. 🙇♂️ |
Beta Was this translation helpful? Give feedback.
-
Disregard my previous answer, this doesn’t work. The workflow runs after I merge the PR into development.
So again, is there any way to know what was SHA of the branch before the merge happened? |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to somehow use:
to retrieve the list of changed files in a PR. Then I could filter those and grab the ones ending with .sql. This was I wouldn’t rely on SHAs. FYI I tried the solution mentioned here Get list of files on pull request merge and it didn’t work:
|
Beta Was this translation helpful? Give feedback.
-
Hi @akoskm, Please remove the jq code for your command firstly, make sure rest api(curl) command can get the pull request files content. Then follow the structure to add jq code to filter the filename. Acccording to the jq error, there should be some code error in your script. I confirmed the sample code works fine on my side. BTW, it’s recommened to check github context to get the sha…you wanted.
Thanks. |
Beta Was this translation helpful? Give feedback.
-
You’re right, I just made the following test: while in context I have:
This is clearly what I need, now I just have to find a way to get to Is there any difference these:
If I understand correctly all 3 would point to the latest commit in the branch. |
Beta Was this translation helpful? Give feedback.
-
Hi @akoskm, The three commands could be different, it depends on which event you used. If you use push event, GITHUB_SHA, HEAD, {{ github.event.after }} all points to the latest commit, they have same value. If you use pull request, they could be different: HEAD: same with GITHUB_SHA ${{ github.event.after }}: points to the latest commit on the compared(source) branch, not the fake merged branch. Different sha will output different file list, hence, please make sure you used the correct sha for the git diff command. Hope it clear and helpful! |
Beta Was this translation helpful? Give feedback.
-
Thanks @weide-zhou, is there are reason why context values set as environment variables are not being forwarded to my script? The syntax seems to be correct because
I can also see the values when I dump github context: |
Beta Was this translation helpful? Give feedback.
-
Hi @akoskm, Please use ${{ github.event.before }}, no s for event. |
Beta Was this translation helpful? Give feedback.
-
Thanks @weide-zhou for catching that typo. 😅 Works as expected: |
Beta Was this translation helpful? Give feedback.
You’re right, I just made the following test:
while in context I have:
This is clearly what I need, now I just have to find a way to get to
context.event.before/after
- I think it’s just${{ github.event.before }}
- and send those SHA to my script.Is there any difference these:
If I understand correctly all 3 would point to the latest…