|
| 1 | +name: Build Python Tools |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'tools/get.py' |
| 7 | + - 'tools/espota.py' |
| 8 | + - 'tools/gen_esp32part.py' |
| 9 | + - 'tools/gen_insights_package.py' |
| 10 | + |
| 11 | +jobs: |
| 12 | + find-changed-tools: |
| 13 | + name: Check if tools have been changed |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + outputs: |
| 16 | + any_changed: ${{ steps.verify-changed-files.outputs.any_changed }} |
| 17 | + all_changed_files: ${{ steps.verify-changed-files.outputs.all_changed_files }} |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + fetch-depth: 2 |
| 23 | + ref: ${{ github.event.pull_request.head.ref }} |
| 24 | + - name: Verify Python Tools Changed |
| 25 | + uses: tj-actions/changed-files@v36 |
| 26 | + id: verify-changed-files |
| 27 | + with: |
| 28 | + fetch_depth: '2' |
| 29 | + since_last_remote_commit: 'true' |
| 30 | + files: | |
| 31 | + tools/get.py |
| 32 | + tools/espota.py |
| 33 | + tools/gen_esp32part.py |
| 34 | + tools/gen_insights_package.py |
| 35 | + - name: List all changed files |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + for file in ${{ steps.verify-changed-files.outputs.all_changed_files }}; do |
| 39 | + echo "$file was changed" |
| 40 | + done |
| 41 | +
|
| 42 | + build-pytools-binaries: |
| 43 | + name: Build python tools binaries for ${{ matrix.os }} |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + needs: find-changed-tools |
| 46 | + if: needs.find-changed-tools.outputs.any_changed == 'true' |
| 47 | + strategy: |
| 48 | + fail-fast: false |
| 49 | + matrix: |
| 50 | + os: [windows-latest, macos-latest, ubuntu-20.04, ARM, ARM64] |
| 51 | + include: |
| 52 | + - os: windows-latest |
| 53 | + TARGET: win64 |
| 54 | + EXTEN: .exe |
| 55 | + SEPARATOR: ';' |
| 56 | + - os: macos-latest |
| 57 | + TARGET: macos |
| 58 | + SEPARATOR: ':' |
| 59 | + - os: ubuntu-20.04 |
| 60 | + TARGET: linux-amd64 |
| 61 | + SEPARATOR: ':' |
| 62 | + - os: ARM |
| 63 | + CONTAINER: python:3.8-bullseye |
| 64 | + TARGET: arm |
| 65 | + SEPARATOR: ':' |
| 66 | + - os: ARM64 |
| 67 | + CONTAINER: python:3.8-bullseye |
| 68 | + TARGET: arm64 |
| 69 | + SEPARATOR: ':' |
| 70 | + container: ${{ matrix.CONTAINER }} # use python container on ARM |
| 71 | + env: |
| 72 | + DISTPATH: pytools-${{ matrix.TARGET }} |
| 73 | + PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi" |
| 74 | + steps: |
| 75 | + - name: List changed tools |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + CHANGED_FILES=() |
| 79 | + for file in ${{ needs.find-changed-tools.outputs.all_changed_files }}; do |
| 80 | + file="${file#*\/}" |
| 81 | + file="${file%\.*}" |
| 82 | + CHANGED_FILES+=("$file") |
| 83 | + done |
| 84 | + CHANGED_FILES="${CHANGED_FILES[@]}" |
| 85 | + echo "CHANGED_TOOLS=$CHANGED_FILES" >> "$GITHUB_ENV" |
| 86 | + for tool in ${{ env.CHANGED_TOOLS }}; do |
| 87 | + echo "tool $tool was changed" |
| 88 | + done |
| 89 | + - name: Checkout repository |
| 90 | + uses: actions/checkout@v3 |
| 91 | + with: |
| 92 | + ref: ${{ github.event.pull_request.head.ref }} |
| 93 | + - name: Set up Python 3.8 |
| 94 | + # Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108 |
| 95 | + if: matrix.os != 'ARM' && matrix.os != 'ARM64' |
| 96 | + uses: actions/setup-python@master |
| 97 | + with: |
| 98 | + python-version: 3.8 |
| 99 | + - name: Install dependencies |
| 100 | + run: | |
| 101 | + python -m pip install --upgrade pip |
| 102 | + pip install pyinstaller requests |
| 103 | + - name: Build with PyInstaller |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + for tool in ${{ env.CHANGED_TOOLS }}; do |
| 107 | + pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/$tool.py |
| 108 | + done |
| 109 | + - name: Sign binaries |
| 110 | + if: matrix.os == 'windows-latest' |
| 111 | + env: |
| 112 | + CERTIFICATE: ${{ secrets.CERTIFICATE }} |
| 113 | + CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }} |
| 114 | + shell: pwsh |
| 115 | + run: | |
| 116 | + $data = Write-Output ${{ env.CHANGED_TOOLS }} |
| 117 | + foreach ( $node in $data ) |
| 118 | + { |
| 119 | + ./.github/pytools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/$node.exe |
| 120 | + } |
| 121 | + - name: Test binaries |
| 122 | + shell: bash |
| 123 | + run: | |
| 124 | + for tool in ${{ env.CHANGED_TOOLS }}; do |
| 125 | + ./${{ env.DISTPATH }}/$tool${{ matrix.EXTEN }} -h |
| 126 | + done |
| 127 | + - name: Push binary to tools |
| 128 | + if: matrix.os == 'windows-latest' |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + for tool in ${{ env.CHANGED_TOOLS }}; do |
| 134 | + cp -f ./${{ env.DISTPATH }}/$tool.exe tools/$tool.exe |
| 135 | + done |
| 136 | + bash .github/scripts/upload_py_tools.sh "${{ env.CHANGED_TOOLS }}" |
| 137 | + - name: Archive artifact |
| 138 | + uses: actions/upload-artifact@master |
| 139 | + with: |
| 140 | + name: ${{ env.DISTPATH }} |
| 141 | + path: ${{ env.DISTPATH }} |
0 commit comments