[openwrt/openwrt] CI: build: add support for external toolchains from stable branch

LEDE Commits lede-commits at lists.infradead.org
Sun Dec 4 07:37:45 PST 2022


ansuel pushed a commit to openwrt/openwrt.git, branch openwrt-21.02:
https://git.openwrt.org/69c0c3c2f904279d1c687cd7a42d82987c99b3e7

commit 69c0c3c2f904279d1c687cd7a42d82987c99b3e7
Author: Christian Marangi <ansuelsmth at gmail.com>
AuthorDate: Mon Nov 28 12:44:01 2022 +0100

    CI: build: add support for external toolchains from stable branch
    
    Add support to use external toolchains from stable branch if we are
    testing commit targeting stable openwrt branch in kernel and packages
    workflow.
    
    With pr the target branch is parsed and the right toolchain is used.
    
    To use the stable toolchain for local testing the branch needs to have
    the prefix openwrt-[0-9][0-9].[0-9][0-9]- (example openwrt-21.02-fixup)
    
    Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
    (cherry picked from commit e24a1e6f6d7f08fb766eb11b8008f8fc5b72d072)
---
 .github/workflows/build.yml | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 510ff6a879..909b849731 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -145,13 +145,38 @@ jobs:
         if: inputs.build_toolchain == false
         working-directory: openwrt
         run: |
-          TOOLCHAIN_STRING="$(curl "https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
+          TOOLCHAIN_PATH=snapshots
+
+          if [ -n "${{ github.base_ref }}" ]; then
+            if echo "${{ github.base_ref }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
+              major_ver="$(echo ${{ github.base_ref }} | sed 's/openwrt-/v/')"
+            fi
+          elif [ "${{ github.ref_type }}" = "branch" ]; then
+            if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
+              major_ver="$(echo ${{ github.ref_name }} | sed 's/openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
+            fi
+          elif [ "${{ github.ref_type }}" = "tag" ]; then
+            if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
+              major_ver="$(sed 's/\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
+            fi
+          fi
+
+          if [ -n "$major_ver" ]; then
+            git fetch --tags
+            latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
+            if [ -n "$latest_tag" ]; then
+              TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
+            fi
+          fi
+
+          TOOLCHAIN_STRING="$(curl "https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
             | grep ".*openwrt-toolchain.*tar.xz")"
           TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
           TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
 
           echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
           echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
+          echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
 
       - name: Cache external toolchain
         if: inputs.build_toolchain == false
@@ -174,7 +199,7 @@ jobs:
         shell: su buildbot -c "sh -e {0}"
         working-directory: openwrt
         run: |
-          wget -O - https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${TOOLCHAIN_FILE}.tar.xz \
+          wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
             | tar --xz -xf -
 
       - name: Extract prebuilt tools




More information about the lede-commits mailing list