diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml index 87a1667..39a0aa7 100644 --- a/.github/workflows/update.yaml +++ b/.github/workflows/update.yaml @@ -11,13 +11,15 @@ jobs: - name: Checkout current uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: - fetch-depth: ${{github.event_name == 'pull_request' && 2 || 0}} + # See https://stackoverflow.com/a/74268200 -- the PR branch has a single + # commit merging the two branches, so we need the last 2 commits. + fetch-depth: 2 - name: Checkout comparison branch (main) in subdirectory uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: - # Checkout the comparison branch (main) into a subdirectory - ref: main + # Checkout the comparison branch into a subdirectory + ref: ${{ github.event.pull_request.head.sha }} path: before_files - name: Set up Go @@ -30,25 +32,14 @@ jobs: # Fail the script if any command fails set -e - git branch -a - # Determine the current branch and compare branch (default to 'main') - GITHUB_BRANCH=remotes/${GITHUB_REF#*/} - COMPARE_BRANCH="main" - - git log - # Show changed files between the current branch and the comparison branch # See https://stackoverflow.com/a/74268200 for why diffing with HEAD^1 is used - echo "Comparing $GITHUB_BRANCH (from '$GITHUB_REF') with $COMPARE_BRANCH..." CHANGED_FILES=$(git diff --name-only -r HEAD^1 HEAD) - echo $CHANGED_FILES - echo ---- - git diff --name-only "$COMPARE_BRANCH" "$GITHUB_BRANCH" if [ -z "$CHANGED_FILES" ]; then echo "No changes found." else - echo "Files changed in branch $GITHUB_BRANCH (compared to $COMPARE_BRANCH):" + echo "Files changed in branch $GITHUB_REF (compared to base):" echo "$CHANGED_FILES" # Set the output to be used in later GitHub Action steps @@ -60,7 +51,7 @@ jobs: # Fail the script if any command fails set -e - go build -o ./mindev github.com/mindersec/minder/cmd/dev@latest + go install github.com/mindersec/minder/cmd/dev@latest # Loop through the changed files and run the go command for each for FILE in ${{ env.changed_files }}; do @@ -73,7 +64,7 @@ jobs: if [ -f "$BEFORE_FILE" ]; then echo "Running ruletype validate-update command for $BEFORE_FILE and $AFTER_FILE..." # Run the go command with the before and after files - ./mindev ruletype validate-update --before "$BEFORE_FILE" --after "$AFTER_FILE" + dev ruletype validate-update --before "$BEFORE_FILE" --after "$AFTER_FILE" else echo "Warning: $BEFORE_FILE does not exist, skipping." fi