Skip to content

Commit f2bfb15

Browse files
authored
Merge pull request #8930 from dhalbert/improve-pr-merge-filenames
Fix build filenames for pr merges
2 parents e3c4b79 + 8932094 commit f2bfb15

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

.github/workflows/build-boards.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@ jobs:
3131
submodules: false
3232
show-progress: false
3333
fetch-depth: 1
34+
3435
- name: Set up python
3536
uses: actions/setup-python@v5
3637
with:
3738
python-version: 3.x
39+
3840
- name: Set up port
3941
id: set-up-port
4042
uses: ./.github/actions/deps/ports
4143
with:
4244
board: ${{ matrix.board }}
45+
4346
- name: Set up submodules
4447
id: set-up-submodules
4548
uses: ./.github/actions/deps/submodules
49+
4650
- name: Set up external
4751
uses: ./.github/actions/deps/external
4852
with:
@@ -68,18 +72,21 @@ jobs:
6872
6973
- name: Set up build failure matcher
7074
run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/workflows/match-build-fail.json"
75+
7176
- name: Build board
7277
run: python3 -u build_release_files.py
7378
working-directory: tools
7479
env:
7580
BOARDS: ${{ matrix.board }}
7681
PULL: ${{ github.event.number }}
82+
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
7783

7884
- name: Upload artifact
7985
uses: actions/upload-artifact@v4
8086
with:
8187
name: ${{ matrix.board }}
8288
path: bin/${{ matrix.board }}
89+
8390
- name: Upload to S3
8491
uses: ./.github/actions/upload_aws
8592
with:

tools/build_board_info.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import json
88
import os
9+
import re
910
import requests
1011
import subprocess
1112
import sys
@@ -76,19 +77,34 @@ def get_version_info():
7677

7778
if not version:
7879
# Get branch we are PR'ing into, if any.
79-
branch = os.environ.get("GITHUB_BASE_REF", "").strip().replace("/", "_")
80+
# Works for pull_request actions.
81+
branch = os.environ.get("GITHUB_BASE_REF", "")
82+
if not branch:
83+
# Works for push actions (usually a PR merge).
84+
branch = os.environ.get("GITHUB_REF_NAME", "")
8085
if not branch:
8186
branch = "no-branch"
87+
# replace slashes with underscores to prevent path subdirs.
88+
branch = branch.strip().replace("/", "_")
8289

8390
# Get PR number, if any
84-
pull_request_maybe = os.environ.get("PULL", "")
85-
if pull_request_maybe:
86-
pull_request_maybe = f"-PR{pull_request_maybe}"
91+
# PR jobs put the PR number in PULL.
92+
pull_request = os.environ.get("PULL", "")
93+
if not pull_request:
94+
# PR merge jobs put a commit message that includes the PR number in HEAD_COMMIT_MESSAGE.
95+
head_commit_message = os.environ.get("HEAD_COMMIT_MESSAGE", "")
96+
if head_commit_message:
97+
match = re.match(r"Merge pull request #(\d+) from", head_commit_message)
98+
if match:
99+
pull_request = match.group(1)
100+
101+
if pull_request:
102+
pull_request = f"-PR{pull_request}"
87103

88104
date_stamp = date.today().strftime("%Y%m%d")
89105
short_sha = sha[:7]
90106
# Example: 20231121-8.2.x-PR9876-123abcd
91-
version = f"{date_stamp}-{branch}{pull_request_maybe}-{short_sha}"
107+
version = f"{date_stamp}-{branch}{pull_request}-{short_sha}"
92108

93109
return sha, version
94110

0 commit comments

Comments
 (0)