Browse Source

Add dockerfile detection, qemu env for build scripts, longpath support (#226)

Mike Chang 1 year ago
parent
commit
a8019a5abb
1 changed files with 26 additions and 22 deletions
  1. 26 22
      .github/workflows/build-package.yaml

+ 26 - 22
.github/workflows/build-package.yaml

@@ -37,7 +37,7 @@ jobs:
               OS_RUNNER="ubuntu-20.04"
               OS_RUNNER="ubuntu-20.04"
               ;;
               ;;
             windows)
             windows)
-              OS_RUNNER="windows-2019"
+              OS_RUNNER="windows-latest" # This is bundled with VS2022
               ;;
               ;;
             darwin)
             darwin)
               OS_RUNNER="macos-latest"
               OS_RUNNER="macos-latest"
@@ -49,14 +49,11 @@ jobs:
 
 
             DIFF=$(git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} --no-ext-diff --unified=0 \
             DIFF=$(git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} --no-ext-diff --unified=0 \
                         --exit-code -a --no-prefix -- $FILE | egrep "^\+" | grep Scripts) # Get oly the changes that can be built
                         --exit-code -a --no-prefix -- $FILE | egrep "^\+" | grep Scripts) # Get oly the changes that can be built
-
-            if [[ $? -ne 0 ]]; then
-              echo No valid build change found. Exiting with non-zero
-            fi
           
           
             PACKAGE=$(echo $DIFF | cut -d'"' -f2)
             PACKAGE=$(echo $DIFF | cut -d'"' -f2)
-      
-            JSONline="{\"package\": \"$PACKAGE\", \"os\": \"$OS_RUNNER\"},"
+            PACKPATH=$(echo $DIFF | egrep -o "package-system/[^ ]*")
+            DOCKER=$(test -f "$PACKPATH/Dockerfile" && echo 1 || echo 0)
+            JSONline="{\"package\": \"$PACKAGE\", \"os\": \"$OS_RUNNER\", \"dockerfile\": \"$DOCKER\"},"
             if [[ "$JSON" != *"$JSONline"* ]]; then
             if [[ "$JSON" != *"$JSONline"* ]]; then
               JSON="$JSON$JSONline"
               JSON="$JSON$JSONline"
             fi
             fi
@@ -114,20 +111,22 @@ jobs:
 
 
     steps:
     steps:
     - name: Configure
     - name: Configure
-      id: get-user
-      run: echo "uid_gid=$(id -u):$(id -g)" >> $GITHUB_OUTPUT
+      id: configure
+      run: |
+        git config --global core.longpaths true
+        echo "uid_gid=$(id -u):$(id -g)" >> $GITHUB_OUTPUT
       
       
     - name: Checkout 3P source repo
     - name: Checkout 3P source repo
       uses: actions/checkout@v4
       uses: actions/checkout@v4
       with:
       with:
-        path: 3p-package-source
+        path: source
         fetch-depth: 0
         fetch-depth: 0
     
     
     - name: Checkout 3P scripts repo
     - name: Checkout 3P scripts repo
       uses: actions/checkout@v4
       uses: actions/checkout@v4
       with:
       with:
         repository: o3de/3p-package-scripts
         repository: o3de/3p-package-scripts
-        path: 3p-package-scripts
+        path: scripts
       
       
     - name: Update python
     - name: Update python
       uses: actions/setup-python@v4
       uses: actions/setup-python@v4
@@ -165,32 +164,37 @@ jobs:
         max-size: 2048M
         max-size: 2048M
         key: ${{ matrix.package }}-${{ matrix.os }}
         key: ${{ matrix.package }}-${{ matrix.os }}
         restore-keys:
         restore-keys:
