Check FL ticket in PR name after merge (#2076)

* Add base
* Add base again
* Test reporting
* Fix reporting
* Fix secrets
* Fix arguments in report
* Remove depricated actions
* Disable reporting on PR

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Max Andreev 2022-12-10 16:10:51 +03:00 committed by GitHub
parent 7fb1af07b8
commit 9d728a1c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 130 additions and 41 deletions

View File

@ -39,7 +39,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}

View File

@ -24,7 +24,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
@ -35,6 +35,7 @@ jobs:
mkdir artifacts mkdir artifacts
- name: 'Get commit details' - name: 'Get commit details'
id: names
run: | run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull" TYPE="pull"
@ -45,14 +46,6 @@ jobs:
fi fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Generate suffixes for comment'
id: names
run: |
echo "::set-output name=branch_name::${BRANCH_NAME}"
echo "::set-output name=commit_sha::${COMMIT_SHA}"
echo "::set-output name=default_target::${DEFAULT_TARGET}"
echo "::set-output name=suffix::${SUFFIX}"
- name: 'Bundle scripts' - name: 'Bundle scripts'
if: ${{ !github.event.pull_request.head.repo.fork }} if: ${{ !github.event.pull_request.head.repo.fork }}
run: | run: |
@ -143,7 +136,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
submodules: true submodules: true

View File

@ -20,7 +20,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
@ -36,12 +36,12 @@ jobs:
BRANCHES=$(git branch -r --contains "$SUBMODULE_HASH"); BRANCHES=$(git branch -r --contains "$SUBMODULE_HASH");
COMMITS_IN_BRANCH="$(git rev-list --count dev)"; COMMITS_IN_BRANCH="$(git rev-list --count dev)";
if [ $COMMITS_IN_BRANCH -lt $SUB_COMMITS_MIN ]; then if [ $COMMITS_IN_BRANCH -lt $SUB_COMMITS_MIN ]; then
echo "::set-output name=fails::error"; echo "name=fails::error" >> $GITHUB_OUTPUT
echo "::error::Error: Too low commits in $SUB_BRANCH of submodule $SUB_PATH: $COMMITS_IN_BRANCH(expected $SUB_COMMITS_MIN+)"; echo "::error::Error: Too low commits in $SUB_BRANCH of submodule $SUB_PATH: $COMMITS_IN_BRANCH(expected $SUB_COMMITS_MIN+)";
exit 1; exit 1;
fi fi
if ! grep -q "/$SUB_BRANCH" <<< "$BRANCHES"; then if ! grep -q "/$SUB_BRANCH" <<< "$BRANCHES"; then
echo "::set-output name=fails::error"; echo "name=fails::error" >> $GITHUB_OUTPUT
echo "::error::Error: Submodule $SUB_PATH is not on branch $SUB_BRANCH"; echo "::error::Error: Submodule $SUB_PATH is not on branch $SUB_BRANCH";
exit 1; exit 1;
fi fi

View File

@ -23,7 +23,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}

View File

@ -20,7 +20,7 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}

41
.github/workflows/merge_report.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: 'Check FL ticket in PR name'
on:
push:
branches:
- dev
jobs:
merge_report:
runs-on: [self-hosted,FlipperZeroShell]
steps:
- name: 'Decontaminate previous build leftovers'
run: |
if [ -d .git ]; then
git submodule status || git checkout "$(git rev-list --max-parents=0 HEAD | tail -n 1)"
fi
- name: 'Checkout code'
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: 'Get commit details'
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull"
elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
TYPE="tag"
else
TYPE="other"
fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Check ticket and report'
run: |
FBT_TOOLCHAIN_PATH=/runner/_work source scripts/toolchain/fbtenv.sh
python3 -m pip install slack_sdk
python3 scripts/merge_report_qa.py \
${{ secrets.QA_REPORT_SLACK_TOKEN }} \
${{ secrets.QA_REPORT_SLACK_CHANNEL }}

View File

@ -25,12 +25,13 @@ jobs:
fi fi
- name: 'Checkout code' - name: 'Checkout code'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
- name: 'Get commit details' - name: 'Get commit details'
id: names
run: | run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull" TYPE="pull"
@ -41,15 +42,6 @@ jobs:
fi fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Generate suffixes for comment'
if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
id: names
run: |
echo "::set-output name=branch_name::${BRANCH_NAME}"
echo "::set-output name=commit_sha::${COMMIT_SHA}"
echo "::set-output name=default_target::${DEFAULT_TARGET}"
echo "::set-output name=suffix::${SUFFIX}"
- name: 'Make reports directory' - name: 'Make reports directory'
run: | run: |
rm -rf reports/ rm -rf reports/

