mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 08:41:02 -05:00
fix: fix GITHUB_BEFORE_SHA diff on push events (#5096)
- Fix GITHUB_BEFORE_SHA initialization on push events by setting the correct key. - Add an additional check against setting GITHUB_BEFORE_SHA to null. - Run the CI workflow on push events to trigger required status checks when using the merge queue.
This commit is contained in:
parent
4fca3cf28f
commit
1d5ed2c386
5 changed files with 39 additions and 33 deletions
21
.github/pull_request-template.md
vendored
21
.github/pull_request-template.md
vendored
|
@ -1,19 +1,8 @@
|
||||||
<!-- Start: issue fix section -->
|
# Proposed changes
|
||||||
<!-- Link to issue if there is one, otherwise remove the "issue fix" section -->
|
|
||||||
<!-- markdownlint-disable -->
|
|
||||||
|
|
||||||
Fixes #
|
_describe the proposed changes and remove this template text_
|
||||||
|
|
||||||
<!-- markdownlint-restore -->
|
## Readiness checklist
|
||||||
<!-- End: issue fix section -->
|
|
||||||
|
|
||||||
## Proposed Changes
|
|
||||||
|
|
||||||
- ...
|
|
||||||
- ...
|
|
||||||
- ...
|
|
||||||
|
|
||||||
## Readiness Checklist
|
|
||||||
|
|
||||||
In order to have this pull request merged, complete the following tasks.
|
In order to have this pull request merged, complete the following tasks.
|
||||||
|
|
||||||
|
@ -23,7 +12,9 @@ In order to have this pull request merged, complete the following tasks.
|
||||||
- [ ] I provided the necessary tests.
|
- [ ] I provided the necessary tests.
|
||||||
- [ ] I squashed all the commits into a single commit.
|
- [ ] I squashed all the commits into a single commit.
|
||||||
- [ ] I followed the [Conventional Commit v1.0.0 spec](https://www.conventionalcommits.org/en/v1.0.0/).
|
- [ ] I followed the [Conventional Commit v1.0.0 spec](https://www.conventionalcommits.org/en/v1.0.0/).
|
||||||
- [ ] If this is a breaking change, write upgrade instructions in the [upgrade guide](../docs/upgrade-guide.md).
|
- [ ] I wrote the necessary upgrade instructions in the [upgrade guide](../docs/upgrade-guide.md).
|
||||||
|
- [ ] If this pull request is about and existing issue,
|
||||||
|
I added the `Fix #ISSUE_NUMBER` label to the description of the pull request.
|
||||||
|
|
||||||
### Super-linter maintainer tasks
|
### Super-linter maintainer tasks
|
||||||
|
|
||||||
|
|
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
|
@ -2,6 +2,7 @@ name: Build and Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
push:
|
||||||
merge_group:
|
merge_group:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,10 @@ To run super-linter as a GitHub Action, you do the following:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# super-linter needs the full git history to get the
|
||||||
|
# list of files that changed across commits
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Super-linter
|
- name: Super-linter
|
||||||
uses: super-linter/super-linter@v5.7.2 # x-release-please-version
|
uses: super-linter/super-linter@v5.7.2 # x-release-please-version
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
function IssueHintForFullGitHistory() {
|
function IssueHintForFullGitHistory() {
|
||||||
info "Check that you have the full git history, the checkout is not shallow, etc"
|
info "Check that the local repository has the full history and that the repository is not shallow."
|
||||||
|
info "See https://github.com/super-linter/super-linter#get-started"
|
||||||
info "Is shallow repository: $(git -C "${GITHUB_WORKSPACE}" rev-parse --is-shallow-repository)"
|
info "Is shallow repository: $(git -C "${GITHUB_WORKSPACE}" rev-parse --is-shallow-repository)"
|
||||||
info "See https://github.com/super-linter/super-linter#example-connecting-github-action-workflow"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function GenerateFileDiff() {
|
function GenerateFileDiff() {
|
||||||
|
|
|
@ -519,21 +519,23 @@ GetGitHubVars() {
|
||||||
debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions"
|
debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions"
|
||||||
else
|
else
|
||||||
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
||||||
error "Failed to get [GITHUB_WORKSPACE]!"
|
fatal "Failed to get GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
|
||||||
fatal "[${GITHUB_WORKSPACE}]"
|
|
||||||
else
|
else
|
||||||
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
|
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ensure that Git can access the local repository
|
||||||
|
ConfigureGitSafeDirectories
|
||||||
|
|
||||||
if [ -z "${GITHUB_EVENT_PATH}" ]; then
|
if [ -z "${GITHUB_EVENT_PATH}" ]; then
|
||||||
error "Failed to get [GITHUB_EVENT_PATH]!"
|
fatal "Failed to get GITHUB_EVENT_PATH: ${GITHUB_EVENT_PATH}]"
|
||||||
fatal "[${GITHUB_EVENT_PATH}]"
|
|
||||||
else
|
else
|
||||||
info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}"
|
info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}"
|
||||||
|
debug "${GITHUB_EVENT_PATH} contents: $(cat "${GITHUB_EVENT_PATH}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${GITHUB_SHA}" ]; then
|
if [ -z "${GITHUB_SHA}" ]; then
|
||||||
fatal "Failed to get the value for the GITHUB_SHA variable [${GITHUB_SHA}]"
|
fatal "Failed to get GITHUB_SHA: ${GITHUB_SHA}"
|
||||||
else
|
else
|
||||||
info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]"
|
info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]"
|
||||||
fi
|
fi
|
||||||
|
@ -542,38 +544,46 @@ GetGitHubVars() {
|
||||||
# Need to pull the GitHub Vars from the env file #
|
# Need to pull the GitHub Vars from the env file #
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
######################
|
|
||||||
# Get the GitHub Org #
|
|
||||||
######################
|
|
||||||
GITHUB_ORG=$(jq -r '.repository.owner.login' <"${GITHUB_EVENT_PATH}")
|
GITHUB_ORG=$(jq -r '.repository.owner.login' <"${GITHUB_EVENT_PATH}")
|
||||||
|
|
||||||
########################
|
|
||||||
# Fix SHA for PR event #
|
|
||||||
########################
|
|
||||||
# Github sha on PR events is not the latest commit.
|
# Github sha on PR events is not the latest commit.
|
||||||
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
|
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
|
||||||
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
|
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
|
||||||
debug "This is a GitHub pull request. Updating the current GITHUB_SHA (${GITHUB_SHA}) to the pull request HEAD sha"
|
debug "This is a GitHub pull request. Updating the current GITHUB_SHA (${GITHUB_SHA}) to the pull request HEAD SHA"
|
||||||
GITHUB_SHA=$(jq -r .pull_request.head.sha <"$GITHUB_EVENT_PATH")
|
GITHUB_SHA=$(jq -r .pull_request.head.sha <"$GITHUB_EVENT_PATH")
|
||||||
ERROR_CODE=$?
|
ERROR_CODE=$?
|
||||||
debug "GITHUB_SHA update error code: ${ERROR_CODE}"
|
debug "GITHUB_SHA update error code: ${ERROR_CODE}"
|
||||||
|
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||||
error "Failed to update GITHUB_SHA for pull request event."
|
fatal "Failed to update GITHUB_SHA for pull request event: ${GITHUB_SHA}"
|
||||||
fatal "[Output: ${GITHUB_SHA}]"
|
|
||||||
fi
|
fi
|
||||||
debug "Updated GITHUB_SHA: ${GITHUB_SHA}"
|
debug "Updated GITHUB_SHA: ${GITHUB_SHA}"
|
||||||
elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
|
elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
|
||||||
debug "This is a GitHub push event."
|
debug "This is a GitHub push event."
|
||||||
|
|
||||||
GITHUB_BEFORE_SHA=$(jq -r .push.before <"$GITHUB_EVENT_PATH")
|
GITHUB_IS_FORCE_PUSH="$(jq -r .forced <"$GITHUB_EVENT_PATH")"
|
||||||
|
ERROR_CODE=$?
|
||||||
|
debug "GITHUB_IS_FORCE_PUSH initialization error code: ${ERROR_CODE}"
|
||||||
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||||
|
fatal "Failed to initialize GITHUB_IS_FORCE_PUSH for a push event. Output: ${GITHUB_IS_FORCE_PUSH}"
|
||||||
|
else
|
||||||
|
debug "Initialized GITHUB_IS_FORCE_PUSH: ${GITHUB_IS_FORCE_PUSH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${GITHUB_IS_FORCE_PUSH}" == "true" ]; then
|
||||||
|
debug "This is a forced push. Get the hash of the previous commit from Git because the previous commit referenced in the GitHub event payload may not exist anymore"
|
||||||
|
GITHUB_BEFORE_SHA=$(git -C "${GITHUB_WORKSPACE}" rev-parse HEAD^)
|
||||||
|
else
|
||||||
|
debug "This isn't a forced push. Get the hash of the previous commit from the GitHub event that triggered this workflow"
|
||||||
|
GITHUB_BEFORE_SHA=$(jq -r .before <"$GITHUB_EVENT_PATH")
|
||||||
|
fi
|
||||||
ERROR_CODE=$?
|
ERROR_CODE=$?
|
||||||
debug "GITHUB_BEFORE_SHA initialization error code: ${ERROR_CODE}"
|
debug "GITHUB_BEFORE_SHA initialization error code: ${ERROR_CODE}"
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||||
fatal "Failed to initialize GITHUB_BEFORE_SHA for a push event. Output: ${GITHUB_BEFORE_SHA}"
|
fatal "Failed to initialize GITHUB_BEFORE_SHA for a push event. Output: ${GITHUB_BEFORE_SHA}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${GITHUB_BEFORE_SHA}" ]; then
|
if [ -z "${GITHUB_BEFORE_SHA}" ] || [ "${GITHUB_BEFORE_SHA}" == "null" ]; then
|
||||||
fatal "Failed to get GITHUB_BEFORE_SHA: [${GITHUB_BEFORE_SHA}]"
|
fatal "Failed to get GITHUB_BEFORE_SHA: [${GITHUB_BEFORE_SHA}]"
|
||||||
else
|
else
|
||||||
info "Successfully found:${F[W]}[GITHUB_BEFORE_SHA]${F[B]}, value:${F[W]}[${GITHUB_BEFORE_SHA}]"
|
info "Successfully found:${F[W]}[GITHUB_BEFORE_SHA]${F[B]}, value:${F[W]}[${GITHUB_BEFORE_SHA}]"
|
||||||
|
|
Loading…
Reference in a new issue