diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..3f052e9 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,4 @@ +[codespell] +skip = *.bin,test/images/efuse/*,docs/en/espefuse/inc/* +ignore-words-list = bloc,ser,dout,exten +write-changes = false diff --git a/.cz.toml b/.cz.toml new file mode 100644 index 0000000..cca4ea5 --- /dev/null +++ b/.cz.toml @@ -0,0 +1,24 @@ +[tool.commitizen] +version = "4.7.0" +update_changelog_on_bump = true +tag_format = "v$version" +changelog_start_rev = "v4.2.1" +changelog_merge_prerelease = true +annotated_tag = true +bump_message = "change: Update version to $new_version" +version_files = [ + "esptool/__init__.py:__version__" +] +change_type_order = [ + "BREAKING CHANGE", + "New Features", + "Bug Fixes", + "Code Refactoring", + "Performance Improvements" +] + +[tool.commitizen.change_type_map] +feat = "New Features" +fix = "Bug Fixes" +refactor = "Code Refactoring" +perf = "Performance Improvements" \ No newline at end of file diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml new file mode 100644 index 0000000..6171928 --- /dev/null +++ b/.github/workflows/create_release.yml @@ -0,0 +1,46 @@ +name: Build stubs + +on: [push, pull_request] + +jobs: + create_release: + name: Create GitHub release + if: startsWith(github.ref, 'refs/tags/') && !(contains(github.ref_name, 'dev')) + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Get version + id: get_version + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT + shell: bash + - name: Checkout + uses: actions/checkout@master + with: + fetch-depth: 0 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --user -e ".[dev]" + - name: Generate changelog + run: | + cz changelog ${{ steps.get_version.outputs.VERSION }} --template ci/gh_changelog_template.md.j2 --file-name changelog_body.md + cat changelog_body.md + - name: Download built binaries + uses: actions/download-artifact@master + - name: Compress and rename binaries + run: | + for dir in esptool-*; do + zip -r "esptool-v${{ steps.get_version.outputs.VERSION }}-${dir#esptool-}.zip" "$dir" + done + - name: Create release + id: create_release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + body_path: changelog_body.md + name: Version ${{ steps.get_version.outputs.VERSION }} + draft: true + prerelease: false + files: esptool-v${{ steps.get_version.outputs.VERSION }}-*.zip diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml new file mode 100644 index 0000000..b302469 --- /dev/null +++ b/.github/workflows/test_build.yml @@ -0,0 +1,64 @@ +name: Test esptool + +on: [push, pull_request] + +jobs: + test_esptool: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + + steps: + - name: Checkout ref commit + uses: actions/checkout@master + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@master + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools + + - name: SoftHSM2 setup + run: | + sudo apt-get update + sudo apt-get install -y softhsm2 + sudo chmod -R a+rx /etc/softhsm + sudo chmod a+r /etc/softhsm/softhsm2.conf + sudo chown -R $(whoami) /var/lib/softhsm + ./ci/setup_softhsm2.sh || exit 1 + + - name: Install esptool and check if the installed versions can run + run: | + python setup.py build + pip install --extra-index-url https://dl.espressif.com/pypi -e .[dev,hsm] + esptool.py --help + espefuse.py --help + espsecure.py --help + + - name: Test esptool and components + run: | + pytest -m host_test + pytest test/test_espsecure_hsm.py + + - name: Build stub (Python 3.7 only) + if: matrix.python-version == 3.7 + run: | + export TOOLCHAIN_DIR=$HOME/toolchain + + export ESP8266_BINDIR=$TOOLCHAIN_DIR/xtensa-lx106-elf/bin + export ESP32_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32-elf/bin + export ESP32S2_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32s2-elf/bin + export ESP32S3_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32s3-elf/bin + export ESP32C3_BINDIR=$TOOLCHAIN_DIR/riscv32-esp-elf/bin + + export PATH=$PATH:$ESP8266_BINDIR:$ESP32_BINDIR:$ESP32S2_BINDIR:$ESP32S3_BINDIR:$ESP32C3_BINDIR + + ./ci/setup_ci_build_env.sh + make -C flasher_stub V=1 + cd flasher_stub && python ./compare_stubs.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5570e40 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +repos: + - repo: https://github.com/codespell-project/codespell + rev: v2.2.5 + hooks: + - id: codespell + - repo: https://github.com/espressif/conventional-precommit-linter + rev: v1.4.0 + hooks: + - id: conventional-precommit-linter + stages: [commit-msg] +default_stages: [commit] +default_install_hook_types: [pre-commit, commit-msg] diff --git a/ci/gh_changelog_template.md.j2 b/ci/gh_changelog_template.md.j2 new file mode 100644 index 0000000..5dc2df5 --- /dev/null +++ b/ci/gh_changelog_template.md.j2 @@ -0,0 +1,28 @@ +{# This changelog template is used for automatically generated GH release notes. #} +{# It is passed to commitizen's --template option in a GH Actions workflow run. #} + +{% for entry in tree %} + +{% for change_key, changes in entry.changes.items() %} + +{% if change_key %} +### {{ change_key }} +{% endif %} + +{% for change in changes %} +{% if change.scope %} +- **{{ change.scope }}**: {{ change.message }} +{% elif change.message %} +- {{ change.message }} +{% endif %} +{% endfor %} +{% endfor %} +{% endfor %} + +Thanks to , and others for contributing to this release! + +# Results of checking the release against common anti-virus SW + + + +The failures are probably false positives. You can mark esptool as safe in your anti-virus SW, or [install esptool from source](https://docs.espressif.com/projects/esptool/en/latest/installation.html). diff --git a/ci/setup_ci_build_env.sh b/ci/setup_ci_build_env.sh new file mode 100755 index 0000000..178bd0e --- /dev/null +++ b/ci/setup_ci_build_env.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -exuo pipefail + +ESP8266_TOOLCHAIN_URL="https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-92-g8facf4c-5.2.0.tar.gz" +ESP32_TOOLCHAIN_URL="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1/xtensa-esp32-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz" +ESP32S2_TOOLCHAIN_URL="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1/xtensa-esp32s2-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz" +ESP32S3_TOOLCHAIN_URL="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1/xtensa-esp32s3-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz" +ESP32C3_TOOLCHAIN_URL="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz" + +# Setup shell script to download & configure ESP8266 & ESP32 toolchains +# for building the flasher stub program + +mkdir -p ${TOOLCHAIN_DIR} +cd ${TOOLCHAIN_DIR} + +if ! [ -d ${ESP8266_BINDIR} ]; then + wget --continue --no-verbose "${ESP8266_TOOLCHAIN_URL}" + tar zxf $(basename ${ESP8266_TOOLCHAIN_URL}) +fi + +if ! [ -d ${ESP32_BINDIR} ]; then + # gitlab CI image may already have this file + wget --continue --no-verbose "${ESP32_TOOLCHAIN_URL}" + tar Jxf $(basename ${ESP32_TOOLCHAIN_URL}) +fi + +if ! [ -d ${ESP32S2_BINDIR} ]; then + # gitlab CI image may already have this file + wget --continue --no-verbose "${ESP32S2_TOOLCHAIN_URL}" + tar Jxf $(basename ${ESP32S2_TOOLCHAIN_URL}) +fi + +if ! [ -d ${ESP32S3_BINDIR} ]; then + # gitlab CI image may already have this file + wget --continue --no-verbose "${ESP32S3_TOOLCHAIN_URL}" + tar Jxf $(basename ${ESP32S3_TOOLCHAIN_URL}) +fi + +if ! [ -d ${ESP32C3_BINDIR} ]; then + # gitlab CI image may already have this file + wget --continue --no-verbose "${ESP32C3_TOOLCHAIN_URL}" + tar Jxf $(basename ${ESP32C3_TOOLCHAIN_URL}) +fi