diff --git a/.github/workflows/platformio_publish_template.yml b/.github/workflows/platformio_publish_template.yml new file mode 100644 index 0000000..cc6b11a --- /dev/null +++ b/.github/workflows/platformio_publish_template.yml @@ -0,0 +1,69 @@ +name: PlatformIO Publish + +on: + workflow_call: + inputs: + pkg-owner: + type: string + description: The user/org that will be the owner of the published package + default: "sensirion" + should-publish: + type: boolean + description: Should the package be published to the registry + default: false + secrets: + pio-registry-token: + description: PlatformIO Token used to login + required: true + +jobs: + platformio-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio + - uses: actions/setup-python@v4 + with: + python-version: "3.9" + - name: Install PlatformIO Core + run: pip install --upgrade platformio + - name: Recreate tmp folder + run: | + if [ -d ./tmp/ ]; then rm -Rf ./tmp/; fi + mkdir ./tmp/ + - name: Select relevant resource to package + run: | + cp -r examples tmp + cp -r src tmp + cp -r py_scripts tmp + cp CHANGELOG.md tmp + cp library.properties tmp + cp LICENSE tmp + cp platformio.ini tmp + cp README.md tmp + - name: Remove 'Sensirion' from lib name + run: | + nameline=$(head -n 1 tmp/library.properties) + toremove='Sensirion ' + pioname="${nameline/$toremove/}" + sed -i "1s/.*/$pioname/" tmp/library.properties + - name: Create library package + run: pio pkg pack tmp + - name: Upload package archive + uses: actions/upload-artifact@v4 + with: + name: pio-library-archive + path: /*.tar.gz + retention-days: 2 + - name: Login into PlatformIO + run: pio account login + env: + PLATFORMIO_AUTH_TOKEN: ${{ secrets.pio-registry-token }} + - name: Run 'pio pkg publish' + if: ${{ inputs.should-publish }} + run: pio pkg publish --owner ${{ inputs.pkg-owner }} --no-interactive ./*.tar.gz diff --git a/make_cpp_files.py b/make_cpp_files.py deleted file mode 100644 index 389c629..0000000 --- a/make_cpp_files.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - -# Create a .cpp file for all the .ino files in the examples dir (CAUTION: will overwrite existing) -print("PRE_SCRIPT: Copying .ino file contents to .cpp files.") -os.system(f'find examples -type f -name "*.ino" -exec bash -c \'for file; do cp "$file" "$(dirname "$file")/$(basename "$file" .ino).cpp"; done\' _ {{}} +') diff --git a/platformio.ini b/platformio.ini index b2c1a2d..0755dae 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,7 +16,7 @@ framework = arduino platform = espressif32 board = lilygo-t-display-s3 extra_scripts = - pre:make_cpp_files.py + pre:py_scripts/make_cpp_files.py monitor_speed = 115200 lib_ldf_mode = deep lib_extra_dirs = ${PROJECT_DIR}/src/ diff --git a/py_scripts/make_cpp_files.py b/py_scripts/make_cpp_files.py new file mode 100644 index 0000000..405468d --- /dev/null +++ b/py_scripts/make_cpp_files.py @@ -0,0 +1,16 @@ +import os +import shutil + +ARDUINO_FILE_EXTENSION = ".ino" +TARGET_FILE_EXTENSION = ".cpp" +EXAMPLE_FOLDER = "examples" + +# Create a .cpp file for all the .ino files in the examples dir (CAUTION: will overwrite existing) +print("PRE_SCRIPT: Copying .ino file contents to .cpp files.") +for e in os.listdir(EXAMPLE_FOLDER): + if os.path.isdir(f"{EXAMPLE_FOLDER}/{e}") and os.path.isfile(f"{EXAMPLE_FOLDER}/{e}/{e}{ARDUINO_FILE_EXTENSION}"): + arduino_file =f"{EXAMPLE_FOLDER}/{e}/{e}{ARDUINO_FILE_EXTENSION}" + cpp_file = f"{EXAMPLE_FOLDER}/{e}/{e}{TARGET_FILE_EXTENSION}" + shutil.copyfile(arduino_file, cpp_file) + print(f'\tcopied {arduino_file} to {cpp_file}') +print("\t>> Done.")