Fix CI/CD in tags #1703

This commit is contained in:
Max Andreev 2022-09-05 16:40:54 +03:00 committed by GitHub
parent 8d8481b17f
commit b7a6d18186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 17 deletions

View File

@ -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: |

View File

@ -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: |

View File

@ -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 }}

View File

@ -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)