Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Conversation

@JamesMGreene
Copy link
Contributor

@JamesMGreene JamesMGreene commented Oct 21, 2020

With the now open sourced github/docs, we have run into at least one situation where this Action arguably should've failed but did not. The situation was due to a misconfiguration on our part after we renamed our default branch from master to main but hadn't yet updated the branch name used in our Actions workflows.

Example failure: https://github.com/github/docs/runs/1123997453?check_suite_focus=true

image

This particular failure arose from the current line 36 in the entrypoint.sh script:

# Do not proceed if there are no file differences, this avoids PRs with just a merge commit and no content
LINES_CHANGED=$(git diff --name-only "$DESTINATION_BRANCH" "$SOURCE_BRANCH" | wc -l | awk '{print $1}')
if [[ "$LINES_CHANGED" = "0" ]] && [[ ! "$INPUT_PR_ALLOW_EMPTY" == "true" ]]; then
echo "No file changes detected between source and destination branches."
exit 0
fi

Having set -e enabled as you do is a great practice but there are often other options to consider adding, especially -o pipefail. Without it, failing exit codes from command that are piped into other commands do not cause the script to exit. 😭

From the Bash manual:

pipefail
If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.

cc @chiedo

@@ -1,6 +1,7 @@
#!/bin/sh
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -o pipefail is an option specific to Bash.

@wei wei self-requested a review October 21, 2020 22:51
Copy link
Member

@wei wei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@wei wei changed the title Enable pipe failure propagation through Bash feat: enable pipe failure propagation through Bash Oct 21, 2020
@wei wei merged commit c58b552 into repo-sync:master Oct 21, 2020
@wei
Copy link
Member

wei commented Oct 21, 2020

@allcontributors please add @JamesMGreene for code

@allcontributors
Copy link
Contributor

@wei

I've put up a pull request to add @JamesMGreene! πŸŽ‰

@wei
Copy link
Member

wei commented Oct 21, 2020

Thanks @JamesMGreene ! It's now accessible at repo-sync/[email protected] and repo-sync/pull-request@v2

@wei wei added the enhancement New feature or request label Oct 21, 2020
@JamesMGreene
Copy link
Contributor Author

Thanks for the quick turnaround! πŸŽ‰

@JamesMGreene JamesMGreene deleted the patch-1 branch October 21, 2020 23:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants