mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Fix list-components when PR is not targeting dev (#6375)
This commit is contained in:
parent
a5553827f1
commit
4de58559c6
3 changed files with 22 additions and 8 deletions
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
|
@ -398,6 +398,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- common
|
- common
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
outputs:
|
outputs:
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -406,10 +407,14 @@ jobs:
|
||||||
with:
|
with:
|
||||||
# Fetch enough history so `git merge-base refs/remotes/origin/dev HEAD` works.
|
# Fetch enough history so `git merge-base refs/remotes/origin/dev HEAD` works.
|
||||||
fetch-depth: 500
|
fetch-depth: 500
|
||||||
- name: Fetch dev branch
|
- name: Get target branch
|
||||||
|
id: target-branch
|
||||||
run: |
|
run: |
|
||||||
git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/dev*:refs/remotes/origin/dev* +refs/tags/dev*:refs/tags/dev*
|
echo "branch=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
|
||||||
git merge-base refs/remotes/origin/dev HEAD
|
- name: Fetch ${{ steps.target-branch.outputs.branch }} branch
|
||||||
|
run: |
|
||||||
|
git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/${{ steps.target-branch.outputs.branch }}:refs/remotes/origin/${{ steps.target-branch.outputs.branch }}
|
||||||
|
git merge-base refs/remotes/origin/${{ steps.target-branch.outputs.branch }} HEAD
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
|
@ -419,7 +424,7 @@ jobs:
|
||||||
id: set-matrix
|
id: set-matrix
|
||||||
run: |
|
run: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
echo "matrix=$(script/list-components.py --changed | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
echo "matrix=$(script/list-components.py --changed --branch ${{ steps.target-branch.outputs.branch }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
test-build-components:
|
test-build-components:
|
||||||
name: Component test ${{ matrix.file }}
|
name: Component test ${{ matrix.file }}
|
||||||
|
@ -427,7 +432,7 @@ jobs:
|
||||||
needs:
|
needs:
|
||||||
- common
|
- common
|
||||||
- list-components
|
- list-components
|
||||||
if: ${{ needs.list-components.outputs.matrix != '[]' && needs.list-components.outputs.matrix != '' }}
|
if: ${{ github.event_name == 'pull_request' && needs.list-components.outputs.matrix != '[]' && needs.list-components.outputs.matrix != '' }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 2
|
max-parallel: 2
|
||||||
|
|
|
@ -70,11 +70,11 @@ def splitlines_no_ends(string):
|
||||||
return [s.strip() for s in string.splitlines()]
|
return [s.strip() for s in string.splitlines()]
|
||||||
|
|
||||||
|
|
||||||
def changed_files():
|
def changed_files(branch="dev"):
|
||||||
check_remotes = ["upstream", "origin"]
|
check_remotes = ["upstream", "origin"]
|
||||||
check_remotes.extend(splitlines_no_ends(get_output("git", "remote")))
|
check_remotes.extend(splitlines_no_ends(get_output("git", "remote")))
|
||||||
for remote in check_remotes:
|
for remote in check_remotes:
|
||||||
command = ["git", "merge-base", f"refs/remotes/{remote}/dev", "HEAD"]
|
command = ["git", "merge-base", f"refs/remotes/{remote}/{branch}", "HEAD"]
|
||||||
try:
|
try:
|
||||||
merge_base = splitlines_no_ends(get_output(*command))[0]
|
merge_base = splitlines_no_ends(get_output(*command))[0]
|
||||||
break
|
break
|
||||||
|
|
|
@ -120,12 +120,21 @@ def main():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-c", "--changed", action="store_true", help="Only run on changed files"
|
"-c", "--changed", action="store_true", help="Only run on changed files"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-b", "--branch", help="Branch to compare changed files against"
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.branch and not args.changed:
|
||||||
|
parser.error("--branch requires --changed")
|
||||||
|
|
||||||
files = git_ls_files()
|
files = git_ls_files()
|
||||||
files = filter(filter_component_files, files)
|
files = filter(filter_component_files, files)
|
||||||
|
|
||||||
if args.changed:
|
if args.changed:
|
||||||
|
if args.branch:
|
||||||
|
changed = changed_files(args.branch)
|
||||||
|
else:
|
||||||
changed = changed_files()
|
changed = changed_files()
|
||||||
files = [f for f in files if f in changed]
|
files = [f for f in files if f in changed]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue