Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stm32g4_flash
Browse files Browse the repository at this point in the history
  • Loading branch information
kywwilson11 committed Oct 7, 2024
2 parents 377916c + 79be76a commit 507df45
Show file tree
Hide file tree
Showing 158 changed files with 2,976 additions and 3,224 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/arch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Identify the Arch for the PR and select the applicable builds
name: Arch

on:
workflow_call:
inputs:
os:
description: "Operating System hosting the build: Linux, macOS or msys2"
required: true
type: string
boards:
description: "List of All Builds: [arm-01, risc-v-01, xtensa-01, ...]"
required: true
type: string
outputs:
skip_all_builds:
description: "Set to 1 if all builds should be skipped"
value: ${{ jobs.Select-Builds.outputs.skip_all_builds }}
selected_builds:
description: "Selected Builds for the PR: [arm-01, risc-v-01, xtensa-01, ...]"
value: ${{ jobs.Select-Builds.outputs.selected_builds }}

jobs:
Select-Builds:
runs-on: ubuntu-latest

outputs:
skip_all_builds: ${{ steps.select-builds.outputs.skip_all_builds }}
selected_builds: ${{ steps.select-builds.outputs.selected_builds }}

steps:

# Get the Arch for the PR: arm, arm64, risc-v, xtensa, ...
- name: Get arch
id: get-arch
run: |
# If PR is Not Created or Modified: Build all targets
pr=${{github.event.pull_request.number}}
if [[ "$pr" == "" ]]; then
exit
fi
# Get the Labels for the PR: "Arch: risc-v \n Size: XS"
# If GitHub CLI Fails: Build all targets
labels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq '.labels[] | .name' || echo "")
numlabels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq '.[] | length' || echo "")
echo "numlabels=$numlabels" | tee -a $GITHUB_OUTPUT
# Identify the Size and Arch Labels
if [[ "$labels" == *"Size: "* ]]; then
echo 'labels_contain_size=1' | tee -a $GITHUB_OUTPUT
fi
if [[ "$labels" == *"Arch: arm64"* ]]; then
echo 'arch_contains_arm64=1' | tee -a $GITHUB_OUTPUT
elif [[ "$labels" == *"Arch: arm"* ]]; then
echo 'arch_contains_arm=1' | tee -a $GITHUB_OUTPUT
elif [[ "$labels" == *"Arch: risc-v"* ]]; then
echo 'arch_contains_riscv=1' | tee -a $GITHUB_OUTPUT
elif [[ "$labels" == *"Arch: simulator"* ]]; then
echo 'arch_contains_sim=1' | tee -a $GITHUB_OUTPUT
elif [[ "$labels" == *"Arch: x86_64"* ]]; then
echo 'arch_contains_x86_64=1' | tee -a $GITHUB_OUTPUT
elif [[ "$labels" == *"Arch: xtensa"* ]]; then
echo 'arch_contains_xtensa=1' | tee -a $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Select the Builds for the PR: arm-01, risc-v-01, xtensa-01, ...
- name: Select builds
id: select-builds
run: |
# Fetch the outputs from the previous step
arch_contains_arm=${{ steps.get-arch.outputs.arch_contains_arm }}
arch_contains_arm64=${{ steps.get-arch.outputs.arch_contains_arm64 }}
arch_contains_riscv=${{ steps.get-arch.outputs.arch_contains_riscv }}
arch_contains_sim=${{ steps.get-arch.outputs.arch_contains_sim }}
arch_contains_x86_64=${{ steps.get-arch.outputs.arch_contains_x86_64 }}
arch_contains_xtensa=${{ steps.get-arch.outputs.arch_contains_xtensa }}
labels_contain_size=${{ steps.get-arch.outputs.labels_contain_size }}
numlabels=${{ steps.get-arch.outputs.numlabels }}
# inputs.boards is a JSON Array: ["arm-01", "risc-v-01", "xtensa-01", ...]
# We compact and remove the newlines
boards=$( echo '${{ inputs.boards }}' | jq --compact-output ".")
numboards=$( echo "$boards" | jq "length" )
# We consider only PRs with 2 labels, including size
if [[ "$numlabels" != "2" || "$labels_contain_size" != "1" ]]; then
echo "selected_builds=$boards" | tee -a $GITHUB_OUTPUT
exit
fi
# For every board
for (( i=0; i<numboards; i++ ))
do
# Fetch the board
board=$( echo "$boards" | jq ".[$i]" )
skip_build=0
# For "Arch: arm": Build arm-01, arm-02, ...
if [[ "$arch_contains_arm" == "1" ]]; then
if [[ "$board" != *"arm"* ]]; then
skip_build=1
fi
# For "Arch: arm64": Build other
elif [[ "$arch_contains_arm64" == "1" ]]; then
if [[ "$board" != *"other"* ]]; then
skip_build=1
fi
# For "Arch: risc-v": Build risc-v-01, risc-v-02
elif [[ "$arch_contains_riscv" == "1" ]]; then
if [[ "$board" != *"risc-v"* ]]; then
skip_build=1
fi
# For "Arch: simulator": Build sim-01, sim-02
elif [[ "$arch_contains_sim" == "1" ]]; then
if [[ "$board" != *"sim"* ]]; then
skip_build=1
fi

