Skip to content

Commit

Permalink
Check FL ticket in PR name after merge (flipperdevices#2076)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
drunkbatya and skotopes authored Dec 10, 2022
1 parent 7fb1af0 commit 9d728a1
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/amap_analyse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -35,6 +35,7 @@ jobs:
mkdir artifacts
- name: 'Get commit details'
id: names
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull"
Expand All @@ -45,14 +46,6 @@ jobs:
fi
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'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
Expand Down Expand Up @@ -143,7 +136,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check_submodules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -36,12 +36,12 @@ jobs:
BRANCHES=$(git branch -r --contains "$SUBMODULE_HASH");
COMMITS_IN_BRANCH="$(git rev-list --count dev)";
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+)";
exit 1;
fi
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";
exit 1;
fi
2 changes: 1 addition & 1 deletion .github/workflows/lint_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/merge_report.yml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 2 additions & 10 deletions .github/workflows/pvs_studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ jobs:
fi
- name: 'Checkout code'
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: 'Get commit details'
id: names
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull"
Expand All @@ -41,15 +42,6 @@ jobs:
fi
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'
run: |
rm -rf reports/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: [self-hosted, FlipperZeroTest]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
38 changes: 24 additions & 14 deletions scripts/get_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,38 @@ def add_env(name, value, file):
print(f"{delimeter}", file=file)


def add_envs(data, env_file, args):
add_env("COMMIT_MSG", data["commit_comment"], env_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)
add_env("BRANCH_NAME", data["branch_name"], env_file)
add_env("DIST_SUFFIX", data["suffix"], env_file)
add_env("WORKFLOW_BRANCH_OR_TAG", data["branch_name"], env_file)
def add_set_output_var(name, value, file):
print(f"{name}={value}", file=file)


def add_envs(data, gh_env_file, gh_out_file, args):
add_env("COMMIT_MSG", data["commit_comment"], gh_env_file)
add_env("COMMIT_HASH", data["commit_hash"], gh_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":
add_env("PULL_ID", data["pull_id"], env_file)
add_env("PULL_NAME", data["pull_name"], env_file)
add_env("PULL_ID", data["pull_id"], gh_env_file)
add_env("PULL_NAME", data["pull_name"], gh_env_file)


def main():
args = parse_args()
event_file = open(args.event_file)
event_file = open(args.event_file, "r")
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)
add_envs(data, env_file, args)
add_envs(data, gh_env_file, gh_out_file, args)
event_file.close()
env_file.close()
gh_env_file.close()
gh_out_file.close()


if __name__ == "__main__":
Expand Down
53 changes: 53 additions & 0 deletions scripts/merge_report_qa.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 9d728a1

Please sign in to comment.