浏览代码

Expand GitHub Actions for build

Sebastien 4 年之前
父节点
当前提交
33ad6d5950
共有 1 个文件被更改,包括 111 次插入12 次删除
  1. 111 12
      .github/workflows/I2S-4MBFlash.yml

+ 111 - 12
.github/workflows/I2S-4MBFlash.yml

@@ -9,28 +9,127 @@ on:
     branches: [ master-cmake ]
 
 jobs:
+  job1:
+    name: Build Number
+    runs-on: ubuntu-latest
+    outputs:
+      build_number: ${{ steps.buildnumber.outputs.build_number }}
+    steps:
+    - name: Generate common build number
+      id: buildnumber
+      uses: einaregilsson/build-number@v2 
+      with:
+        token: ${{secrets.github_token}}
   build:
     runs-on: ubuntu-latest
+    needs: job1
+    strategy:
+      matrix:
+        node: [I2S-4MFlash, ESP32-A1S, SqueezeAmp]
     steps:
-    - name: Set target
-      run: echo "TARGET_BUILD_NAME=I2S-4MFlash" >> $GITHUB_ENV
-      id: target-name-generator
-    - name: Show Target
-      run: echo "Target is ${TARGET_BUILD_NAME}"
+    - name: Set target name
+      run: |
+        echo "TARGET_BUILD_NAME=${{ matrix.node }}" >> $GITHUB_ENV
+        echo "build_version_prefix=V0." >> $GITHUB_ENV
     - uses: actions/checkout@v2
       with:
         submodules: true
-    - name: Generate build number
-      id: buildnumber
-      uses: einaregilsson/build-number@v2 
-      with:
-        token: ${{secrets.github_token}}        
     - name: Cache build
       id: cache-build
       uses: actions/cache@v1
       with:
-        path: ${{github.workspace}}/build
+        path: ${{github.RUNNER_WORKSPACE}}/build
         key: ${{ runner.os }}-${TARGET_BUILD_NAME}
+    - name: Set build parameters
+      run: |
+        shopt -s nocasematch
+        branch_name="${GITHUB_REF//refs\/heads\//}"
+        branch_name="${branch_name//[^a-zA-Z0-9\-~!@_\.]/}"
+        BUILD_NUMBER=${{ needs.job1.outputs.build_number }}
+        echo "BUILD_NUMBER=${BUILD_NUMBER}" >> $GITHUB_ENV
+        tag="${build_version_prefix}${BUILD_NUMBER}-${TARGET_BUILD_NAME}-${branch_name}"
+        last_commit="$(git log --pretty=format:'%s' --max-count=1)"
+        if [[ "$last_commit" =~ .*"Release".* ]]; then echo "release_flag=1" >> $GITHUB_ENV; else echo "release_flag=0" >> $GITHUB_ENV; fi
+        name="${build_version_prefix}${BUILD_NUMBER}.${branch_name}#v4.0#${TARGET_BUILD_NAME}#${branch_name}"
+        artifact_prefix="squeezelite-esp32-${branch_name}-${TARGET_BUILD_NAME}-${build_version_prefix}${BUILD_NUMBER}"
+        artifact_file_name="${artifact_prefix}.zip"
+        artifact_bin_file_name="${artifact_prefix}.bin"
+        echo "name=${name}" >> $GITHUB_ENV
+        echo "last_commit=${last_commit}" >> $GITHUB_ENV
+        echo "artifact_file_name=${artifact_file_name}" >> $GITHUB_ENV
+        echo "artifact_bin_file_name=${artifact_bin_file_name}" >> $GITHUB_ENV
+        description=""
+        description=${description}$'------------------------------\n### Revision Log\n\n'
+        description="$description$(git log --pretty=format:'%h %s (%cI) <%an>' --abbrev-commit --max-count=15 | sed --r 's/(^[\*]+)/\\\1/g') "        
+        echo ${description}
+        echo ${description} >>release_desc.txt
+        echo "description=${description}" >> $GITHUB_ENV
+        cat release_desc.txt
+    - name: Show Target
+      run: |
+        echo "Target is ${TARGET_BUILD_NAME}"
+        env
     - name: Build the firmware
+      if: env.release_flag == 1 && env.release_flag == 0
+      run: |
+        docker run --rm -v $PWD:/project -w /project espressif/idf:release-v4.0 /bin/bash -c "cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig && export PROJECT_VER=${TARGET_BUILD_NAME}-${{ steps.buildnumber.outputs.build_number }} && idf.py build && zip ${artifact_file_name} ../partitions*.csv *.bin ./bootloader/bootloader.bin ./partition_table/partition-table.bin flash_project_args ./size_*.txt"
+    - name: Build Mock firmware
+      run: |
+        mkdir -p build
+        cd build
+        mkdir -p partition_table
+        mkdir -p bootloader
+        echo "mock content"> squeezelite.bin
+        echo "mock content"> recovery.bin
+        echo "mock content"> ./bootloader/bootloader.bin
+        echo "mock content"> ./partition_table/partition-table.bin 
+        echo "mock content"> flash_project_args 
+        echo "mock content"> size_comp1.txt
+        echo "mock content"> size_comp2.txt
+        echo "mock content"> ../partitions.csv
+    - uses: actions/upload-artifact@v2
+      with:
+        name: ${{ env.artifact_file_name }}
+        path: |
+          build/*.bin
+          build/bootloader/bootloader.bin
+          build/partition_table/partition-table.bin 
+          build/flash_project_args 
+          build/size_comp1.txt
+          build/size_comp2.txt
+          partitions.csv
+    - uses: actions/upload-artifact@v2
+      with:
+        name: ${{ env.artifact_bin_file_name }}
+        path: |
+          build/squeezelite.bin
+
+    - name: Create Release
+      if: env.release_flag == 1     
+      id: create_release
+      uses: actions/create-release@v1
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
+      with:
+        tag_name: ${{ env.tag }}
+
+        release_name: ${{ env.name }}
+        body: ${{ env.description }}
+        draft: false
+        prerelease: true
+
+
+
+
+
+
+
+
+    - name: Prepare release
+      if: env.release_flag == 1    
       run: |
-        docker run --rm -v $PWD:/project -w /project espressif/idf:release-v4.0 /bin/bash -c "cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig && export PROJECT_VER=${TARGET_BUILD_NAME}-${{ steps.buildnumber.outputs.build_number }} && idf.py build"
+        description=""
+        description=${description}$'------------------------------\n### Revision Log\n\n'
+        description="$description$(git -C ${RUNNER_WORKSPACE} log --pretty=format:'%h %s (%cI) <%an>' --abbrev-commit --max-count=15 | sed --r 's/(^[\*]+)/\\\1/g') "
+        
+