8000 Add workflow to build executables from python scripts · espressif/arduino-esp32@ac9cf46 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac9cf46

Browse files
committed
Add workflow to build executables from python scripts
1 parent c34f850 commit ac9cf46

File tree

6 files changed

+217
-2
lines changed
  • scripts
  • workflows
  • tools
  • 6 files changed

    +217
    -2
    lines changed

    .github/pytools/Sign-File.ps1

    Lines changed: 78 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,78 @@
    1+
    [CmdletBinding()]
    2+
    param (
    3+
    [Parameter()]
    4+
    [String]
    5+
    $Path
    6+
    )
    7+
    8+
    9+
    function FindSignTool {
    10+
    $SignTool = "signtool.exe"
    11+
    if (Get-Command $SignTool -ErrorAction SilentlyContinue) {
    12+
    return $SignTool
    13+
    }
    14+
    $SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\signtool.exe"
    15+
    if (Test-Path -Path $SignTool -PathType Leaf) {
    16+
    return $SignTool
    17+
    }
    18+
    $SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x86\signtool.exe"
    19+
    if (Test-Path -Path $SignTool -PathType Leaf) {
    20+
    return $SignTool
    21+
    }
    22+
    $sdkVers = "10.0.22000.0", "10.0.20348.0", "10.0.19041.0", "10.0.17763.0"
    23+
    Foreach ($ver in $sdkVers)
    24+
    {
    25+
    $SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\${ver}\x64\signtool.exe"
    26+
    if (Test-Path -Path $SignTool -PathType Leaf) {
    27+
    return $SignTool
    28+
    }
    29+
    }
    30+
    "signtool.exe not found"
    31+
    Exit 1
    32+
    }
    33+
    34+
    function SignEsptool {
    35+
    param(
    36+
    [Parameter()]
    37+
    [String]
    38+
    $Path
    39+
    )
    40+
    41+
    $SignTool = FindSignTool
    42+
    "Using: $SignTool"
    43+
    $CertificateFile = [system.io.path]::GetTempPath() + "certificate.pfx"
    44+
    45+
    if ($null -eq $env:CERTIFICATE) {
    46+
    "CERTIFICATE variable not set, unable to sign the file"
    47+
    Exit 1
    48+
    }
    49+
    50+
    if ("" -eq $env:CERTIFICATE) {
    51+
    "CERTIFICATE variable is empty, unable to sign the file"
    52+
    Exit 1
    53+
    }
    54+
    55+
    $SignParameters = @("sign", "/tr", 'http://timestamp.digicert.com', "/td", "SHA256", "/f", $CertificateFile, "/fd", "SHA256")
    56+
    if ($env:CERTIFICATE_PASSWORD) {
    57+
    "CERTIFICATE_PASSWORD detected, using the password"
    58+
    $SignParameters += "/p"
    59+
    $SignParameters += $env:CERTIFICATE_PASSWORD
    60+
    }
    61+
    $SignParameters += $Path
    62+
    63+
    [byte[]]$CertificateBytes = [convert]::FromBase64String($env:CERTIFICATE)
    64+
    [IO.File]::WriteAllBytes($CertificateFile, $CertificateBytes)
    65+
    66+
    &$SignTool $SignParameters
    67+
    68+
    if (0 -eq $LASTEXITCODE) {
    69+
    Remove-Item $CertificateFile
    70+
    } else {
    71+
    Remove-Item $CertificateFile
    72+
    "Signing failed"
    73+
    Exit 1
    74+
    }
    75+
    76+
    }
    77+
    78+
    SignEsptool ${Path}

    .github/pytools/espressif.ico

    115 KB
    Binary file not shown.

    .github/scripts/upload_py_tools.sh

    Lines changed: 9 additions & 0 deletions
    < B41A div data-testid="addition diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__addition--jeNtt">
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,9 @@
    1+
    #!/bin/bash
    2+
    echo "Pushing as $GITHUB_ACTOR"
    3+
    git config --global github.user "$GITHUB_ACTOR"
    4+
    git config --global user.name "$GITHUB_ACTOR"
    5+
    git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
    6+
    git add tools/get.exe
    7+
    git commit -m "Push binary to tools"
    8+
    git push
    9+

    .github/workflows/build_py_tools.yml

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

    tools/get.exe

    1.55 MB
    Binary file not shown.

    tools/get.py

    Lines changed: 14 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -35,7 +35,13 @@
    3535
    if 'Windows' in platform.system():
    3636
    import requests
    3737

    38-
    current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
    38+
    # determine if application is a script file or frozen exe
    39+
    if getattr(sys, 'frozen', False):
    40+
    current_dir = os.path.dirname(os.path.realpath(unicode(sys.executable)))
    41+
    elif __file__:
    42+
    current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
    43+
    44+
    #current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
    3945
    dist_dir = current_dir + '/dist/'
    4046

    4147
    def sha256sum(filename, blocksize=65536):
    @@ -88,6 +94,8 @@ def unpack(filename, destination):
    8894

    8995
    # a little trick to rename tool directories so they don't contain version number
    9096
    rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
    97+
    if rename_to == dirname and dirname.startswith('esp32-arduino-libs-'):
    98+
    rename_to = 'esp32-arduino-libs'
    9199
    if rename_to != dirname:
    92100
    print('Renaming {0} to {1} ...'.format(dirname, rename_to))
    93101
    if os.path.isdir(rename_to):
    @@ -220,7 +228,11 @@ def identify_platform():
    220228
    identified_platform = identify_platform()
    221229
    print('Platform: {0}'.format(identified_platform))
    222230
    tools_to_download = load_tools_list(current_dir + '/../package/package_esp32_index.template.json', identified_platform)
    231+
    is_test = (len(sys.argv) > 1 and sys.argv[1] == '-h')
    223232
    mkdir_p(dist_dir)
    224233
    for tool in tools_to_download:
    225-
    get_tool(tool)
    234+
    if is_test:
    235+
    print('Would install: {0}'.format(tool['archiveFileName']))
    236+
    else:
    237+
    get_tool(tool)
    226238
    print('Platform Tools Installed')

    0 commit comments

    Comments
     (0)
    0