Skip to content

Commit

Permalink
CI: Build and release binaries
Browse files Browse the repository at this point in the history
Closes #625
  • Loading branch information
radimkarnis committed May 19, 2021
1 parent e5f94fa commit 9305da8
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 2 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/build_esptool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Build esptool

on: [push, pull_request]

jobs:
build-esptool-binaries:
name: Build esptool binaries for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: macos-latest
TARGET: macos
- os: ubuntu-latest
TARGET: linux-amd64
- os: windows-latest
TARGET: win64
EXTEN: .exe
env:
DISTPATH: esptool-${{ matrix.TARGET }}
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install --user -e .
- name: Build with PyInstaller
run: |
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=build_tools/espressif.ico esptool.py
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=build_tools/espressif.ico espefuse.py
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=build_tools/espressif.ico espsecure.py
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=build_tools/espressif.ico esp_rfc2217_server.py
- name: Sign binaries
if: matrix.os == 'windows-latest'
env:
CERTIFICATE: ${{ secrets.CERTIFICATE }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
shell: pwsh
run: |
./build_tools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/esptool.exe
./build_tools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/espefuse.exe
./build_tools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/espsecure.exe
./build_tools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/esp_rfc2217_server.exe
- name: Test binaries
shell: bash
run: |
./${{ env.DISTPATH }}/esptool${{ matrix.EXTEN }} -h
./${{ env.DISTPATH }}/espefuse${{ matrix.EXTEN }} -h
./${{ env.DISTPATH }}/espsecure${{ matrix.EXTEN }} -h
./${{ env.DISTPATH }}/esp_rfc2217_server${{ matrix.EXTEN }} -h
- name: Add license and readme
shell: bash
run: mv LICENSE README.md ./${{ env.DISTPATH }}
- name: Archive artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.DISTPATH }}
path: ${{ env.DISTPATH }}

create_release:
name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
needs: build-esptool-binaries
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Version ${{ github.ref }}
draft: true
prerelease: false
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
shell: bash

upload_assets:
name: Upload release assets
if: startsWith(github.ref, 'refs/tags/')
needs: create_release
runs-on: ubuntu-latest
strategy:
matrix:
TARGET: [macos, linux-amd64, win64]
env:
DISTPATH: esptool-${{ needs.create_release.outputs.VERSION }}-${{ matrix.TARGET }}
steps:
- name: Download built binaries
uses: actions/download-artifact@v2
- name: Rename and package binaries
run: |
mv esptool-${{ matrix.TARGET }} ${{ env.DISTPATH }}
zip -r ${{ env.DISTPATH }}.zip ./${{ env.DISTPATH }}/*
- name: Upload release assets
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: "${{ env.DISTPATH }}.zip"
asset_name: "${{ env.DISTPATH }}.zip"
asset_content_type: application/zip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow will upload an esptool Python package when a release is created

name: Upload release to PyPI
name: PyPI release

on:
release:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ esptool.py was started by Fredrik Ahlberg (@[themadinventor](https://github.com/

esptool.py is Free Software under a GPLv2 license.

[![Test esptool](https://github.com/espressif/esptool/workflows/Test%20esptool/badge.svg?branch=master)](https://github.com/espressif/esptool)
[![Test esptool](https://github.com/espressif/esptool/actions/workflows/test_esptool.yml/badge.svg?branch=master)](https://github.com/espressif/esptool/actions/workflows/test_esptool.yml)[![Build esptool](https://github.com/espressif/esptool/actions/workflows/build_esptool.yml/badge.svg?branch=master)](https://github.com/espressif/esptool/actions/workflows/build_esptool.yml)

## Installation / dependencies

Expand Down
70 changes: 70 additions & 0 deletions build_tools/Sign-File.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[CmdletBinding()]
param (
[Parameter()]
[String]
$Path
)


function FindSignTool {
$SignTool = "signtool.exe"
if (Get-Command $SignTool -ErrorAction SilentlyContinue) {
return $SignTool
}
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\signtool.exe"
if (Test-Path -Path $SignTool -PathType Leaf) {
return $SignTool
}
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x86\signtool.exe"
if (Test-Path -Path $SignTool -PathType Leaf) {
return $SignTool
}
"signtool.exe not found"
Exit 1
}

function SignInstaller {
param(
[Parameter()]
[String]
$Path
)

$SignTool = FindSignTool
"Using: $SignTool"
$CertificateFile = [system.io.path]::GetTempPath() + "certificate.pfx"

if ($null -eq $env:CERTIFICATE) {
"CERTIFICATE variable not set, unable to sign the file"
Exit 1
}

if ("" -eq $env:CERTIFICATE) {
"CERTIFICATE variable is empty, unable to sign the file"
Exit 1
}

$SignParameters = @("sign", "/tr", 'http://timestamp.digicert.com', "/f", $CertificateFile)
if ($env:CERTIFICATE_PASSWORD) {
"CERTIFICATE_PASSWORD detected, using the password"
$SignParameters += "/p"
$SignParameters += $env:CERTIFICATE_PASSWORD
}
$SignParameters += $Path

[byte[]]$CertificateBytes = [convert]::FromBase64String($env:CERTIFICATE)
[IO.File]::WriteAllBytes($CertificateFile, $CertificateBytes)

&$SignTool $SignParameters

if (0 -eq $LASTEXITCODE) {
Remove-Item $CertificateFile
} else {
Remove-Item $CertificateFile
"Signing failed"
Exit 1
}

}

SignInstaller ${Path}
Binary file added build_tools/espressif.ico
Binary file not shown.

0 comments on commit 9305da8

Please sign in to comment.