-          ${{ matrix.package }}-${{ matrix.os }}
-        
+          ${{ matrix.package }}-${{ matrix.os }}  
+
+    - name: Set up QEMU (aarch64) # Only if the package folder contains a Dockerfile
+      if: ${{ (contains(matrix.package, 'aarch64')) && (matrix.dockerfile == '1') }}
+      run: |
+        sudo apt-get install -y qemu qemu-user-static
+
     - name: Run build command
     - name: Run build command
-      if: ${{ !contains(matrix.package, 'aarch64') }}
+      if: ${{ (!contains(matrix.package, 'aarch64')) || (matrix.dockerfile == '1') }}
       env:
       env:
         CMAKE_CXX_COMPILER_LAUNCHER: sccache
         CMAKE_CXX_COMPILER_LAUNCHER: sccache
         CMAKE_C_COMPILER_LAUNCHER: sccache
         CMAKE_C_COMPILER_LAUNCHER: sccache
         CMAKE_GENERATOR: Ninja # ccache/sccache cannot be used as the compiler launcher under cmake if the generator is MSBuild
         CMAKE_GENERATOR: Ninja # ccache/sccache cannot be used as the compiler launcher under cmake if the generator is MSBuild
       run: |
       run: |
-        python3 3p-package-scripts/o3de_package_scripts/build_package.py --search_path 3p-package-source ${{ matrix.package }}
+        python3 scripts/o3de_package_scripts/build_package.py --search_path source ${{ matrix.package }}
 
 
-    - name: Run build command (aarch64)
-      if: contains(matrix.package, 'aarch64')
+    - name: Run build command (aarch64) # Generic build for packages without a Dockerfile
+      if: ${{ (contains(matrix.package, 'aarch64')) && (matrix.dockerfile != '1') }}
       uses: uraimo/[email protected]
       uses: uraimo/[email protected]
       with:
       with:
         arch: none
         arch: none
         distro: none
         distro: none
         base_image: ghcr.io/${{ github.repository }}/run-on-arch-${{ github.repository_owner }}-${{ github.event.repository.name }}-build-container-aarch64-ubuntu20-04:latest # built from build-container.yaml
         base_image: ghcr.io/${{ github.repository }}/run-on-arch-${{ github.repository_owner }}-${{ github.event.repository.name }}-build-container-aarch64-ubuntu20-04:latest # built from build-container.yaml
         setup: |
         setup: |
-          grep -q ${{ matrix.package }} ${PWD}/3p-package-source/package_build_list_host_linux.json || rm ${PWD}/3p-package-source/package_build_list_host_linux.json
+          grep -q ${{ matrix.package }} ${PWD}/source/package_build_list_host_linux.json || rm ${PWD}/source/package_build_list_host_linux.json
         dockerRunArgs: |
         dockerRunArgs: |
           --platform=linux/arm64 
           --platform=linux/arm64 
-          --user ${{ steps.get-user.outputs.uid_gid }}
+          --user ${{ steps.configure.outputs.uid_gid }}
           --volume "${PWD}:/workspace"
           --volume "${PWD}:/workspace"
-          --volume "${PWD}/3p-package-scripts:/scripts"
-          --volume "${PWD}/3p-package-source:/source"
+          --volume "${PWD}/scripts:/scripts"
+          --volume "${PWD}/source:/source"
         env: |
         env: |
           CMAKE_CXX_COMPILER_LAUNCHER: sccache
           CMAKE_CXX_COMPILER_LAUNCHER: sccache
           CMAKE_C_COMPILER_LAUNCHER: sccache
           CMAKE_C_COMPILER_LAUNCHER: sccache
@@ -210,7 +214,7 @@ jobs:
       uses: actions/upload-artifact@v3
       uses: actions/upload-artifact@v3
       with:
       with:
         name: ${{ matrix.package }}
         name: ${{ matrix.package }}
-        path: 3p-package-source/packages/*
+        path: source/packages/*
 
 
   validate-packages:
   validate-packages:
     name: Validating ${{ matrix.package }}
     name: Validating ${{ matrix.package }}