diff --git a/.github/workflows/amap_analyse.yml b/.github/workflows/amap_analyse.yml index 36352978..6be99c9d 100644 --- a/.github/workflows/amap_analyse.yml +++ b/.github/workflows/amap_analyse.yml @@ -46,12 +46,14 @@ jobs: - name: 'Get commit details' run: | - FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh if [[ ${{ github.event_name }} == 'pull_request' ]]; then - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--is_pull" + TYPE="pull" + elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + TYPE="tag" else - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" + TYPE="other" fi + python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" - name: 'Make artifacts directory' run: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 530bbc9e..15b3966a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,12 +36,14 @@ jobs: - name: 'Get commit details' run: | - FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh if [[ ${{ github.event_name }} == 'pull_request' ]]; then - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--is_pull" + TYPE="pull" + elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + TYPE="tag" else - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" + TYPE="other" fi + python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" - name: 'Generate suffixes for comment' id: names @@ -159,14 +161,14 @@ jobs: - name: 'Get commit details' run: | - FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh if [[ ${{ github.event_name }} == 'pull_request' ]]; then - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--is_pull" + TYPE="pull" + elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + TYPE="tag" else - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" + TYPE="other" fi - echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_NAME}" >> $GITHUB_ENV - echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV + python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" - name: 'Build the firmware' run: | diff --git a/.github/workflows/pvs_studio.yml b/.github/workflows/pvs_studio.yml index 8ace58b6..7bd71de4 100644 --- a/.github/workflows/pvs_studio.yml +++ b/.github/workflows/pvs_studio.yml @@ -32,12 +32,14 @@ jobs: - name: 'Get commit details' run: | - FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh if [[ ${{ github.event_name }} == 'pull_request' ]]; then - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--is_pull" + TYPE="pull" + elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + TYPE="tag" else - python3 scripts/get_env.py "--event_file=${{ github.event_path }}" + TYPE="other" 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 }} diff --git a/scripts/get_env.py b/scripts/get_env.py index 843a1e40..d0527309 100644 --- a/scripts/get_env.py +++ b/scripts/get_env.py @@ -20,7 +20,10 @@ def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--event_file", help="Current GitHub event file", required=True) parser.add_argument( - "--is_pull", help="Is it Pull Request", default=False, action="store_true" + "--type", + help="Event file type", + required=True, + choices=["pull", "tag", "other"], ) args = parser.parse_args() return args @@ -38,13 +41,17 @@ def get_commit_json(event): def get_details(event, args): data = {} current_time = datetime.datetime.utcnow().date() - if args.is_pull: + if args.type == "pull": commit_json = get_commit_json(event) data["commit_comment"] = shlex.quote(commit_json[-1]["commit"]["message"]) data["commit_hash"] = commit_json[-1]["sha"] ref = event["pull_request"]["head"]["ref"] data["pull_id"] = event["pull_request"]["number"] data["pull_name"] = shlex.quote(event["pull_request"]["title"]) + elif args.type == "tag": + data["commit_comment"] = shlex.quote(event["head_commit"]["message"]) + data["commit_hash"] = event["head_commit"]["id"] + ref = event["ref"] else: data["commit_comment"] = shlex.quote(event["commits"][-1]["message"]) data["commit_hash"] = event["commits"][-1]["id"] @@ -78,7 +85,7 @@ def add_envs(data, env_file, args): 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) - if args.is_pull: + if args.type == "pull": add_env("PULL_ID", data["pull_id"], env_file) add_env("PULL_NAME", data["pull_name"], env_file)