mirror of
https://github.com/stan220/flathub.git
synced 2026-09-08 18:29:08 +00:00
pr-check: Add automation to start build automatically and misc fixes
This commit is contained in:
@@ -40,23 +40,55 @@ jobs:
|
||||
fi
|
||||
|
||||
for PR_NUM in "${PR_NUMBERS[@]}"; do
|
||||
echo "Checking PR #$PR_NUM"
|
||||
echo "Checking PR https://github.com/flathub/flathub/pull/$PR_NUM"
|
||||
|
||||
json=$(gh pr view "$PR_NUM" --json body,title -q '{body: .body, title: .title}')
|
||||
PR_BODY=$(echo "$json" | jq -r .body)
|
||||
PR_TITLE=$(echo "$json" | jq -r .title)
|
||||
|
||||
unset $PR_TITLE
|
||||
unset "$PR_TITLE"
|
||||
export PR_TITLE="$PR_TITLE"
|
||||
|
||||
EXIT_CODE=$(curl -sSL "$SCRIPT_URL" | python3 | grep 'EXIT_CODE=' | cut -d= -f2)
|
||||
echo "EXIT_CODE is $EXIT_CODE"
|
||||
unset $PR_TITLE
|
||||
unset "$PR_TITLE"
|
||||
|
||||
PR_COMMENTS="$(gh pr view "$PR_NUM" --json comments -q '.comments[].body')"
|
||||
|
||||
PR_LABELS="$(gh pr view "$PR_NUM" --json labels -q '.labels[].name')"
|
||||
|
||||
BLOCKED=0
|
||||
|
||||
comment_exists() {
|
||||
gh pr view "$PR_NUM" --json comments -q '.comments[].body' | grep -Fq "$PART_COMMENT"
|
||||
local comment="$1"
|
||||
echo "$PR_COMMENTS" | grep -Fq "$comment"
|
||||
}
|
||||
|
||||
comment_exists_any() {
|
||||
for comment in "$@"; do
|
||||
if echo "$PR_COMMENTS" | grep -Fq "$comment"; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
label_exists_any() {
|
||||
for label in "$@"; do
|
||||
if echo "$PR_LABELS" | grep -Fq "$label"; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
start_build() {
|
||||
if ! label_exists_any "pr-check-blocked" "blocked"; then
|
||||
if ! comment_exists_any "$BUILD_START_COMMENT_PARTIAL" "$BUILD_ENQUEUED" "$BUILD_STARTED" "$BUILD_SUCCESS_COMMENT"; then
|
||||
echo "PR is not marked as blocked and none of the build comments exist. Starting a build"
|
||||
gh pr comment "$PR_NUM" --body "$BUILD_START_COMMENT"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$EXIT_CODE" -ne 0 ]; then
|
||||
@@ -77,35 +109,44 @@ jobs:
|
||||
BLOCKED=1
|
||||
fi
|
||||
|
||||
has_label=$(gh pr view "$PR_NUM" --json labels -q '.labels | any(.name == "awaiting-changes" or .name == "awaiting-upstream" or .name == "blocked")')
|
||||
|
||||
echo "BLOCKED is set to $BLOCKED"
|
||||
echo "Reviewed labels is set to $has_label"
|
||||
|
||||
if [ "$BLOCKED" -eq 0 ] && [ "$has_label" != "true" ]; then
|
||||
if [ "$BLOCKED" -eq 0 ] && ! label_exists_any "awaiting-changes" "awaiting-upstream" "blocked" "reviewed-waiting"; then
|
||||
echo "Marking as awaiting-review"
|
||||
gh pr edit "$PR_NUM" --add-label "awaiting-review" --remove-label "pr-check-blocked" || true
|
||||
start_build
|
||||
elif [ "$BLOCKED" -eq 1 ]; then
|
||||
echo "Marking as blocked"
|
||||
gh pr edit "$PR_NUM" --add-label "pr-check-blocked" --remove-label "awaiting-review"
|
||||
if ! comment_exists; then
|
||||
if ! comment_exists "$REVIEW_COMMENT_PARTIAL"; then
|
||||
echo "Did not find comment, commenting"
|
||||
gh pr comment "$PR_NUM" --body "$COMMENT"
|
||||
gh pr comment "$PR_NUM" --body "$REVIEW_COMMENT"
|
||||
else
|
||||
echo "Found comment, skipping commenting"
|
||||
fi
|
||||
else
|
||||
echo "Nothing to do"
|
||||
start_build
|
||||
fi
|
||||
done
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
SCRIPT_URL: https://raw.githubusercontent.com/flathub/flathub/refs/heads/master/.github/scripts/validate.py
|
||||
PART_COMMENT: "This pull request is temporarily marked as blocked as some"
|
||||
COMMENT: >
|
||||
BUILD_ENQUEUED: "Test build [enqueued]"
|
||||
BUILD_STARTED: "Started [test build]"
|
||||
BUILD_SUCCESS_COMMENT: "[Test build succeeded]"
|
||||
BUILD_START_COMMENT: |
|
||||
Starting a test build of the submission. Please fix any
|
||||
issues reported in the build log. You can restart the build
|
||||
once the issue is fixed by commenting the phrase below.
|
||||
|
||||
bot, build
|
||||
BUILD_START_COMMENT_PARTIAL: "Starting a test build of the submission"
|
||||
REVIEW_COMMENT: >
|
||||
This pull request is temporarily marked as blocked as some
|
||||
automated checks failed on it. Please make sure the pull
|
||||
request title is `Add $FLATPAK_ID` and that all
|
||||
[checklist items](https://github.com/flathub/flathub/blob/master/.github/pull_request_template.md)
|
||||
in the pull request body are marked as complete.
|
||||
REVIEW_COMMENT_PARTIAL: "This pull request is temporarily marked as blocked as some"
|
||||
|
||||
Reference in New Issue
Block a user