diff --git a/.github/workflows/auto_tag.yml b/.github/workflows/auto_tag.yml deleted file mode 100644 index cb7f194..0000000 --- a/.github/workflows/auto_tag.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: "Create Tags" - -on: - # Start only after Build was finished - workflow_run: - workflows: [Build] - branches: [main] - types: [completed] - -jobs: - check-hsmcpp-version: - # only run for successful build after push event - # avoid running this action on forks - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && ((github.event.workflow_run == null) || ((github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'push'))) }} - - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.get_version.outputs.commit_version }} - commit_action: ${{ steps.get_version.outputs.commit_action }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - create-release-tag: - needs: check-hsmcpp-version - if: ${{ (needs.check-hsmcpp-version.outputs.commit_version != '') && (needs.check-hsmcpp-version.outputs.commit_action == 'r') }} - - runs-on: ubuntu-latest - - steps: - # need to checkout current repo because workflow is not related with push event - - uses: actions/checkout@v3 - - # prepare gpg for commit signing - - name: Import GPG key - id: import_gpg - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - workdir: ${{github.workspace}} - - - name: Commit new files - run: | - git tag ${{needs.check-hsmcpp-version.outputs.commit_version}} ${{ github.event.workflow_run.head_sha }} - git push origin ${{needs.check-hsmcpp-version.outputs.commit_version}} - diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 1687440..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,192 +0,0 @@ -name: "Build" - -on: - workflow_dispatch: - push: - branches: [ main, dev ] - pull_request: - branches: [ main, dev ] - -env: - BUILD_TYPE: Release - -jobs: - # check if it's a version update - check-hsmcpp-version: - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.get_version.outputs.commit_version }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - # validate that all metadata was updated correctly - validate-metadata: - needs: check-hsmcpp-version - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && (needs.check-hsmcpp-version.outputs.commit_version != '') }} - run: ./scripts/validate_metadata.py ${{ needs.check-hsmcpp-version.outputs.commit_version }} ./ - - # ----------------------------------------------------------------- - build-ubuntu: - needs: validate-metadata - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Build project - uses: ./.github/workflows/build_helper - with: - build_type: ${{env.BUILD_TYPE}} - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'posix' - - # ----------------------------------------------------------------- - build-windows: - needs: validate-metadata - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Build project - uses: ./.github/workflows/build_helper - with: - build_type: ${{env.BUILD_TYPE}} - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'windows' - - # ----------------------------------------------------------------- - build-platformio: - needs: validate-metadata - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - uses: ./.github/workflows/install_platformio - - # deploy files - - name: Generate package - run: | - cmake -S ./ -B ./build -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino - cmake --build ./build --target install - - - name: Copy package to examples folder - run: | - mkdir -p ./examples/09_arduino/01_blink/lib/hsmcpp - cp -Rv ./build/deploy/platformio/* ./examples/09_arduino/01_blink/lib/hsmcpp - mkdir -p ./examples/09_arduino/02_blink_button/lib/hsmcpp - cp -Rv ./build/deploy/platformio/* ./examples/09_arduino/02_blink_button/lib/hsmcpp - - # build examples - - name: Build 01_blink - run: | - cd ./examples/09_arduino/01_blink/ - pio run - - - name: Build 02_blink_button - run: | - cd ./examples/09_arduino/02_blink_button/ - pio run - - # ----------------------------------------------------------------- - build-arduinoide: - needs: validate-metadata - runs-on: ubuntu-latest - - env: - library_dir: ./build/deploy/arduinoide - example1_dir: ./build/deploy/arduinoide/examples/01_blink - example2_dir: ./build/deploy/arduinoide/examples/02_blink_button - scxml2gen_dir: ./build/deploy/arduinoide/tools/scxml2gen - hsmcpp_library: ./build/deploy/hsmcpp.zip - - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Generate hsmcpp library package - run: | - cmake -S ./ -B ./build -DHSMBUILD_TARGET=arduinoide -DHSMBUILD_PLATFORM=arduino - cmake --build ./build --target install - cp -Rv ${{ env.library_dir }} ./build/deploy/hsmcpp - cd ./build/deploy/ - zip -r ./hsmcpp.zip ./hsmcpp - - - name: Generate HSM files - run: | - python3 ${{ env.scxml2gen_dir }}/scxml2gen.py -code -scxml ${{ env.example1_dir }}/blink.scxml \ - -class_name BlinkHsm \ - -class_suffix Base \ - -template_hpp ${{ env.scxml2gen_dir }}/template.hpp \ - -template_cpp ${{ env.scxml2gen_dir }}/template.cpp \ - -dest_dir ${{ env.example1_dir }}/ - python3 ${{ env.scxml2gen_dir }}/scxml2gen.py -code -scxml ${{ env.example2_dir }}/blink_button.scxml \ - -class_name BlinkButtonHsm \ - -class_suffix Base \ - -template_hpp ${{ env.scxml2gen_dir }}/template.hpp \ - -template_cpp ${{ env.scxml2gen_dir }}/template.cpp \ - -dest_dir ${{ env.example2_dir }}/ - - - name: Setup Arduino CLI - uses: arduino/setup-arduino-cli@v1.1.1 - - - name: Install platform files - run: | - arduino-cli core update-index --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json - arduino-cli core install esp8266:esp8266 --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json - - - name: Install hsmcpp library - run: | - arduino-cli config init - arduino-cli config set library.enable_unsafe_install true - arduino-cli lib install --zip-path ${{ env.hsmcpp_library }} - - - name: Compile Sketch 01 - run: arduino-cli compile --fqbn esp8266:esp8266:d1_mini ${{ env.example1_dir }}/ --warnings more - - - name: Compile Sketch 02 - run: arduino-cli compile --fqbn esp8266:esp8266:d1_mini ${{ env.example2_dir }}/ --warnings more - - # ----------------------------------------------------------------- - build-freertos: - needs: validate-metadata - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - path: './source' - submodules: 'recursive' - - - uses: actions/checkout@v3 - with: - repository: 'FreeRTOS/FreeRTOS' - ref: '202212.00' - submodules: 'recursive' - path: './FreeRTOS' - - # build FreeRTOS example - - name: Build 08_freertos - run: | - cd ./source/examples/08_freertos - ./build.sh '${{github.workspace}}/FreeRTOS' diff --git a/.github/workflows/build_helper/action.yml b/.github/workflows/build_helper/action.yml deleted file mode 100644 index 17c6aaf..0000000 --- a/.github/workflows/build_helper/action.yml +++ /dev/null @@ -1,132 +0,0 @@ -name: "Build Helper" - -inputs: - # values: posix, windows - platform: - required: true - type: string - default: 'posix' - src_dir: - required: true - type: string - build_dir: - required: true - type: string - # values: Release, Debug - build_type: - required: false - type: string - default: 'Release' - build_glib: - required: false - type: string - default: 'ON' - build_glibmm: - required: false - type: string - default: 'ON' - build_qt: - required: false - type: string - default: 'ON' - build_std: - required: false - type: string - default: 'ON' - build_tests: - required: false - type: string - default: 'ON' - build_examples: - required: false - type: string - default: 'ON' - codecoverage: - required: false - type: string - default: 'OFF' - only_configure: - required: false - type: boolean - default: false - -runs: - using: "composite" - - steps: - # --------------------------------- Ubuntu build --------------------------------- - - uses: awalsh128/cache-apt-pkgs-action@v1.2.2 - if: ${{ (inputs.platform == 'posix') && ((inputs.build_glib == 'ON') || (inputs.build_glibmm == 'ON')) }} - with: - packages: libglibmm-2.4-dev - version: 1.0 - - - name: Install Qt (Ubuntu) - if: ${{ (inputs.platform == 'posix') && (inputs.build_qt == 'ON') }} - uses: jurplel/install-qt-action@v3 - with: - version: '6.4.*' - host: 'linux' - target: 'desktop' - arch: 'gcc_64' - modules: '' - cache: 'true' - cache-key-prefix: 'install-qt-action-linux' - set-env: 'true' - - - name: Configure CMake (Ubuntu) - if: ${{ inputs.platform == 'posix' }} - shell: bash - run: | - cmake -B ${{ inputs.build_dir }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} \ - -DHSMBUILD_VERBOSE=OFF \ - -DHSMBUILD_PLATFORM=${{ inputs.platform }} \ - -DHSMBUILD_DISPATCHER_GLIB=${{ inputs.build_glib }} \ - -DHSMBUILD_DISPATCHER_GLIBMM=${{ inputs.build_glibmm }} \ - -DHSMBUILD_DISPATCHER_STD=${{ inputs.build_std }} \ - -DHSMBUILD_DISPATCHER_QT=${{ inputs.build_qt }} \ - -DHSMBUILD_TESTS=${{ inputs.build_tests }} \ - -DHSMBUILD_EXAMPLES=${{ inputs.build_examples }} \ - -DHSMBUILD_CODECOVERAGE=${{ inputs.codecoverage }} \ - -DHSMBUILD_DEBUGGING=ON \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - ${{ inputs.src_dir }} - - - name: Build (Ubuntu) - if: ${{ (inputs.platform == 'posix') && (inputs.only_configure == 'false') }} - shell: bash - run: cmake --build ${{ inputs.build_dir }} --parallel 2 --config ${{ inputs.build_type }} - - # --------------------------------- Windows build --------------------------------- - - name: Install Qt (Windows) - if: ${{ (inputs.platform == 'windows') && (inputs.build_qt == 'ON') }} - uses: jurplel/install-qt-action@v3 - with: - version: '6.4.*' - host: 'windows' - target: 'desktop' - arch: 'win64_msvc2019_64' - modules: '' - cache: 'true' - cache-key-prefix: 'install-qt-action-win32' - set-env: 'true' - - - name: Configure CMake (Windows) - if: ${{ inputs.platform == 'windows' }} - shell: cmd - run: cmake -B ${{github.workspace}}\build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ^ - -DHSMBUILD_VERBOSE=OFF ^ - -DHSMBUILD_PLATFORM=${{ inputs.platform }} ^ - -DHSMBUILD_DISPATCHER_GLIB=OFF ^ - -DHSMBUILD_DISPATCHER_GLIBMM=OFF ^ - -DHSMBUILD_DISPATCHER_STD=ON ^ - -DHSMBUILD_DISPATCHER_QT=ON ^ - -DHSMBUILD_TESTS=ON ^ - -DHSMBUILD_EXAMPLES=ON ^ - -DHSMBUILD_DEBUGGING=ON ^ - ${{ inputs.src_dir }} - - - name: Build (Windows) - if: ${{ (inputs.platform == 'windows') && (inputs.only_configure == 'false') }} - shell: cmd - run: cmake --build ${{github.workspace}}\build --parallel 2 --config ${{env.BUILD_TYPE}} \ No newline at end of file diff --git a/.github/workflows/ci_pipeline.yml b/.github/workflows/ci_pipeline.yml new file mode 100644 index 0000000..651c2f5 --- /dev/null +++ b/.github/workflows/ci_pipeline.yml @@ -0,0 +1,117 @@ +name: "CI/CD" + +on: + workflow_dispatch: + push: + branches: + - "**" + pull_request: + branches: [ main, dev ] + + +jobs: + verify: + if: > + github.event_name == 'pull_request' || + (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')) + uses: igor-krechetov/hsm-github-workflows/.github/workflows/verify.yml@feature/hsmcpp-ci-integration + + # -------------------------------------------------------- + build: + needs: verify + uses: igor-krechetov/hsm-github-workflows/.github/workflows/build.yml@feature/hsmcpp-ci-integration + if: > + always() && + (needs.verify.result == 'success' || needs.verify.result == 'skipped') + with: + build_type: Release + platforms: "posix,windows,platformio,arduinoide,freertos" + install_qt: 'ON' + install_glibmm: 'ON' + build_tests: 'ON' + + # -------------------------------------------------------- + test: + needs: build + if: always() && (needs.build.result == 'success') + uses: igor-krechetov/hsm-github-workflows/.github/workflows/test.yml@feature/hsmcpp-ci-integration + with: + platform: 'ubuntu' + install_qt: 'ON' + install_glibmm: 'ON' + + # -------------------------------------------------------- + sast: + needs: build + if: always() && (needs.build.result == 'success') + uses: igor-krechetov/hsm-github-workflows/.github/workflows/sast.yml@feature/hsmcpp-ci-integration + + # -------------------------------------------------------- + autotag: + needs: [verify, build, test, sast] + if: > + (github.event_name == 'push' && github.ref_name == 'main') && + needs.build.result == 'success' && + needs.test.result == 'success' && + needs.sast.result == 'success' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/autotag.yml@main + with: + commit_version: ${{ needs.verify.outputs.commit_version }} + commit_action: ${{ needs.verify.outputs.commit_action }} + commit_sha: ${{ github.sha }} + + # -------------------------------------------------------- + update_documentation: + needs: [verify, autotag] + if: > + (github.event_name == 'push' && github.ref_name == 'main') && + needs.verify.result == 'success' && + needs.autotag.result == 'success' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/update-docs.yml@feature/hsmcpp-ci-integration + with: + library_name: hsmcpp + commit_version: ${{ needs.verify.outputs.commit_version }} + secrets: + HSMCPP_BOT_TOKEN: ${{ secrets.HSMCPP_BOT_TOKEN }} + BOT_GPG_PRIVATE_KEY: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + BOT_GPG_PASSPHRASE: ${{ secrets.BOT_GPG_PASSPHRASE }} + + # -------------------------------------------------------- + release: + needs: [verify, update_documentation] + if: > + (github.event_name == 'push' && github.ref_name == 'main') && + needs.verify.outputs.commit_action == 'r' && + needs.verify.result == 'success' && + needs.update_documentation.result == 'success' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/release.yml@feature/hsmcpp-ci-integration + with: + commit_sha: ${{ github.sha }} + tag_version: ${{ needs.update_documentation.outputs.tag_name }} + builds: "build-artifacts-ubuntu,build-artifacts-windows" + release_description: | + Release ${{ needs.update_documentation.outputs.tag_name }} + + - Built on Ubuntu and Windows + - Includes binaries for both platforms + + # -------------------------------------------------------- + deploy: + needs: [verify, release] + if: > + (github.event_name == 'push' && github.ref_name == 'main') && + needs.release.result == 'success' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/deploy.yml@feature/hsmcpp-ci-integration + with: + deploy_target: "platformio,arduinoide" + commit_sha: ${{ needs.check-hsmcpp-version.outputs.commit_sha }} + commit_version: ${{ needs.check-hsmcpp-version.outputs.commit_version }} + target_repo: igor-krechetov/hsmcpp + platformio_target_branch: platformio_library + secrets: + HSMCPP_BOT_TOKEN: ${{ secrets.HSMCPP_BOT_TOKEN }} + BOT_GPG_PRIVATE_KEY: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + BOT_GPG_PASSPHRASE: ${{ secrets.BOT_GPG_PASSPHRASE }} + PLATFORMIO_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }} + + diff --git a/.github/workflows/deploy-arduinoide.yml b/.github/workflows/deploy-arduinoide.yml deleted file mode 100644 index 017daf6..0000000 --- a/.github/workflows/deploy-arduinoide.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: "Deploy ArduinoIDE library" - -on: - workflow_dispatch: - # Start only after Build was finished - workflow_run: - workflows: [Build] - branches: [main] - types: [completed] - -jobs: - check-hsmcpp-version: - # only run for successful build after push event - # avoid running this action on forks - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && ((github.event.workflow_run == null) || ((github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'push'))) }} - - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.get_version.outputs.commit_version }} - commit_action: ${{ steps.get_version.outputs.commit_action }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - deploy-arduinoide: - needs: check-hsmcpp-version - # only if commit has version defined and is a release commit - if: ${{ (needs.check-hsmcpp-version.outputs.commit_version != '') && (needs.check-hsmcpp-version.outputs.commit_action == 'r') }} - - runs-on: ubuntu-latest - - env: - target_dir: './arduinoide_deploy/' - library_dir: './main/build/deploy/hsmcpp' - - steps: - # need to checkout current repo because workflow is not related with push event - - uses: actions/checkout@v3 - - # checkout repositories - - uses: actions/checkout@v3 - with: - path: './main' - - uses: actions/checkout@v3 - with: - repository: 'igor-krechetov/hsmcpp-arduinoide' - token: ${{ secrets.HSMCPP_BOT_TOKEN }} - ref: main - path: ${{ env.target_dir }} - - # prepare gpg for commit signing - - name: Import GPG key - id: import_gpg - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - workdir: ${{ env.target_dir }} - - # deploy files - - name: Generate hsmcpp package - run: | - cmake -S ./main -B ./main/build -DHSMBUILD_TARGET=arduinoide -DHSMBUILD_PLATFORM=arduino - cmake --build ./main/build --target install - mv ./main/build/deploy/arduinoide ${{ env.library_dir }} - - - name: Install arduino-lint - run: | - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | BINDIR=./ sh - - - name: Validate arduino library structure - run: | - ./arduino-lint --compliance strict --recursive --library-manager update ${{ env.library_dir }} - - - name: Copy package files to target repository - run: cp -Rv ${{ env.library_dir }}/* "$target_dir" - - - name: Prepare commit message - run: | - cd ./main - git log -1 --format=%B ${{ github.event.workflow_run.head_sha }} > ../commit.txt - - - name: Publish ArduinoIDE package - run: | - cd "$target_dir" - git add -A - git commit -S -F ../commit.txt - git tag ${{needs.check-hsmcpp-version.outputs.commit_version}} - git push - git push --tags \ No newline at end of file diff --git a/.github/workflows/deploy-platformio.yml b/.github/workflows/deploy-platformio.yml deleted file mode 100644 index f1f6f43..0000000 --- a/.github/workflows/deploy-platformio.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: "Deploy PlatformIO library" - -on: - workflow_dispatch: - inputs: - version: - type: string - # Start only after Build was finished - workflow_run: - workflows: [Build] - branches: [main] - types: [completed] - -jobs: - check-hsmcpp-version: - # only run for successful build after push event - # avoid running this action on forks - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && ((github.event.workflow_run == null) || ((github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'push'))) }} - - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.finalize_version.outputs.commit_version }} - commit_action: ${{ steps.get_version.outputs.commit_action }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - - name: Check user input - if: ${{ github.event.inputs.version != '' }}" - id: check_user_input - run: | - echo "TEMP_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV - - - name: Check commit version - id: check_commit - if: ${{ github.event.inputs.version == '' }} - run: | - echo "TEMP_VERSION=${{ steps.get_version.outputs.commit_version }}" >> $GITHUB_ENV - - - name: Final - id: finalize_version - run: | - echo "commit_version=$TEMP_VERSION" >> $GITHUB_OUTPUT - - deploy-platformio: - runs-on: ubuntu-latest - needs: check-hsmcpp-version - - # only run for successful build after push event - # avoid running this action on forks - if: ${{ (needs.check-hsmcpp-version.outputs.commit_version != '') }} - - env: - target_dir: './platformio_deploy/' - - steps: - # need to checkout current repo because workflow is not related with push event - - uses: actions/checkout@v3 - - uses: ./.github/workflows/install_platformio - - # checkout repositories - - uses: actions/checkout@v3 - with: - ref: main - path: './main' - - uses: actions/checkout@v3 - with: - ref: platformio_library - path: ${{ env.target_dir }} - - # prepare gpg for commit signing - - name: Import GPG key - id: import_gpg - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - workdir: ${{ env.target_dir }} - - # deploy files - - name: Generate package - run: | - cmake -S ./main -B ./main/build -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino - cmake --build ./main/build --target install - - - name: Copy package files to target repository - run: cp -Rv ./main/build/deploy/platformio/* "$target_dir" - - - name: Publish PlatformIO package - # only publish release versions or when started manually - if: ${{ (needs.check-hsmcpp-version.outputs.commit_action == 'r') || (github.event.inputs.version != '') }} - env: - PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }} - # $PWD is needed due to an issue in "pio pkg publish". It usese os.path.isdir() and sometimes it doesn't not - # recognize relative path as a directory - run: | - pio pkg publish --type library --no-interactive $PWD/main/build/deploy/platformio/ - - - name: Prepare commit message - run: | - cd ./main - git log -1 --format=%B ${{ github.event.workflow_run.head_sha }} > ../commit.txt - - - name: Commit new files - run: | - cd "$target_dir" - git add -A - git commit -S -F ../commit.txt - git push diff --git a/.github/workflows/install_platformio/action.yml b/.github/workflows/install_platformio/action.yml deleted file mode 100644 index ec50751..0000000 --- a/.github/workflows/install_platformio/action.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: "Install PlatformIO" - -runs: - using: "composite" - - steps: - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Cache PlatformIO - uses: actions/cache@v3 - with: - path: ~/.platformio - key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - - name: Set up Python - uses: actions/setup-python@v4 - - name: Install PlatformIO - shell: bash - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio diff --git a/.github/workflows/sca_codeql.yml b/.github/workflows/sca_codeql.yml deleted file mode 100644 index c0c8786..0000000 --- a/.github/workflows/sca_codeql.yml +++ /dev/null @@ -1,72 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "SCA: CodeQL" - -# TODO: run only on successfull builds -on: - workflow_dispatch: - push: - branches: [ main, dev ] - pull_request: - branches: [ main, dev ] - -env: - BUILD_TYPE: Release - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: cpp - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - name: Build project - uses: ./.github/workflows/build_helper - with: - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'posix' - build_tests: 'OFF' - build_examples: 'ON' - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:cpp" diff --git a/.github/workflows/sca_coverity.yml b/.github/workflows/sca_coverity.yml deleted file mode 100644 index 60ea4a7..0000000 --- a/.github/workflows/sca_coverity.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: "SCA: Coverity" - -on: - workflow_dispatch: - inputs: - version: - type: string - push: - branches: [ main ] - -env: - BUILD_TYPE: Release - -jobs: - check-hsmcpp-version: - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.finalize_version.outputs.commit_version }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - - name: Check user input - if: ${{ github.event.inputs.version != '' }}" - id: check_user_input - run: | - echo "TEMP_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV - - - name: Check commit version - id: check_commit - if: ${{ github.event.inputs.version == '' }} - run: | - echo "TEMP_VERSION=${{ steps.get_version.outputs.commit_version }}" >> $GITHUB_ENV - - - name: Final - id: finalize_version - run: | - echo "commit_version=$TEMP_VERSION" >> $GITHUB_OUTPUT - - sca-coverity: - needs: check-hsmcpp-version - # only run when started manually or if there is a version change - if: ${{ needs.check-hsmcpp-version.outputs.commit_version != '' }} - runs-on: ubuntu-latest - - env: - COVERITY_NAME: 'Igor Krechetov' - COVERITY_VERSION: 'cov-analysis-linux64-2023.6.2' - COVERITY_PROJECT_DESCRIPTION: 'C++ library for hierarchical state machines / finite state machines. Provides a code-free visual approach for defining state machine logic using GUI editors with automatic code and diagram generation. Check out https://hsmcpp.readthedocs.io for detailed documentation.' - COVERITY_PROJECT: 'igor-krechetov/hsmcpp' - COVERITY_PROJECT_URL: 'igor-krechetov%2Fhsmcpp' - BUILDCMD: 'cmake --build ./build --parallel 2 --config Release' - - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 11 - - name: Cache Coverity - id: cache-coverity - uses: actions/cache@v3 - with: - path: ~/coverity - key: coverity-tool - restore-keys: coverity-tool - - - name: Coverity Download & Install - if: ${{ steps.cache-coverity.outputs.cache-hit != 'true' }} - run: | - mkdir -p ~/download - mkdir -p ~/coverity - wget https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_TOKEN }}&project=$COVERITY_PROJECT_URL" -O ~/download/coverity_tool.tgz - cd ~/coverity - tar -xvzf ~/download/coverity_tool.tgz - - - name: Configure project build - uses: ./.github/workflows/build_helper - with: - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'posix' - build_tests: 'OFF' - only_configure: true - - - name: Coverity Full Scan - run: | - export PATH=$PATH:~/coverity/$COVERITY_VERSION/bin/ - cov-configure --config ./coverity.xml --template --compiler c++ --comptype gcc --xml-option=skip_file:"/usr/include/.*" --xml-option=skip_file:".*/build/hsmcpp_qt_autogen/.*" --xml-option=skip_file:".*/build/include/hsmcpp/.*" --xml-option=skip_file:".*/thirdparty/.*" - python3 ./scripts/coverity/coverity-submit.py -u "$COVERITY_NAME" -b ${{ needs.check-hsmcpp-version.outputs.commit_version }} -config ./coverity.xml -t "$COVERITY_PROJECT_DESCRIPTION" -p "$COVERITY_PROJECT" -pu "$COVERITY_PROJECT_URL" -token "${{ secrets.COVERITY_TOKEN }}" -email "${{ secrets.COVERITY_EMAIL }}" -build "$BUILDCMD" diff --git a/.github/workflows/sca_misra.yml b/.github/workflows/sca_misra.yml deleted file mode 100644 index d43181a..0000000 --- a/.github/workflows/sca_misra.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: "SCA: MISRA-C-2012" - -# TODO: run only on successfull builds -on: - workflow_dispatch: - push: - branches: [ main, dev ] - pull_request: - branches: [ main, dev ] - -env: - BUILD_TYPE: Release - -jobs: - sca-misra: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install cppcheck - uses: awalsh128/cache-apt-pkgs-action@v1.2.2 - with: - packages: cppcheck - version: 1.0 - - - name: Build project - uses: ./.github/workflows/build_helper - with: - build_type: ${{env.BUILD_TYPE}} - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'posix' - build_tests: 'OFF' - build_examples: 'ON' - - - name: Run MISRA check - run: | - cppcheck --addon=${{github.workspace}}/scripts/cppcheck/misra.json \ - --enable=warning,performance,portability,information \ - --inline-suppr \ - --xml \ - --suppressions-list=${{github.workspace}}/scripts/cppcheck/cppcheck_suppress.txt \ - --project=${{github.workspace}}/build/compile_commands.json \ - -DSTL_AVAILABLE -D__GNU__=1 -D__LITTLE_ENDIAN__ -D__GNUC__ 2> ${{github.workspace}}/sca_misra.txt - - - name: Validate cppcheck report - run: | - ${{github.workspace}}/scripts/cppcheck/cppcheck_review.py ${{github.workspace}}/sca_misra.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index d718034..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,129 +0,0 @@ -name: "Unit Tests" - -on: - workflow_dispatch: - push: - branches: [ main ] - -env: - BUILD_TYPE: Debug - -jobs: - check-hsmcpp-version: - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') }} - - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.get_version.outputs.commit_version }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - run-tests: - needs: check-hsmcpp-version - # only run when started manually or if there is a version change - if: ${{ (needs.check-hsmcpp-version.outputs.commit_version != '') || (github.event_name == 'workflow_dispatch') }} - runs-on: ubuntu-latest - - env: - artifacts_dir: "${{github.workspace}}/build_artifacts/" - # For debuging Coveralls - # NODE_COVERALLS_DEBUG: 1 - - steps: - - uses: awalsh128/cache-apt-pkgs-action@v1.2.2 - with: - packages: lcov - version: 1.0 - - # checkout repositories - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - ref: ${{ github.ref }} - - # build tests - - name: Build tests - uses: ./.github/workflows/build_helper - with: - src_dir: ${{github.workspace}} - build_dir: ${{github.workspace}}/build - platform: 'posix' - build_examples: 'OFF' - codecoverage: 'ON' - - - name: Run Tests (STD) - run: | - cd ${{github.workspace}}/build/ - timeout 2m ./tests/hsmUnitTestsSTD > ./tests_result_std.log - lcov -c -d . -o ./coverage_std.info - - name: Run Tests (GLib) - run: | - cd ${{github.workspace}}/build/ - timeout 2m ./tests/hsmUnitTestsGLib > ./tests_result_glib.log - lcov -c -d . -o ./coverage_glib.info - - name: Run Tests (GLibmm) - run: | - cd ${{github.workspace}}/build/ - timeout 2m ./tests/hsmUnitTestsGLibmm > ./tests_result_glibmm.log - lcov -c -d . -o ./coverage_glibmm.info - - name: Run Tests (Qt) - run: | - cd ${{github.workspace}}/build/ - timeout 2m ./tests/hsmUnitTestsQt > ./tests_result_qt.log - lcov -c -d . -o ./coverage_qt.info - - - name: Generate Coverage - run: | - cd ${{github.workspace}}/build/ - lcov --add-tracefile ./coverage_std.info \ - -a ./coverage_glib.info \ - -a ./coverage_qt.info \ - -a ./coverage_glibmm.info \ - -o ./coverage.info - lcov -r ./coverage.info /usr/include/\* . -o ./coverage.info - lcov -r ./coverage.info \*/build/\* . -o ./coverage.info - lcov -r ./coverage.info \*/tests/\* . -o ./coverage.info - lcov -r ./coverage.info \*/gcc_64/include/QtCore/\* . -o ./coverage.info - lcov -r ./coverage.info \*/thirdparty/\* . -o ./coverage.info - - - name: Push test coverage to Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ${{github.workspace}}/build/coverage.info - - # checkout artifacts branch - - uses: actions/checkout@v3 - with: - ref: build_artifacts - path: './build_artifacts' - - # prepare GPG - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - workdir: './build_artifacts' - - # Upload test artifacts - - name: Copy test results to artifacts folder - run: | - cp ${{github.workspace}}/build/tests_result_* ${{ env.artifacts_dir }} - - - name: Push test artifacts to branch - run: | - cd ${{ env.artifacts_dir }} - git add -A ./ - git commit -S -am "[auto] build artifacts for commit ${{ github.sha }}" - git push - diff --git a/.github/workflows/update-doc.yml b/.github/workflows/update-doc.yml deleted file mode 100644 index 38e7028..0000000 --- a/.github/workflows/update-doc.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: "Update Documentation" - -on: - workflow_dispatch: - # Start only after Build was finished - workflow_run: - workflows: [Build] - branches: [main] - types: [completed] - -jobs: - check-hsmcpp-version: - # only run for successful build after push event - # avoid running this action on forks - if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && ((github.event.workflow_run == null) || ((github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'push'))) }} - - runs-on: ubuntu-latest - outputs: - commit_version: ${{ steps.get_version.outputs.commit_version }} - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/workflows/get-commit-version - id: get_version - with: - repo_dir: ${{ env.GITHUB_WORKSPACE }} - commit_sha: ${{ github.event.workflow_run.head_sha }} - - update-doc-src: - runs-on: ubuntu-latest - needs: check-hsmcpp-version - - # only run for commits which have version defined - if: ${{ needs.check-hsmcpp-version.outputs.commit_version != '' }} - - env: - target_dir: './hsmcpp_doc' - - steps: - # checkout docs repository - - uses: actions/checkout@v3 - with: - repository: 'igor-krechetov/hsmcpp-doc' - token: ${{ secrets.HSMCPP_BOT_TOKEN }} - ref: main - submodules: 'recursive' - path: ${{ env.target_dir }} - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - workdir: ${{ env.target_dir }} - - - name: Update to latest hsmcpp - run: | - cd ${{ env.target_dir }} - git submodule foreach git fetch --all - git submodule foreach git reset --hard origin/main - git add ./source/hsmcpp - - # Update documentation only if commit had version defined - - name: Update documentation - run: | - cd ${{ env.target_dir }} - echo "Found new hsmcpp version '${{ needs.check-hsmcpp-version.outputs.commit_version }}'" - git commit -S -am "[auto] hsmcpp library updated to ${{ needs.check-hsmcpp-version.outputs.commit_version }}" - git push diff --git a/ci_reference/example/build.yml b/ci_reference/example/build.yml new file mode 100644 index 0000000..20803a9 --- /dev/null +++ b/ci_reference/example/build.yml @@ -0,0 +1,89 @@ +name: "CI/CD for HSM IDE" + +on: + push: + branches: + - main + - dev + - "**" # allow other branches to trigger build+test + pull_request: + branches: + - main + - dev + +jobs: + # -------------------------------------------------------- + # VERIFY — only on main/dev (push or PR) + # -------------------------------------------------------- + verify: + if: > + github.ref_name == 'main' || + github.ref_name == 'dev' || + github.event_name == 'pull_request' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/verify.yml@main + + # -------------------------------------------------------- + # BUILD — always runs (even if verify is skipped) + # -------------------------------------------------------- + build: + needs: verify + uses: igor-krechetov/hsm-github-workflows/.github/workflows/build.yml@main + if: > + always() && + (needs.verify.result == 'success' || needs.verify.result == 'skipped') + with: + build_type: Release + platforms: "posix,windows" + install_qt: 'ON' + build_tests: 'ON' + + # -------------------------------------------------------- + # TEST — always runs after build + # -------------------------------------------------------- + test: + needs: build + uses: igor-krechetov/hsm-github-workflows/.github/workflows/test.yml@main + if: > + always() && (needs.build.result == 'success') + with: + test_script: "validate.sh" + + # -------------------------------------------------------- + # AUTOTAG — only on push to *dev* + # -------------------------------------------------------- + autotag: + needs: [test, verify] + if: github.event_name == 'push' && github.ref_name == 'dev' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/autotag.yml@main + with: + commit_version: ${{ needs.verify.outputs.commit_version }} + commit_action: ${{ needs.verify.outputs.commit_action }} + commit_sha: ${{ github.sha }} + + # -------------------------------------------------------- + # DOCS — only on push to *main* + # -------------------------------------------------------- + update_documentation: + needs: test + if: github.event_name == 'push' && github.ref_name == 'main' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/update-docs.yml@main + + # -------------------------------------------------------- + # RELEASE — only on push to main (after docs) + # -------------------------------------------------------- + release: + needs: [verify, update_documentation] + if: > + github.event_name == 'push' && + github.ref_name == 'main' && + needs.verify.outputs.commit_action == 'r' + uses: igor-krechetov/hsm-github-workflows/.github/workflows/release.yml@main + with: + commit_sha: ${{ github.sha }} + tag_version: ${{ needs.update_documentation.outputs.tag_name }} + builds: "build-artifacts-ubuntu,build-artifacts-windows" + release_description: | + Release ${{ needs.update_documentation.outputs.tag_name }} + + - Built on Ubuntu and Windows + - Includes binaries for both platforms diff --git a/ci_reference/hsm-github-workflows/actions/build_helper/action.yml b/ci_reference/hsm-github-workflows/actions/build_helper/action.yml new file mode 100644 index 0000000..a294aa0 --- /dev/null +++ b/ci_reference/hsm-github-workflows/actions/build_helper/action.yml @@ -0,0 +1,131 @@ +name: "Build Helper" + +inputs: + # values: posix, windows, platformio, arduino, freertos + platform: + required: true + type: string + default: 'posix' + src_dir: + required: true + type: string + build_dir: + required: true + type: string + # values: Release, Debug + build_type: + required: false + type: string + default: 'Release' + build_glib: + required: false + type: string + default: 'OFF' + build_glibmm: + required: false + type: string + default: 'OFF' + install_qt: + required: false + type: string + default: 'OFF' + build_std: + required: false + type: string + default: 'ON' + build_tests: + required: false + type: string + default: 'OFF' + build_examples: + required: false + type: string + default: 'OFF' + codecoverage: + required: false + type: string + default: 'OFF' + only_configure: + required: false + type: boolean + default: false + cmake_args: + required: false + type: string + default: '' + +runs: + using: "composite" + + steps: + - name: Validate platform scripts directory + shell: bash + run: | + scripts_dir="$GITHUB_ACTION_PATH/../../../scripts/build/${{ inputs.platform }}" + if [ ! -d "$scripts_dir" ]; then + echo "Missing scripts directory: $scripts_dir" + exit 1 + fi + + - uses: awalsh128/cache-apt-pkgs-action@v1.6.0 + if: ${{ (inputs.platform == 'posix') && ((inputs.build_glib == 'ON') || (inputs.build_glibmm == 'ON')) }} + with: + packages: libglibmm-2.4-dev + version: 1.0 + + - name: Install Qt (Ubuntu) + if: ${{ (inputs.platform == 'posix') && (inputs.install_qt == 'ON') }} + uses: jurplel/install-qt-action@v4 + with: + version: '6.4.*' + host: 'linux' + target: 'desktop' + arch: 'gcc_64' + modules: '' + cache: 'true' + cache-key-prefix: 'install-qt-action-linux' + set-env: 'true' + + - name: Install Qt (Windows) + if: ${{ (inputs.platform == 'windows') && (inputs.install_qt == 'ON') }} + uses: jurplel/install-qt-action@v4 + with: + version: '6.4.*' + host: 'windows' + target: 'desktop' + arch: 'win64_msvc2019_64' + modules: '' + cache: 'true' + cache-key-prefix: 'install-qt-action-win32' + set-env: 'true' + + - name: Configure (POSIX platforms) + if: ${{ inputs.platform != 'windows' }} + shell: bash + run: | + $GITHUB_ACTION_PATH/../../../scripts/build/${{ inputs.platform }}/configure.sh \ + "${{ inputs.build_dir }}" \ + "${{ inputs.build_type }}" \ + "${{ inputs.cmake_args }}" \ + "${{ inputs.src_dir }}" \ + "${{ inputs.build_tests }}" + + - name: Configure (Windows) + if: ${{ inputs.platform == 'windows' }} + shell: cmd + run: | + call "%GITHUB_ACTION_PATH%\..\..\..\scripts\build\windows\configure.cmd" "${{ inputs.build_dir }}" "${{ inputs.build_type }}" "${{ inputs.cmake_args }}" "${{ inputs.src_dir }}" "${{ inputs.build_tests }}" + + - name: Build (POSIX platforms) + if: ${{ (inputs.platform != 'windows') && (inputs.only_configure == 'false') }} + shell: bash + run: | + $GITHUB_ACTION_PATH/../../../scripts/build/${{ inputs.platform }}/build.sh \ + "${{ inputs.build_dir }}" \ + "${{ inputs.build_type }}" + + - name: Build (Windows) + if: ${{ (inputs.platform == 'windows') && (inputs.only_configure == 'false') }} + shell: cmd + run: | + call "%GITHUB_ACTION_PATH%\..\..\..\scripts\build\windows\build.cmd" "${{ inputs.build_dir }}" "${{ inputs.build_type }}" diff --git a/.github/workflows/get-commit-version/action.yml b/ci_reference/hsm-github-workflows/actions/get-commit-version/action.yml similarity index 68% rename from .github/workflows/get-commit-version/action.yml rename to ci_reference/hsm-github-workflows/actions/get-commit-version/action.yml index 3b58bd2..c115227 100644 --- a/.github/workflows/get-commit-version/action.yml +++ b/ci_reference/hsm-github-workflows/actions/get-commit-version/action.yml @@ -1,4 +1,6 @@ -name: Get commit version +name: Get commit version + +# TODO: implement commit description validation inputs: repo_dir: @@ -15,7 +17,7 @@ outputs: description: "Tag extracted from commit (head if commit_sha was not provided or is empty)" value: ${{ format('{0}{1}', steps.read_head_version.outputs.head_tag, steps.read_commit_version.outputs.commit_tag) }} commit_action: - description: "Action extracted from commit (head if commit_sha was not provided or is empty)" + description: "Action extracted from commit (head if commit_sha was not provided or is empty). Currently: r - release" value: ${{ format('{0}{1}', steps.read_head_version.outputs.head_action, steps.read_commit_version.outputs.commit_action) }} runs: @@ -27,10 +29,24 @@ runs: if: ${{ inputs.commit_sha == '' }} run: | cd "${{ inputs.repo_dir }}" - git log -1 --pretty=format:"%s %d" - echo "head_version=$(git log -1 --pretty=format:"%s" | grep -Po '\[\K([\d.]+)\]' | grep -Po '[^\]]+')" >> $GITHUB_OUTPUT - echo "head_tag=$(git log -1 --pretty=format:"%d" | grep -Po 'tag: \K\d+\.\d+\.\d+')" >> $GITHUB_OUTPUT - echo "head_action=$(git log -1 --pretty=format:"%s" | grep -Po '\[([\d.]+)\]\[\K[\w]+\]' | grep -Po '[^\]]+')" >> $GITHUB_OUTPUT + + if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then + CHANGE_MSG="${{ github.event.pull_request.title }}" + CHANGE_TAGS="$CHANGE_MSG" + else + COMMIT_SHA="${{ github.sha }}" + CHANGE_MSG=$(git log -1 $COMMIT_SHA --pretty=format:"%s") + CHANGE_TAGS=$(git log -1 $COMMIT_SHA --pretty=format:"%d") + fi + + head_version=$(echo "$CHANGE_MSG" | grep -Po '\[\K([\d.]+)\]' | grep -Po '[^\]]+' || true) + head_action=$(echo "$CHANGE_MSG" | grep -Po '\[([\d.]+)\]\[\K[\w]+\]' | grep -Po '[^\]]+' || true) + head_tag=$(echo "$CHANGE_TAGS" | grep -Po 'tag: \K\d+\.\d+\.\d+' || true) + + # Output values + echo "head_version=$head_version" >> $GITHUB_OUTPUT + echo "head_tag=$head_tag" >> $GITHUB_OUTPUT + echo "head_action=$head_action" >> $GITHUB_OUTPUT - if: ${{ inputs.commit_sha == '' }} shell: bash run: | @@ -38,6 +54,7 @@ runs: echo "TAG: '${{ steps.read_head_version.outputs.head_tag }}'" echo "ACTION: '${{ steps.read_head_version.outputs.head_action }}'" + - id: read_commit_version shell: bash if: ${{ inputs.commit_sha != '' }} diff --git a/ci_reference/hsm-github-workflows/workflows/autotag.yml b/ci_reference/hsm-github-workflows/workflows/autotag.yml new file mode 100644 index 0000000..3400b3a --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/autotag.yml @@ -0,0 +1,54 @@ +name: "Auto Tagging (Reusable)" +on: + workflow_call: + inputs: + commit_sha: + required: true + type: string + commit_version: + required: true + type: string + commit_action: + required: true + type: string + +# Required Secrets +# - BOT_GPG_PRIVATE_KEY +# - BOT_GPG_PASSPHRASE + +jobs: + # check_version: + # uses: ./.github/workflows/check-version.yml + + create_release_tag: + # needs: check_version + if: > + github.ref_name == 'main' && + inputs.commit_version != '' && + inputs.commit_action == 'r' + + outputs: + tag_name: ${{ steps.create_tag.outputs.tag_name }} # reference step output + + name: "Create Tags" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + git_config_global: true + git_user_signingkey: true + git_commit_gpgsign: true + workdir: ${{ github.workspace }} + - name: Create git tag + id: create_tag + run: | + TAG=${{ needs.check_version.outputs.commit_version }} + git tag $TAG ${{ inputs.commit_sha }} + git push origin $TAG + echo "tag_name=$TAG" >> $GITHUB_OUTPUT + diff --git a/ci_reference/hsm-github-workflows/workflows/build.yml b/ci_reference/hsm-github-workflows/workflows/build.yml new file mode 100644 index 0000000..93b7fb0 --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/build.yml @@ -0,0 +1,246 @@ +name: "Build (Reusable)" +on: + workflow_call: + inputs: + platforms: + description: "Comma-separated list of platforms: windows,posix,platformio,arduinoide,freertos" + required: false + type: string + default: "posix" + src_dir: + required: false + type: string + build_dir: + required: false + type: string + build_type: + required: false + type: string + default: 'Release' + build_glib: + required: false + type: string + default: 'OFF' + build_glibmm: + required: false + type: string + default: 'OFF' + install_qt: + required: false + type: string + default: 'OFF' + build_std: + required: false + type: string + default: 'ON' + build_tests: + required: false + type: string + default: 'OFF' + build_examples: + required: false + type: string + default: 'OFF' + codecoverage: + required: false + type: string + default: 'OFF' + cmake_args: + required: false + type: string + default: '' + freertos_ref: + required: false + type: string + default: '202212.00' +jobs: + prepare_args: + name: "Parse Build Arguments" + runs-on: ubuntu-latest + outputs: + platforms_json: ${{ steps.parse.outputs.platforms_json }} + build_dir: ${{ steps.resolve_build_dir.outputs.dir }} + src_dir: ${{ steps.resolve_src_dir.outputs.dir }} + steps: + - name: Parse platforms input + id: parse + run: | + platforms="${{ inputs.platforms }}" + json="[$(printf '"%s",' ${platforms//,/ })]" + json="${json%,}]" + echo "platforms_json=$json" >> $GITHUB_OUTPUT + + - name: Resolve build directory + id: resolve_build_dir + run: | + echo "dir=${{ inputs.build_dir || format('{0}/build', github.workspace) }}" >> $GITHUB_OUTPUT + + - name: Resolve src directory + id: resolve_src_dir + run: | + echo "dir=${{ inputs.src_dir || github.workspace }}" >> $GITHUB_OUTPUT + + build_project_ubuntu: + name: "Ubuntu" + needs: prepare_args + if: contains(needs.prepare_args.outputs.platforms_json, 'posix') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Build project (Ubuntu) + uses: igor-krechetov/hsm-github-workflows/.github/actions/build_helper@main + with: + platform: 'posix' + build_type: ${{ inputs.build_type }} + src_dir: ${{ needs.prepare_args.outputs.src_dir }} + build_dir: ${{ needs.prepare_args.outputs.build_dir }} + build_glib: ${{ inputs.build_glib }} + build_glibmm: ${{ inputs.build_glibmm }} + install_qt: ${{ inputs.install_qt }} + build_std: ${{ inputs.build_std }} + build_tests: ${{ inputs.build_tests }} + build_examples: ${{ inputs.build_examples }} + codecoverage: ${{ inputs.codecoverage }} + cmake_args: ${{ inputs.cmake_args }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts-ubuntu + path: ${{ needs.prepare_args.outputs.build_dir }} + + build_project_windows: + name: "Windows" + needs: prepare_args + if: contains(needs.prepare_args.outputs.platforms_json, 'windows') + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Build project (Windows) + uses: igor-krechetov/hsm-github-workflows/.github/actions/build_helper@main + with: + platform: 'windows' + build_type: ${{ inputs.build_type }} + src_dir: ${{ needs.prepare_args.outputs.src_dir }} + build_dir: ${{ needs.prepare_args.outputs.build_dir }} + build_glib: ${{ inputs.build_glib }} + build_glibmm: ${{ inputs.build_glibmm }} + install_qt: ${{ inputs.install_qt }} + build_std: ${{ inputs.build_std }} + build_tests: ${{ inputs.build_tests }} + build_examples: ${{ inputs.build_examples }} + codecoverage: ${{ inputs.codecoverage }} + cmake_args: ${{ inputs.cmake_args }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts-windows + path: ${{ needs.prepare_args.outputs.build_dir }} + + build_platformio: + name: "PlatformIO" + needs: prepare_args + if: contains(needs.prepare_args.outputs.platforms_json, 'platformio') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Install PlatformIO + run: pip3 install --user platformio + - name: Generate package + run: | + cmake -S ./ -B ./build -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino + cmake --build ./build --target install + - name: Copy package to examples folder + run: | + mkdir -p ./examples/09_arduino/01_blink/lib/hsmcpp + cp -Rv ./build/deploy/platformio/* ./examples/09_arduino/01_blink/lib/hsmcpp + mkdir -p ./examples/09_arduino/02_blink_button/lib/hsmcpp + cp -Rv ./build/deploy/platformio/* ./examples/09_arduino/02_blink_button/lib/hsmcpp + - name: Build 01_blink + run: | + export PATH="$HOME/.local/bin:$PATH" + cd ./examples/09_arduino/01_blink/ + pio run + - name: Build 02_blink_button + run: | + export PATH="$HOME/.local/bin:$PATH" + cd ./examples/09_arduino/02_blink_button/ + pio run + + build_arduinoide: + name: "ArduinoIDE" + needs: prepare_args + if: contains(needs.prepare_args.outputs.platforms_json, 'arduinoide') + runs-on: ubuntu-latest + env: + library_dir: ./build/deploy/arduinoide + example1_dir: ./build/deploy/arduinoide/examples/01_blink + example2_dir: ./build/deploy/arduinoide/examples/02_blink_button + scxml2gen_dir: ./build/deploy/arduinoide/tools/scxml2gen + hsmcpp_library: ./build/deploy/hsmcpp.zip + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Generate hsmcpp library package + run: | + cmake -S ./ -B ./build -DHSMBUILD_TARGET=arduinoide -DHSMBUILD_PLATFORM=arduino + cmake --build ./build --target install + cp -Rv ${{ env.library_dir }} ./build/deploy/hsmcpp + cd ./build/deploy/ + zip -r ./hsmcpp.zip ./hsmcpp + - name: Generate HSM files + run: | + python3 ${{ env.scxml2gen_dir }}/scxml2gen.py -code -scxml ${{ env.example1_dir }}/blink.scxml \ + -class_name BlinkHsm -class_suffix Base \ + -template_hpp ${{ env.scxml2gen_dir }}/template.hpp \ + -template_cpp ${{ env.scxml2gen_dir }}/template.cpp \ + -dest_dir ${{ env.example1_dir }}/ + python3 ${{ env.scxml2gen_dir }}/scxml2gen.py -code -scxml ${{ env.example2_dir }}/blink_button.scxml \ + -class_name BlinkButtonHsm -class_suffix Base \ + -template_hpp ${{ env.scxml2gen_dir }}/template.hpp \ + -template_cpp ${{ env.scxml2gen_dir }}/template.cpp \ + -dest_dir ${{ env.example2_dir }}/ + - name: Setup Arduino CLI + uses: arduino/setup-arduino-cli@v2 + - name: Install platform files + run: | + arduino-cli core update-index --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json + arduino-cli core install esp8266:esp8266 --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json + - name: Install hsmcpp library + run: | + arduino-cli config init + arduino-cli config set library.enable_unsafe_install true + arduino-cli lib install --zip-path ${{ env.hsmcpp_library }} + - name: Compile Sketch 01 + run: arduino-cli compile --fqbn esp8266:esp8266:d1_mini ${{ env.example1_dir }}/ --warnings more + - name: Compile Sketch 02 + run: arduino-cli compile --fqbn esp8266:esp8266:d1_mini ${{ env.example2_dir }}/ --warnings more + + build_freertos: + name: "FreeRTOS" + needs: prepare_args + if: contains(needs.prepare_args.outputs.platforms_json, 'freertos') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + path: './source' + submodules: 'recursive' + - uses: actions/checkout@v3 + with: + repository: 'FreeRTOS/FreeRTOS' + ref: ${{ inputs.freertos_ref }} + submodules: 'recursive' + path: './FreeRTOS' + - name: Build 08_freertos + run: | + cd ./source/examples/08_freertos + ./build.sh '${{github.workspace}}/FreeRTOS' diff --git a/ci_reference/hsm-github-workflows/workflows/check-version.yml b/ci_reference/hsm-github-workflows/workflows/check-version.yml new file mode 100644 index 0000000..13b4cd0 --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/check-version.yml @@ -0,0 +1,21 @@ +name: "Check Version (Reusable)" +on: + workflow_call: + outputs: + commit_version: + description: "Commit version" + value: ${{ jobs.check_version.outputs.commit_version }} + +jobs: + check_version: + name: "Extract Version" + runs-on: ubuntu-latest + outputs: + commit_version: ${{ steps.get_version.outputs.commit_version }} + steps: + - uses: actions/checkout@v3 + - uses: igor-krechetov/hsm-github-workflows/.github/actions/get-commit-version@main + id: get_version + with: + repo_dir: ${{ env.GITHUB_WORKSPACE }} + commit_sha: ${{ github.event.workflow_run.head_sha }} diff --git a/ci_reference/hsm-github-workflows/workflows/deploy.yml b/ci_reference/hsm-github-workflows/workflows/deploy.yml new file mode 100644 index 0000000..a71e19a --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/deploy.yml @@ -0,0 +1,121 @@ +name: "Deploy Package (Reusable)" + +on: + workflow_call: + inputs: + deploy_target: + description: "Target platform: platformio or arduinoide" + required: true + type: string + commit_sha: + required: true + type: string + commit_version: + required: false + type: string + default: '' + commit_action: + required: false + type: string + default: '' + target_repo: + description: "Target repo in owner/name format" + required: true + type: string + target_branch: + required: false + type: string + default: 'main' + publish_registry: + description: "Publish to external registry if supported" + required: false + type: boolean + default: false + +jobs: + deploy: + runs-on: ubuntu-latest + if: > + inputs.commit_version != '' && + (inputs.deploy_target == 'platformio' || inputs.commit_action == 'r') + env: + target_dir: ./deploy_target + library_dir: ./main/build/deploy/hsmcpp + steps: + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + path: ./main + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.target_repo }} + token: ${{ secrets.HSMCPP_BOT_TOKEN }} + ref: ${{ inputs.target_branch }} + path: ${{ env.target_dir }} + + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + git_config_global: true + git_user_signingkey: true + git_commit_gpgsign: true + workdir: ${{ env.target_dir }} + + - name: Install PlatformIO + if: inputs.deploy_target == 'platformio' + run: pip3 install --user platformio + + - name: Generate package for PlatformIO + if: inputs.deploy_target == 'platformio' + run: | + cmake -S ./main -B ./main/build -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino + cmake --build ./main/build --target install + + - name: Generate package for ArduinoIDE + if: inputs.deploy_target == 'arduinoide' + run: | + cmake -S ./main -B ./main/build -DHSMBUILD_TARGET=arduinoide -DHSMBUILD_PLATFORM=arduino + cmake --build ./main/build --target install + mv ./main/build/deploy/arduinoide ${{ env.library_dir }} + + - name: Validate arduino library structure + if: inputs.deploy_target == 'arduinoide' + run: | + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | BINDIR=./ sh + ./arduino-lint --compliance strict --recursive --library-manager update ${{ env.library_dir }} + + - name: Copy package files to target repository + run: | + if [ "${{ inputs.deploy_target }}" = "platformio" ]; then + cp -Rv ./main/build/deploy/platformio/* "$target_dir" + else + cp -Rv ${{ env.library_dir }}/* "$target_dir" + fi + + - name: Publish PlatformIO package + if: inputs.deploy_target == 'platformio' && inputs.publish_registry + env: + PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }} + run: | + export PATH="$HOME/.local/bin:$PATH" + pio pkg publish --type library --no-interactive $PWD/main/build/deploy/platformio/ + + - name: Prepare commit message + run: | + cd ./main + git log -1 --format=%B ${{ inputs.commit_sha }} > ../commit.txt + + - name: Commit and push files + run: | + cd "$target_dir" + git add -A + git commit -S -F ../commit.txt + if [ "${{ inputs.deploy_target }}" = "arduinoide" ]; then + git tag ${{ inputs.commit_version }} + git push + git push --tags + else + git push + fi diff --git a/ci_reference/hsm-github-workflows/workflows/release.yml b/ci_reference/hsm-github-workflows/workflows/release.yml new file mode 100644 index 0000000..879a396 --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/release.yml @@ -0,0 +1,74 @@ +name: "Release Binaries (Reusable)" + +on: + workflow_call: + inputs: + commit_sha: + required: true + type: string + tag_version: + required: false + type: string + builds: + description: "Comma-separated list of artifact names to release" + required: true + type: string + release_description: + description: "Release notes / description (multiline allowed)" + required: false + type: string + repo_dir: + required: false + type: string + default: ${{ github.workspace }} + +# Secrets: +# - GITHUB_TOKEN + +jobs: + release: + runs-on: ubuntu-latest + steps: + + # Checkout the repo (needed if scripts rely on repo content) + - uses: actions/checkout@v4 + + # Determine release tag + - name: Determine release tag + id: tag + run: | + if [ -z "${{ inputs.tag_version }}" ]; then + TAG="v$(date +'%Y%m%d-%H%M%S')" + else + TAG="${{ inputs.tag_version }}" + fi + echo "tag=$TAG" >> $GITHUB_OUTPUT + + # Create GitHub release + - name: Create release + id: create_release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.tag.outputs.tag }} + name: ${{ steps.tag.outputs.tag }} + body: ${{ inputs.release_description }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Upload all artifacts from the builds list + - name: Upload artifacts + run: | + IFS=',' read -ra ARTIFACT_NAMES <<< "${{ inputs.builds }}" + for ARTIFACT in "${ARTIFACT_NAMES[@]}"; do + echo "Downloading artifact: $ARTIFACT" + # Download artifact from the same workflow run + gh run download --name "$ARTIFACT" --dir ./tmp + + # Assuming each artifact contains a single archive file + FILE=$(ls ./tmp) + echo "Uploading $FILE to release ${{ steps.tag.outputs.tag }}" + gh release upload "${{ steps.tag.outputs.tag }}" ./tmp/"$FILE" --clobber --repo ${{ github.repository }} + rm -rf ./tmp + done + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/ci_reference/hsm-github-workflows/workflows/test.yml b/ci_reference/hsm-github-workflows/workflows/test.yml new file mode 100644 index 0000000..8a92bfb --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/test.yml @@ -0,0 +1,59 @@ +name: "Run Tests (Reusable)" +on: + workflow_call: + inputs: + test_script: + description: "Path to the shell script that runs unit tests" + required: true + type: string + artifact_name: + description: "Name of build artifact produced by build.yml" + required: false + type: string + default: "build-artifacts-ubuntu" + artifacts_dir: + description: "Directory where build artifacts will be downloaded" + required: false + type: string + default: "build" + +jobs: + unit_tests_ubuntu: + name: "Unit Tests (Ubuntu)" + runs-on: ubuntu-latest + steps: + - name: Install Qt (Ubuntu) + uses: jurplel/install-qt-action@v4 + with: + version: '6.4.*' + host: 'linux' + target: 'desktop' + arch: 'gcc_64' + modules: '' + cache: 'true' + cache-key-prefix: 'install-qt-action-linux' + set-env: 'true' + + - uses: actions/checkout@v3 + + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact_name }} + path: ${{ inputs.artifacts_dir }} + + - name: Run unit tests + shell: bash + run: | + repo_root="${{ github.workspace }}" + script_path="${{ github.workspace }}/${{ inputs.test_script }}" + + if [[ ! -f "$script_path" ]]; then + echo "Test script not found: $script_path" + exit 1 + fi + + chmod +x "$script_path" + + cd "${{ inputs.artifacts_dir }}" + "$script_path" "$repo_root" diff --git a/ci_reference/hsm-github-workflows/workflows/update-docs.yml b/ci_reference/hsm-github-workflows/workflows/update-docs.yml new file mode 100644 index 0000000..fc84e99 --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/update-docs.yml @@ -0,0 +1,17 @@ +name: "Update Documentation (Reusable)" +on: + workflow_call: + +jobs: + update_docs: + name: "Update Documentation" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + # - name: Install Doxygen and PlantUML + # run: sudo apt-get update && sudo apt-get install -y doxygen plantuml + + - name: Generate docs + run: | + echo "GENERATE DOCUMENTATION" \ No newline at end of file diff --git a/ci_reference/hsm-github-workflows/workflows/validate-metadata.yml b/ci_reference/hsm-github-workflows/workflows/validate-metadata.yml new file mode 100644 index 0000000..cd45d74 --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/validate-metadata.yml @@ -0,0 +1,41 @@ +name: "Validate Metadata (Reusable)" +on: + workflow_call: + inputs: + commit_version: + required: true + type: string + +jobs: +# steps: +# - uses: actions/checkout@v3 +# - name: Validate metadata +# if: ${{ (inputs.commit_version != '') }} +# run: ./scripts/validate_metadata.py ${{ inputs.commit_version }} ./ + + validate_metadata: + name: "Verify Commit" + runs-on: ubuntu-latest + steps: + # 1ī¸âƒŖ Checkout the target project + - name: Checkout caller repository + uses: actions/checkout@v3 + with: + repository: ${{ github.repository }} + ref: ${{ github.sha }} + path: repoProject + fetch-depth: 0 # important to have full git history if needed + + # 2ī¸âƒŖ Checkout reusable workflow repo + - name: Checkout scripts repository + uses: actions/checkout@v3 + with: + repository: igor-krechetov/hsm-github-workflows + path: repoWorkflows + fetch-depth: 0 + + # 3ī¸âƒŖ Run the Python script from Repo A, pointing to Repo B + - name: Validate metadata + if: ${{ inputs.commit_version != '' }} + run: | + python3 ./repoWorkflows/scripts/validate_metadata.py ${{ inputs.commit_version }} ./repoProject/ diff --git a/ci_reference/hsm-github-workflows/workflows/verify.yml b/ci_reference/hsm-github-workflows/workflows/verify.yml new file mode 100644 index 0000000..c5f276b --- /dev/null +++ b/ci_reference/hsm-github-workflows/workflows/verify.yml @@ -0,0 +1,67 @@ +name: "Validate commit (Reusable)" + +on: + workflow_call: + outputs: + commit_version: + value: ${{ jobs.check_version.outputs.commit_version }} + commit_action: + value: ${{ jobs.check_version.outputs.commit_action }} + +jobs: + # -------------------------------------------------------- + # 1) CHECK VERSION + # -------------------------------------------------------- + check_version: + # uses: ./.github/workflows/check-version.yml + name: "Extract Version" + runs-on: ubuntu-latest + outputs: + commit_version: ${{ steps.get_version.outputs.commit_version }} + commit_action: ${{ steps.get_version.outputs.commit_action }} + steps: + - uses: actions/checkout@v3 + - uses: igor-krechetov/hsm-github-workflows/.github/actions/get-commit-version@main + id: get_version + with: + repo_dir: ${{ env.GITHUB_WORKSPACE }} + commit_sha: ${{ github.event.workflow_run.head_sha }} + + # -------------------------------------------------------- + # 2) VALIDATE METADATA + # -------------------------------------------------------- + verify_metadata: + name: "Verify Commit" + needs: check_version + # Skip metadata checks if no version change was defined + if: needs.check_version.outputs.commit_version != '' + + runs-on: ubuntu-latest + steps: + # Checkout the target project + - name: Checkout caller repository + uses: actions/checkout@v3 + with: + repository: ${{ github.repository }} + ref: ${{ github.sha }} + path: repoProject + fetch-depth: 0 # important to have full git history if needed + + # Checkout reusable workflow repo + - name: Checkout scripts repository + uses: actions/checkout@v3 + with: + repository: igor-krechetov/hsm-github-workflows + path: repoWorkflows + fetch-depth: 0 + + - name: Validate metadata + if: ${{ needs.check_version.outputs.commit_version != '' }} + run: | + python3 ./repoWorkflows/scripts/validate_metadata.py ${{ needs.check_version.outputs.commit_version }} ./repoProject/ + + - name: Fail if version is missing + if: ${{ needs.check_version.outputs.commit_version == '' }} + run: | + echo "Missing commit_version!" + exit 1 \ No newline at end of file diff --git a/scripts/build/arduino/build.sh b/scripts/build/arduino/build.sh new file mode 100755 index 0000000..b37fa2a --- /dev/null +++ b/scripts/build/arduino/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" + +cmake --build "$build_dir" --config "$build_type" --target install diff --git a/scripts/build/arduino/configure.sh b/scripts/build/arduino/configure.sh new file mode 100755 index 0000000..b99b4d8 --- /dev/null +++ b/scripts/build/arduino/configure.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" +cmake_args="$3" +src_dir="$4" +build_tests="$5" + +cmake -S "$src_dir" -B "$build_dir" -DCMAKE_BUILD_TYPE="$build_type" \ + -DHSMBUILD_TARGET=arduinoide -DHSMBUILD_PLATFORM=arduino -DHSMBUILD_TESTS="$build_tests" \ + $cmake_args diff --git a/scripts/build/freertos/build.sh b/scripts/build/freertos/build.sh new file mode 100755 index 0000000..773751d --- /dev/null +++ b/scripts/build/freertos/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" + +cmake --build "$build_dir" --config "$build_type" diff --git a/scripts/build/freertos/configure.sh b/scripts/build/freertos/configure.sh new file mode 100755 index 0000000..9a52d7d --- /dev/null +++ b/scripts/build/freertos/configure.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" +cmake_args="$3" +src_dir="$4" +build_tests="$5" + +cmake -S "$src_dir" -B "$build_dir" -DCMAKE_BUILD_TYPE="$build_type" \ + -DHSMBUILD_PLATFORM=freertos -DHSMBUILD_TESTS="$build_tests" \ + $cmake_args diff --git a/scripts/build/platformio/build.sh b/scripts/build/platformio/build.sh new file mode 100755 index 0000000..b37fa2a --- /dev/null +++ b/scripts/build/platformio/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" + +cmake --build "$build_dir" --config "$build_type" --target install diff --git a/scripts/build/platformio/configure.sh b/scripts/build/platformio/configure.sh new file mode 100755 index 0000000..4dfec91 --- /dev/null +++ b/scripts/build/platformio/configure.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" +cmake_args="$3" +src_dir="$4" +build_tests="$5" + +cmake -S "$src_dir" -B "$build_dir" -DCMAKE_BUILD_TYPE="$build_type" \ + -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino -DHSMBUILD_TESTS="$build_tests" \ + $cmake_args diff --git a/scripts/build/posix/build.sh b/scripts/build/posix/build.sh new file mode 100755 index 0000000..1776375 --- /dev/null +++ b/scripts/build/posix/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" + +cmake --build "$build_dir" --parallel 2 --config "$build_type" diff --git a/scripts/build/posix/configure.sh b/scripts/build/posix/configure.sh new file mode 100755 index 0000000..ccc6627 --- /dev/null +++ b/scripts/build/posix/configure.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +build_type="$2" +cmake_args="$3" +src_dir="$4" +build_tests="$5" +build_examples="$6" + +cmake -B "$build_dir" -DCMAKE_BUILD_TYPE="$build_type" \ + -DHSMBUILD_VERBOSE=OFF \ + -DHSMBUILD_PLATFORM=posix \ + -DHSMBUILD_DISPATCHER_GLIB=ON \ + -DHSMBUILD_DISPATCHER_GLIBMM=ON \ + -DHSMBUILD_DISPATCHER_STD=ON \ + -DHSMBUILD_DISPATCHER_QT=ON \ + -DHSMBUILD_EXAMPLES="$build_examples" \ + -DHSMBUILD_TESTS="$build_tests" \ + -DHSMBUILD_CODECOVERAGE=ON \ + -DHSMBUILD_DEBUGGING=ON \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + $cmake_args \ + "$src_dir" diff --git a/scripts/build/windows/build.cmd b/scripts/build/windows/build.cmd new file mode 100644 index 0000000..e380785 --- /dev/null +++ b/scripts/build/windows/build.cmd @@ -0,0 +1,5 @@ +@echo off +set BUILD_DIR=%1 +set BUILD_TYPE=%2 + +cmake --build "%BUILD_DIR%" --parallel 2 --config %BUILD_TYPE% diff --git a/scripts/build/windows/configure.cmd b/scripts/build/windows/configure.cmd new file mode 100644 index 0000000..8b7299a --- /dev/null +++ b/scripts/build/windows/configure.cmd @@ -0,0 +1,19 @@ +@echo off +set BUILD_DIR=%1 +set BUILD_TYPE=%2 +set CMAKE_ARGS=%3 +set SRC_DIR=%4 +set BUILD_TESTS=%5 + +cmake -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^ + -DHSMBUILD_VERBOSE=OFF ^ + -DHSMBUILD_PLATFORM=windows ^ + -DHSMBUILD_DISPATCHER_GLIB=OFF ^ + -DHSMBUILD_DISPATCHER_GLIBMM=OFF ^ + -DHSMBUILD_DISPATCHER_STD=ON ^ + -DHSMBUILD_DISPATCHER_QT=ON ^ + -DHSMBUILD_TESTS=%BUILD_TESTS% ^ + -DHSMBUILD_EXAMPLES=ON ^ + -DHSMBUILD_DEBUGGING=ON ^ + %CMAKE_ARGS% ^ + "%SRC_DIR%" diff --git a/scripts/coverity/COPYING b/scripts/coverity/COPYING deleted file mode 100644 index bdaa98f..0000000 --- a/scripts/coverity/COPYING +++ /dev/null @@ -1,55 +0,0 @@ - BSD LICENSE - -Copyright (c) 2015, Eric S. Raymond -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - BSD LICENSE - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -Neither name of the this project nor the names of its contributors -may be used to endorse or promote products derived from this software -without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/scripts/coverity/coverity-submit.py b/scripts/coverity/coverity-submit.py deleted file mode 100755 index f516530..0000000 --- a/scripts/coverity/coverity-submit.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -# -# coverity-submit - submit project to Coverity for scanning -# -# By Eric S. Raymond, May 2012. -# SPDX-License-Identifier: BSD-2-Clause -# -# Version 2.0 by Igor Krechetov, Feb 2023 -# Improved to be used inside GitHub actions. -# -# This code runs under both Python 2 and Python 3. Preserve this property! -from __future__ import print_function - -import os, pwd, sys, stat -import tempfile, shutil, datetime, subprocess -import argparse - -version = "2.0" - - -def do_or_die(cmd): - if verbose: - print(cmd) - if not dryrun: - if os.system(cmd) != 0: - sys.stderr.write("Command failed.\n") - sys.exit(1) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='coverity-submit - submit project to Coverity for scanning') - - parser.add_argument('-user', '-u', type=str, required=True, help='build version') - parser.add_argument('-build_version', '-b', type=str, required=True, help='build version') - parser.add_argument('-dryrun', action="store_true", required=False, default=False, help='dry run of all commands') - parser.add_argument('-description', '-t', type=str, required=True, help='project description') - parser.add_argument('-verbose', '-v', action="store_true", required=False, default=False, help='verbose execution') - parser.add_argument('-project', '-p', type=str, required=True, help='project name') - parser.add_argument('-project_url', '-pu', type=str, required=False, help='project url name') - parser.add_argument('-token', type=str, required=True, help='Coverity token') - parser.add_argument('-email', type=str, required=True, help='user email') - parser.add_argument('-prebuild', type=str, required=False, help='prebuild command') - parser.add_argument('-build', type=str, required=True, help='build command') - parser.add_argument('-postbuild', type=str, required=False, help='post-build command') - parser.add_argument('-config', type=str, required=True, help='coverity config') - - args = parser.parse_args() - name = args.user - build_version = args.build_version - dryrun = args.dryrun - description = args.description - verbose = args.verbose - - covname = args.project - covname_url = args.project_url - if covname_url is None: - covname_url = covname - token = args.token - email = args.email - prebuild = args.prebuild - build = args.build - postbuild = args.postbuild - cov_config = args.config - - # Announce self - print("coverity-submit version %s..." % version) - - # Work around a known bug in environment restoration under cov-build. - # Without this, xmlto won't run. - os.environ["XML_CATALOG_FILES"] = '/etc/xml/catalog' - - # Build local stuff - print("Rebuilding and scanning...") - if prebuild: - do_or_die(prebuild) - do_or_die("rm -fr cov-int && cov-build --config " + cov_config + " --dir cov-int " + build) - if postbuild: - do_or_die(postbuild) - - # Create the tarball - if verbose: - print("Bundling up required metadata...") - - readme = """\ - Name: %(name)s - Email: %(email)s - Project: %(covname)s - Build-Version: %(build_version)s - Description: %(description)s - Submitted-by: coverity-submit %(version)s - """ % globals() - - if verbose: - sys.stdout.write(readme) - - tmpdir = tempfile.mkdtemp() - - if not dryrun: - with open(os.path.join(tmpdir, "README"), "w") as wfp: - wfp.write(readme) - - tarball = "%s-scan.tgz" % covname - tarball = tarball.replace('/', '-') - - if verbose and not dryrun: - shutil.copy("cov-int/build-log.txt", "build-log.txt") - - do_or_die("mv cov-int %s; (cd %s; tar -czf %s README cov-int; rm -fr README cov-int)" % (tmpdir, tmpdir, tarball)) - print("Posting the analysis request...") - do_or_die('''curl \ - --form file=@%(tmpdir)s/%(tarball)s \ - --form project="%(covname)s" \ - --form token=%(token)s \ - --form email=%(email)s \ - --form version="%(build_version)s" \ - --form description="%(description)s" \ - https://scan.coverity.com/builds?project=%(covname_url)s \ - ''' % globals()) - - try: - os.remove(os.path.join(tmpdir, tarball)) - os.rmdir(tmpdir) - except OSError: - pass - - print("Finished") - -# The following sets edit modes for GNU EMACS -# Local Variables: -# mode:python -# End: diff --git a/scripts/cppcheck/cppcheck-misra-parsetexts.py b/scripts/cppcheck/cppcheck-misra-parsetexts.py deleted file mode 100644 index 1e49218..0000000 --- a/scripts/cppcheck/cppcheck-misra-parsetexts.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/python3 -# Author: https://github.com/ChisholmKyle/SublimeLinter-cppcheck-misra - -"""Generate MISRA C 2012 rule texts from pdf. - -Arguments: - filename -- text file from parsed MISRA pdf file - -Example: - python3 cppcheck-misra-parsetexts.py "/path/to/MISRA_C_2012.pdf" - -""" - -import os -import re -import sys -import json -import tempfile -import subprocess - -# rules -_appendixa_regex = re.compile(r'Appendix A Summary of guidelines\n') -_appendixb_regex = re.compile(r'Appendix B Guideline attributes\n') -_rule_regex = re.compile( - r'(Rule|Dir).(\d+)\.(\d+)\n\n(Advisory|Required|Mandatory)\n\n([^\n]+)\n') -_line_regex = re.compile(r'([^\n]+)\n') - - -def misra_dict_to_text(misra_dict): - """Convert dict to string readable by cppcheck's misra.py addon.""" - misra_str = '' - for num1 in misra_dict: - for num2 in misra_dict[num1]: - misra_str += '\n{} {}.{} {}\n'.format( - misra_dict[num1][num2]['type'], num1, num2, misra_dict[num1][num2]['category']) - misra_str += '{}\n'.format(misra_dict[num1][num2]['text']) - return misra_str - - -def parse_misra_xpdf_output(misra_file): - """Extract misra rules texts from xPDF output.""" - misra_dict = {} - - with open(misra_file, 'r', encoding="utf-8") as fp: - fp_text = fp.read() - - # end of appendix A - appb_end_res = _appendixb_regex.search(fp_text) - last_index = appb_end_res.regs[0][0] - - appres = _appendixa_regex.search(fp_text) - if appres: - start_index = appres.regs[0][1] - res = _rule_regex.search(fp_text, start_index) - while res: - start_index = res.regs[0][1] - ruletype = res.group(1) - rulenum1 = res.group(2) - rulenum2 = res.group(3) - category = res.group(4) - ruletext = res.group(5).strip() - statereadingrule = True - while statereadingrule: - lineres = _line_regex.match(fp_text, start_index) - if lineres: - start_index = lineres.regs[0][1] - stripped_line = lineres.group(1).strip() - ruletext += ' ' + stripped_line - else: - # empty line, stop reading text and save to dict - if rulenum1 not in misra_dict: - misra_dict[rulenum1] = {} - misra_dict[rulenum1][rulenum2] = { - 'type': ruletype, - 'category': category, - 'text': ruletext - } - statereadingrule = False - res = _rule_regex.search(fp_text, start_index) - if res and (last_index < res.regs[0][0]): - break - fp.close() - - return misra_dict - - -def misra_parse_pdf(misra_pdf): - """Extract misra rules texts from Misra-C-2012 pdf.""" - - if not os.path.isfile(misra_pdf): - print('Fatal error: PDF file is not found: ' + misra_pdf) - sys.exit(1) - f = tempfile.NamedTemporaryFile(delete=False) - f.close() - subprocess.call([ - 'pdftotext', - '-enc', 'UTF-8', - '-eol', 'unix', - misra_pdf, - f.name - ]) - misra_dict = parse_misra_xpdf_output(f.name) - os.remove(f.name) - - return misra_dict - - -misra_pdf_filename = sys.argv[1] - -misra_dict = misra_parse_pdf(misra_pdf_filename) -misra_text = 'Appendix A Summary of guidelines\n\n' + \ - misra_dict_to_text(misra_dict) - -misra_json_fout = os.path.splitext(misra_pdf_filename)[0] + '_Rules.json' -misra_text_fout = os.path.splitext(misra_pdf_filename)[0] + '_Rules.txt' - -with open(misra_json_fout, 'w', encoding='utf-8') as fp: - fp.write(json.dumps(misra_dict, indent=4)) -print('Done creating "' + misra_json_fout + '"') - -with open(misra_text_fout, 'w', encoding='utf-8') as fp: - fp.write(misra_text) -print('Done creating "' + misra_text_fout + '"') \ No newline at end of file diff --git a/scripts/cppcheck/cppcheck_review.py b/scripts/cppcheck/cppcheck_review.py deleted file mode 100755 index 867a722..0000000 --- a/scripts/cppcheck/cppcheck_review.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python3 -import sys -import xml.etree.ElementTree as ET - - -if __name__ == "__main__": - REPORT_FILE = sys.argv[1].strip(" \n\r[]") - print(f"{REPORT_FILE=:}") - tree = ET.parse(REPORT_FILE) - - if tree: - root = tree.getroot() - errors = root.find("errors") - issuesCount = 0 - - for currentError in errors.iter("error"): - # NOTE: there is a crash in misra.py. fixed in 2.8+ (b444c00) - # misra plugin couldn't handle passing string literal to a function with variadic arguments - if ("id" not in currentError.attrib) or (currentError.attrib["id"] != "internalError"): - issuesCount += 1 - ET.dump(currentError) - - if issuesCount > 0: - print("cppcheck: FOUND ISSUES") - exit(1) - else: - print("cppcheck: no issues found") diff --git a/scripts/cppcheck/cppcheck_suppress.txt b/scripts/cppcheck/cppcheck_suppress.txt deleted file mode 100644 index 2125c65..0000000 --- a/scripts/cppcheck/cppcheck_suppress.txt +++ /dev/null @@ -1,8 +0,0 @@ -*:/usr/include/* -*:gen/ -*:*/glib-2.0/include/* -misra-c2012-17.8:*/include/hsmcpp/hsm.hpp -misra-c2012-17.8:*/src/HsmImpl.hpp -misra-c2012-17.8:*/src/HsmImplTypes.hpp -preprocessorErrorDirective:* -missingIncludeSystem:* \ No newline at end of file diff --git a/scripts/cppcheck/misra.json b/scripts/cppcheck/misra.json deleted file mode 100644 index 978e510..0000000 --- a/scripts/cppcheck/misra.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "script": "misra.py", - "args": [ - "--severity=information", - "--suppress-rules=12.3,8.2,8.10,2.7,20.5,13.4", - "--no-summary" - ], - "args_disable": "--rule-texts=../scripts/cppcheck/MISRA-C_2012_Rules.txt" -} \ No newline at end of file diff --git a/scripts/apply_clang_format.sh b/scripts/local/apply_clang_format.sh similarity index 100% rename from scripts/apply_clang_format.sh rename to scripts/local/apply_clang_format.sh diff --git a/scripts/build.sh b/scripts/local/build.sh similarity index 100% rename from scripts/build.sh rename to scripts/local/build.sh diff --git a/scripts/buildFreeRTOS.sh b/scripts/local/buildFreeRTOS.sh similarity index 100% rename from scripts/buildFreeRTOS.sh rename to scripts/local/buildFreeRTOS.sh diff --git a/scripts/build_vs.cmd b/scripts/local/build_vs.cmd similarity index 100% rename from scripts/build_vs.cmd rename to scripts/local/build_vs.cmd diff --git a/scripts/packageArduinoIDE.sh b/scripts/local/packageArduinoIDE.sh similarity index 100% rename from scripts/packageArduinoIDE.sh rename to scripts/local/packageArduinoIDE.sh diff --git a/scripts/packagePlatformio.sh b/scripts/local/packagePlatformio.sh similarity index 100% rename from scripts/packagePlatformio.sh rename to scripts/local/packagePlatformio.sh diff --git a/scripts/validate.sh b/scripts/local/validate.sh similarity index 90% rename from scripts/validate.sh rename to scripts/local/validate.sh index fd8e321..64dd244 100755 --- a/scripts/validate.sh +++ b/scripts/local/validate.sh @@ -1,10 +1,10 @@ #!/bin/sh -python3 ./scripts/validate_metadata.py $1 ./ -if [ $? != 0 ] -then - exit 1 -fi +# python3 ./scripts/local/validate_metadata.py $1 ./ +# if [ $? != 0 ] +# then +# exit 1 +# fi mkdir ./build cd ./build @@ -67,11 +67,11 @@ then -DHSMBUILD_CLANGTIDY=OFF \ .. - cppcheck --addon=../scripts/cppcheck/misra.json \ + cppcheck --addon=../scripts/sca/cppcheck/misra.json \ --enable=warning,performance,portability,information \ --inline-suppr \ --xml \ - --suppressions-list=../scripts/cppcheck/cppcheck_suppress.txt --project=./compile_commands.json \ + --suppressions-list=../scripts/sca/cppcheck/cppcheck_suppress.txt --project=./compile_commands.json \ -DSTL_AVAILABLE -D__GNU__=1 -D__LITTLE_ENDIAN__ -D__GNUC__ lcov --add-tracefile ./coverage_std.info \ diff --git a/scripts/validate_metadata.py b/scripts/local/validate_metadata.py similarity index 100% rename from scripts/validate_metadata.py rename to scripts/local/validate_metadata.py diff --git a/scripts/test/ubuntu/coverage.sh b/scripts/test/ubuntu/coverage.sh new file mode 100755 index 0000000..dd693f2 --- /dev/null +++ b/scripts/test/ubuntu/coverage.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" + +cd $build_dir + +echo "Generate code coverage" +lcov --add-tracefile ./coverage_std.info \ + -a ./coverage_glib.info \ + -a ./coverage_qt.info \ + -a ./coverage_glibmm.info \ + -o ./coverage.info + +lcov -r ./coverage.info \ + '/usr/include/*' \ + '*/build/*' \ + '*/tests/*' \ + '*/gcc_64/include/QtCore/*' \ + '*/thirdparty/*' \ + -o ./coverage.info diff --git a/scripts/test/ubuntu/test.sh b/scripts/test/ubuntu/test.sh new file mode 100755 index 0000000..3583548 --- /dev/null +++ b/scripts/test/ubuntu/test.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +build_dir="$1" +source_dir="$2" + +cd $build_dir + +gcc --version +gcov --version +lcov --version + +echo "Run Tests (STD)" +chmod +x ./tests/hsmUnitTestsSTD +timeout 2m ./tests/hsmUnitTestsSTD > ./tests_result_std.log +lcov -c -d . -b "$source_dir" -o ./coverage_std.info --rc geninfo_unexecuted_blocks=1 --ignore-errors mismatch,gcov,source + +echo "Run Tests (GLib)" +chmod +x ./tests/hsmUnitTestsGLib +timeout 2m ./tests/hsmUnitTestsGLib > ./tests_result_glib.log +lcov -c -d . -b "$source_dir" -o ./coverage_glib.info --rc geninfo_unexecuted_blocks=1 --ignore-errors mismatch,gcov,source + +echo "Run Tests (GLibmm)" +chmod +x ./tests/hsmUnitTestsGLibmm +timeout 2m ./tests/hsmUnitTestsGLibmm > ./tests_result_glibmm.log +lcov -c -d . -b "$source_dir" -o ./coverage_glibmm.info --rc geninfo_unexecuted_blocks=1 --ignore-errors mismatch,gcov,source + +echo "Run Tests (Qt)" +chmod +x ./tests/hsmUnitTestsQt +timeout 2m ./tests/hsmUnitTestsQt > ./tests_result_qt.log +lcov -c -d . -b "$source_dir" -o ./coverage_qt.info --rc geninfo_unexecuted_blocks=1 --ignore-errors mismatch,gcov,source \ No newline at end of file