# For "Arch: x86_64": Build other
elif [[ "$arch_contains_x86_64" == "1" ]]; then
if [[ "$board" != *"other"* ]]; then
skip_build=1
fi

# For "Arch: xtensa": Build xtensa-01, xtensa-02
elif [[ "$arch_contains_xtensa" == "1" ]]; then
if [[ "$board" != *"xtensa"* ]]; then
skip_build=1
fi

# For Other Arch: Allow the build
else
echo Build by default: $board
fi

# Add the board to the selected builds
if [[ "$skip_build" == "0" ]]; then
echo Add $board to selected_builds
if [[ "$selected_builds" == "" ]]; then
selected_builds=$board
else
selected_builds=$selected_builds,$board
fi
fi
done

# Return the selected builds as JSON Array
# If Selected Builds is empty: Skip all builds
echo "selected_builds=[$selected_builds]" | tee -a $GITHUB_OUTPUT
if [[ "$selected_builds" == "" ]]; then
echo "skip_all_builds=1" | tee -a $GITHUB_OUTPUT
fi
124 changes: 45 additions & 79 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ concurrency:
cancel-in-progress: true

jobs:

# Fetch the source from nuttx and nuttx-apps repos
Fetch-Source:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -115,115 +117,57 @@ jobs:
name: source-bundle
path: sources.tar.gz

Linux:
# Select the Linux Builds based on PR Arch Label
Linux-Arch:
uses: apache/nuttx/.github/workflows/arch.yml@master
needs: Fetch-Source
with:
os: Linux
boards: |
[
"arm-01", "other", "risc-v-01", "sim-01", "xtensa-01",
"arm-02", "risc-v-02", "sim-02", "xtensa-02",
"arm-03", "arm-04", "arm-05", "arm-06", "arm-07", "arm-08", "arm-09", "arm-10", "arm-11", "arm-12", "arm-13"
]
# Run the selected Linux Builds
Linux:
needs: Linux-Arch
if: ${{ needs.Linux-Arch.outputs.skip_all_builds != '1' }}
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1

strategy:
max-parallel: 12
matrix:
boards: [
arm-01, other, risc-v-01, sim-01, xtensa-01,
arm-02, risc-v-02, sim-02, xtensa-02,
arm-03, arm-04, arm-05, arm-06, arm-07, arm-08, arm-09, arm-10, arm-11, arm-12, arm-13
]
boards: ${{ fromJSON(needs.Linux-Arch.outputs.selected_builds) }}

steps:

