Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

How to run `git diff` to list changed files of git branch compared to main branch, on GitHub PR merge using GitHub Actions

I have a GitHub Actions config file that looks like this:

name: build
on:
  push:
    branches:
      - main
jobs:
  run:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 2
      - name: Configure Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 14.x
      - name: Install dependencies
        run: yarn install
      - name: Get git changes between branch and main branch
        run: node runmyscript.js

This will run when on merge of a PR to master. But the branch gets auto deleted, so how do you recommend I configure this so it can get the changed files of the branch to master?

It seems there is a race condition.

Basically, I need to run this right before it merges to master:

git diff --name-only master...branch

But it won't work because by this point of running, it is on the master branch and has merged. So it's a conundrum, what do I do?

Is there a way to create some global persistent cache of information available, like the last seen commit hash of the main branch before last merge, and then I can read that config/setting variable from the GitHub actions environment somehow, and then use that in my script to determine the two commit hashes to return the diff between against.

question from:https://stackoverflow.com/questions/65946777/how-to-run-git-diff-to-list-changed-files-of-git-branch-compared-to-main-branc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...