View File

@ -12,7 +12,7 @@ jobs:
runs-on: [self-hosted, FlipperZeroTest] runs-on: [self-hosted, FlipperZeroTest]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}

View File

@ -77,28 +77,38 @@ def add_env(name, value, file):
print(f"{delimeter}", file=file) print(f"{delimeter}", file=file)
def add_envs(data, env_file, args): def add_set_output_var(name, value, file):
add_env("COMMIT_MSG", data["commit_comment"], env_file) print(f"{name}={value}", file=file)
add_env("COMMIT_HASH", data["commit_hash"], env_file)
add_env("COMMIT_SHA", data["commit_sha"], env_file)
add_env("SUFFIX", data["suffix"], env_file) def add_envs(data, gh_env_file, gh_out_file, args):
add_env("BRANCH_NAME", data["branch_name"], env_file) add_env("COMMIT_MSG", data["commit_comment"], gh_env_file)
add_env("DIST_SUFFIX", data["suffix"], env_file) add_env("COMMIT_HASH", data["commit_hash"], gh_env_file)
add_env("WORKFLOW_BRANCH_OR_TAG", data["branch_name"], env_file) add_env("COMMIT_SHA", data["commit_sha"], gh_env_file)
add_env("SUFFIX", data["suffix"], gh_env_file)
add_env("BRANCH_NAME", data["branch_name"], gh_env_file)
add_env("DIST_SUFFIX", data["suffix"], gh_env_file)
add_env("WORKFLOW_BRANCH_OR_TAG", data["branch_name"], gh_env_file)
add_set_output_var("branch_name", data["branch_name"], gh_out_file)
add_set_output_var("commit_sha", data["commit_sha"], gh_out_file)
add_set_output_var("default_target", os.getenv("DEFAULT_TARGET"), gh_out_file)
add_set_output_var("suffix", data["suffix"], gh_out_file)
if args.type == "pull": if args.type == "pull":
add_env("PULL_ID", data["pull_id"], env_file) add_env("PULL_ID", data["pull_id"], gh_env_file)
add_env("PULL_NAME", data["pull_name"], env_file) add_env("PULL_NAME", data["pull_name"], gh_env_file)
def main(): def main():
args = parse_args() args = parse_args()
event_file = open(args.event_file) event_file = open(args.event_file, "r")
event = json.load(event_file) event = json.load(event_file)
env_file = open(os.environ["GITHUB_ENV"], "a") gh_env_file = open(os.environ["GITHUB_ENV"], "a")
gh_out_file = open(os.environ["GITHUB_OUTPUT"], "a")
data = get_details(event, args) data = get_details(event, args)
add_envs(data, env_file, args) add_envs(data, gh_env_file, gh_out_file, args)
event_file.close() event_file.close()
env_file.close() gh_env_file.close()
gh_out_file.close()
if __name__ == "__main__": if __name__ == "__main__":

53
scripts/merge_report_qa.py Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python3
import os
import re
import sys
import argparse
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("slack_token")
parser.add_argument("slack_channel")
args = parser.parse_args()
return args
def checkCommitMessage(msg):
regex = re.compile(r"^'?\[FL-\d+\]")
if regex.match(msg):
return True
return False
def reportSlack(commit_hash, slack_token, slack_channel, message):
client = WebClient(token=slack_token)
try:
client.chat_postMessage(channel="#" + slack_channel, text=message)
except SlackApiError as e:
print(e)
sys.exit(1)
def main():
args = parse_args()
commit_msg = os.getenv("COMMIT_MSG")
commit_hash = os.getenv("COMMIT_HASH")
commit_sha = os.getenv("COMMIT_SHA")
commit_link = (
"<https://github.com/flipperdevices/flipperzero-firmware/commit/"
+ commit_hash
+ "|"
+ commit_sha
+ ">"
)
message = "Commit " + commit_link + " merged to dev without 'FL' ticket!"
if not checkCommitMessage(commit_msg):
reportSlack(commit_hash, args.slack_token, args.slack_channel, message)
if __name__ == "__main__":
main()