# Get the Arch for the PR: arm, arm64, risc-v, xtensa, ...
- name: Get arch
id: get-arch
run: |
# Get the Labels for the PR: "Arch: risc-v \n Size: XS"
pr=${{github.event.pull_request.number}}
if [[ "$pr" == "" ]]; then
exit
fi
numlabels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq '.[] | length')
labels=$(gh pr view $pr --repo $GITHUB_REPOSITORY --json labels --jq '.labels[] | .name')
# Identify the Size and Arch Labels
if [[ "$labels" == *"Size: "* ]]; then
labels_contain_size=1
fi
if [[ "$labels" == *"Arch: arm"* ]]; then
arch_contains_arm_arm64=1
fi
if [[ "$labels" == *"Arch: risc-v"* ]]; then
arch_contains_riscv=1
fi
if [[ "$labels" == *"Arch: xtensa"* ]]; then
arch_contains_xtensa=1
fi
# We consider only PRs with 2 labels, including size
if [ $numlabels -ne 2 ] || [ $labels_contain_size -ne 1 ]; then
exit
fi
# If "Arch: arm / arm64" is the only non-size label, then build other, arm-01, arm-02, ...
if [[ "$arch_contains_arm_arm64" == "1" ]]; then
if [[ "${{matrix.boards}}" == "arm"* ]] || [[ "${{matrix.boards}}" == "other"* ]]; then
echo Allow build: ${{matrix.boards}}
else
echo Skip build: ${{matrix.boards}}
echo "skip_build=1" >> $GITHUB_OUTPUT
fi
fi
# If "Arch: risc-v" is the only non-size label, then build risc-v-01, risc-v-02
if [[ "$arch_contains_riscv" == "1" ]]; then
if [[ "${{matrix.boards}}" == "risc-v"* ]]; then
echo Allow build: ${{matrix.boards}}
else
echo Skip build: ${{matrix.boards}}
echo "skip_build=1" >> $GITHUB_OUTPUT
fi
fi
# If "Arch: xtensa" is the only non-size label, then build xtensa-01, xtensa-02
if [[ "$arch_contains_xtensa" == "1" ]]; then
if [[ "${{matrix.boards}}" == "xtensa"* ]]; then
echo Allow build: ${{matrix.boards}}
else
echo Skip build: ${{matrix.boards}}
echo "skip_build=1" >> $GITHUB_OUTPUT
fi
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Download Source Artifact
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
uses: actions/download-artifact@v4
with:
name: source-bundle
path: .

- name: Extract sources
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
run: tar zxf sources.tar.gz

- name: Docker Login
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Pull
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
run: docker pull ghcr.io/apache/nuttx/apache-nuttx-ci-linux

- name: Export NuttX Repo SHA
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
run: echo "nuttx_sha=`git -C sources/nuttx rev-parse HEAD`" >> $GITHUB_ENV

- name: Run builds
if: ${{ steps.get-arch.outputs.skip_build != '1' }}
uses: ./sources/nuttx/.github/actions/ci-container
env:
BLOBDIR: /tools/blobs
Expand All @@ -247,15 +191,26 @@ jobs:
path: buildartifacts/
continue-on-error: true

# Select the macOS Builds based on PR Arch Label
macOS-Arch:
uses: apache/nuttx/.github/workflows/arch.yml@master
needs: Fetch-Source
with:
os: Linux
boards: |
["macos", "sim-01", "sim-02"]
# Run the selected macOS Builds
macOS:
permissions:
contents: none
runs-on: macos-13
needs: Fetch-Source
needs: macOS-Arch
if: ${{ needs.macOS-Arch.outputs.skip_all_builds != '1' }}
strategy:
max-parallel: 2
matrix:
boards: [macos, sim-01, sim-02]
boards: ${{ fromJSON(needs.macOS-Arch.outputs.selected_builds) }}
steps:
- name: Download Source Artifact
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -296,14 +251,25 @@ jobs:
path: buildartifacts/
continue-on-error: true

msys2:
# Select the msys2 Builds based on PR Arch Label
msys2-Arch:
uses: apache/nuttx/.github/workflows/arch.yml@master
needs: Fetch-Source
with:
os: Linux
boards: |
["msys2"]
# Run the selected msys2 Builds
msys2:
needs: msys2-Arch
if: ${{ needs.msys2-Arch.outputs.skip_all_builds != '1' }}
runs-on: windows-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
boards: [msys2]
boards: ${{ fromJSON(needs.msys2-Arch.outputs.selected_builds) }}

defaults:
run:
Expand Down
Loading

0 comments on commit 507df45

Please sign in to comment.