Commit 3e3d09c9 authored by uxwlu's avatar uxwlu Committed by uxrog
Browse files

Introduce Flammenwehrfer

parent 5db51ab9
......@@ -12,6 +12,7 @@ gruppen:
stage: run
only:
- merge_requests
- master
# Cache dependencies
cache:
......@@ -46,6 +47,6 @@ gruppen:
- ln -s "$PWD" "/mjtest/tests"
- export AUTH="$FLAMMENWEHRFER_AUTH"
- export USE_FLAMMENWEHRFER="$USE_FLAMMENWEHRFER"
- /mjtest/mjt.py lexer /compiler-under-test/run
- ./flammenwehrfer.sh
tags:
- alive
#!/bin/bash
# _ _
# | | | |___ __ _ __ _ ___
# | | | / __|/ _` |/ _` |/ _ \
# | |_| \__ \ (_| | (_| | __/
# \___/|___/\__,_|\__, |\___|
# |___/
if [[ "$GITHUB_PATH" == "" ]] || [[ "$AUTH" == "" ]]; then
echo "GITHUB_PATH ('user/repo') and AUTH ('user:PAT') env vars must be set"
exit 1
fi
# ____ _ _
# / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
# | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
# | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
# \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
#
BODY="Greetings traveller,\n\nsticks and stones won't break your bones but https://git.scc.kit.edu/IPDSnelting/mjtest-tests broke your compiler :(\n\nHave fun and take good care of it :lady_beetle:"
GITHUB_URL="https://api.github.com/repos/$GITHUB_PATH"
# _____ _ _
# |_ _|__ ___| |_(_)_ __ __ _
# | |/ _ \/ __| __| | '_ \ / _` |
# | | __/\__ \ |_| | | | | (_| | _ _ _
# |_|\___||___/\__|_|_| |_|\__, | (_) (_) (_)
# |___/
MJ_OUTPUT="$(/mjtest/mjt.py lexer /compiler-under-test/run 2>&1)"
MJ_EXIT_CODE="$?"
if [[ "$USE_FLAMMENWEHRFER" != 1 ]] || [[ "$CI_COMMIT_BRANCH" != "master" ]]; then
echo "Flammenwehrfer disabled, checked for branch '$CI_COMMIT_BRANCH'"
echo -e "Output: $MJ_OUTPUT"
exit $MJ_EXIT_CODE
fi
# ____ _ _
# | _ \ ___ _ __ ___ ___| |_ __ _| |_ ___
# | |_) / _ \ '_ \ / _ \ / __| __/ _` | __/ _ \
# | _ < __/ |_) | (_) | \__ \ || (_| | || __/
# |_| \_\___| .__/ \___/ |___/\__\__,_|\__\___|
# |_|
FETCHED_ISSUES="$(curl -Ss \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$GITHUB_PATH/issues\?creator\=Flammenwehrfer\&state\=all)"
ISSUE_COUNT="$(echo "$FETCHED_ISSUES" | jq "length")"
echo "Found $ISSUE_COUNT Github issue(s)"
# ____
# / ___| _ _ ___ ___ ___ ___ ___
# \___ \| | | |/ __/ __/ _ \/ __/ __|
# ___) | |_| | (_| (_| __/\__ \__ \
# |____/ \__,_|\___\___\___||___/___/
#
if [[ "$MJ_EXIT_CODE" == "0" ]]; then
echo "Test successful"
if [[ "$ISSUE_COUNT" > 0 ]] && [[ "$(echo "$FETCHED_ISSUES" | jq ".[0].state")" == '"open"' ]]; then
ISSUE_NUMBER="$(echo "$FETCHED_ISSUES" | jq ".[0].number")"
echo "Closing issue $ISSUE_NUMBER!"
curl -Ss \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-u "$AUTH" \
"$GITHUB_URL/issues/$ISSUE_NUMBER" \
-d '{"state":"closed"}' \
-o /dev/null
fi
exit 0
fi
# _____ _ _
# | ___|_ _(_) |_ _ _ __ ___
# | |_ / _` | | | | | | '__/ _ \
# | _| (_| | | | |_| | | | __/
# |_| \__,_|_|_|\__,_|_| \___|
#
echo "Test failed"
CODE_BLOCK_HEADER='```'
BODY="$BODY\n\n----\n\n<details>\n<summary>mjtest output</summary>\n\n$CODE_BLOCK_HEADER\n$MJ_OUTPUT\n$CODE_BLOCK_HEADER\n\n</details>"
if [[ "$ISSUE_COUNT" == "0" ]]; then
echo "Found no issues, creating new one"
# Create new issue
JSON="
{
\"title\": \"Failing test detected\",
\"body\" : $(echo -e "$BODY" | jq -R -s),
\"labels\": [\"test-failure-bot\"]
}
"
curl -Ss \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-u "$AUTH" \
"$GITHUB_URL/issues" \
-d "$JSON" \
-o /dev/null
exit 0
fi
ISSUE_NUMBER="$(echo "$FETCHED_ISSUES" | jq ".[0].number")"
echo "Commenting on issue $ISSUE_NUMBER"
curl -Ss \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-u "$AUTH" \
"$GITHUB_URL/issues/$ISSUE_NUMBER" \
-d '{"state":"open"}' \
-o /dev/null
curl -Ss \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-u "$AUTH" \
"$GITHUB_URL/issues/$ISSUE_NUMBER/comments" \
-d "{\"body\":$(echo -e "$BODY" | jq -R -s)}" \
-o /dev/null
exit $MJ_EXIT_CODE
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment