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' - name: 'Get commit details'
run: | run: |
FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh
if [[ ${{ github.event_name }} == 'pull_request' ]]; then 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 else
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" TYPE="other"
fi fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Make artifacts directory' - name: 'Make artifacts directory'
run: | run: |

View File

@ -36,12 +36,14 @@ jobs:
- name: 'Get commit details' - name: 'Get commit details'
run: | run: |
FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh
if [[ ${{ github.event_name }} == 'pull_request' ]]; then 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 else
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" TYPE="other"
fi fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Generate suffixes for comment' - name: 'Generate suffixes for comment'
id: names id: names
@ -159,14 +161,14 @@ jobs:
- name: 'Get commit details' - name: 'Get commit details'
run: | run: |
FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh
if [[ ${{ github.event_name }} == 'pull_request' ]]; then 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 else
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" TYPE="other"
fi fi
echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_NAME}" >> $GITHUB_ENV python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
- name: 'Build the firmware' - name: 'Build the firmware'
run: | run: |

View File

@ -32,12 +32,14 @@ jobs:
- name: 'Get commit details' - name: 'Get commit details'
run: | run: |
FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh
if [[ ${{ github.event_name }} == 'pull_request' ]]; then 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 else
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" TYPE="other"
fi fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
- name: 'Generate suffixes for comment' - name: 'Generate suffixes for comment'
if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }} 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 = argparse.ArgumentParser()
parser.add_argument("--event_file", help="Current GitHub event file", required=True) parser.add_argument("--event_file", help="Current GitHub event file", required=True)
parser.add_argument( 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() args = parser.parse_args()
return args return args
@ -38,13 +41,17 @@ def get_commit_json(event):
def get_details(event, args): def get_details(event, args):
data = {} data = {}
current_time = datetime.datetime.utcnow().date() current_time = datetime.datetime.utcnow().date()
if args.is_pull: if args.type == "pull":
commit_json = get_commit_json(event) commit_json = get_commit_json(event)
data["commit_comment"] = shlex.quote(commit_json[-1]["commit"]["message"]) data["commit_comment"] = shlex.quote(commit_json[-1]["commit"]["message"])
data["commit_hash"] = commit_json[-1]["sha"] data["commit_hash"] = commit_json[-1]["sha"]
ref = event["pull_request"]["head"]["ref"] ref = event["pull_request"]["head"]["ref"]
data["pull_id"] = event["pull_request"]["number"] data["pull_id"] = event["pull_request"]["number"]
data["pull_name"] = shlex.quote(event["pull_request"]["title"]) 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: else:
data["commit_comment"] = shlex.quote(event["commits"][-1]["message"]) data["commit_comment"] = shlex.quote(event["commits"][-1]["message"])
data["commit_hash"] = event["commits"][-1]["id"] 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("BRANCH_NAME", data["branch_name"], env_file)
add_env("DIST_SUFFIX", data["suffix"], env_file) add_env("DIST_SUFFIX", data["suffix"], env_file)
add_env("WORKFLOW_BRANCH_OR_TAG", data["branch_name"], 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_ID", data["pull_id"], env_file)
add_env("PULL_NAME", data["pull_name"], env_file) add_env("PULL_NAME", data["pull_name"], env_file)