From 906436c38885f42499e90d438217cab4f4f3ff44 Mon Sep 17 00:00:00 2001 From: Kai Hudalla Date: Wed, 14 Aug 2024 16:34:52 +0200 Subject: [PATCH] Use GitHub variable to define OFT file patterns --- .github/actions/run-oft/action.yaml | 87 ++++++++++++++----- .../check-up-spec-compatibility.yaml | 6 +- .github/workflows/nightly.yaml | 17 ++++ .github/workflows/requirements-tracing.yaml | 12 ++- 4 files changed, 94 insertions(+), 28 deletions(-) diff --git a/.github/actions/run-oft/action.yaml b/.github/actions/run-oft/action.yaml index 2bf78e5..6bd2f38 100644 --- a/.github/actions/run-oft/action.yaml +++ b/.github/actions/run-oft/action.yaml @@ -23,11 +23,6 @@ inputs: A whitespace separated list of glob patterns which specify the files to include in the OFT trace run. default: "**/*.*" required: false - java-version: - description: | - The version of Java to use for running OpenFastTrace. - default: "21" - required: false outputs: requirements-tracing-exit-code: description: | @@ -41,37 +36,81 @@ outputs: runs: using: "composite" steps: - - name: Prepare Environment - shell: bash + - shell: bash run: | + # Prepare Environment echo "TRACING_REPORT_FILE_NAME=requirements-tracing-report.html" >> $GITHUB_ENV - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: "temurin" - java-version: ${{ inputs.java-version }} - - name: Download OpenFastTrace JARs - shell: bash + - shell: bash env: OFT_REPO_BASE: "https://github.com/itsallcode" OFT_CORE_VERSION: "4.1.0" OFT_ASCIIDOC_PLUGIN_VERSION: "0.2.0" + LIB_DIR: ${{ github.workspace }}/lib + run: | + # Download OpenFastTrace JARs + mkdir "${LIB_DIR}" + curl -L --output-dir "${LIB_DIR}" -O \ + "${OFT_REPO_BASE}/openfasttrace/releases/download/${OFT_CORE_VERSION}/openfasttrace-${OFT_CORE_VERSION}.jar" + curl -L --output-dir "${LIB_DIR}" -O \ + "${OFT_REPO_BASE}/openfasttrace-asciidoc-plugin/releases/download/${OFT_ASCIIDOC_PLUGIN_VERSION}/openfasttrace-asciidoc-plugin-${OFT_ASCIIDOC_PLUGIN_VERSION}-with-dependencies.jar" + - shell: bash + env: + CLASSPATH: ${{ github.workspace }}/lib/* run: | - mkdir "${{ github.workspace }}/lib" - curl -L -o "${{ github.workspace }}/lib/openfasttrace.jar" \ - "${{ env.OFT_REPO_BASE }}/openfasttrace/releases/download/${{ env.OFT_CORE_VERSION }}/openfasttrace-${{ env.OFT_CORE_VERSION }}.jar" - curl -L -o "${{ github.workspace }}/lib/openfasttrace-asciidoc-plugin.jar" \ - "${{ env.OFT_REPO_BASE }}/openfasttrace-asciidoc-plugin/releases/download/${{ env.OFT_ASCIIDOC_PLUGIN_VERSION }}/openfasttrace-asciidoc-plugin-${{ env.OFT_ASCIIDOC_PLUGIN_VERSION }}-with-dependencies.jar" - - name: Run OpenFastTrace - id: run-oft + # Verify installed JRE is sufficient for running OFT + # by default, use latest Java version + required_java_version=22 + minimum_class_file_format_version=66 + javap_path=$(which javap) + + # determine if the installed JRE is sufficient for running OFT + if [[ -n ${javap_path} ]]; then + installed_jre_class_file_format_version=$(javap -verbose java.lang.String | grep "major version" | cut -d " " -f5) + echo "Installed JRE supports class file format version ${installed_jre_class_file_format_version}" + + oft_core_class_file_format_version=$(javap -verbose -cp "${CLASSPATH}" org.itsallcode.openfasttrace.core.cli.CliStarter | grep "major version" | cut -d " " -f5) + asciidoc_plugin_class_file_format_version=$(javap -verbose -cp "${CLASSPATH}" org.itsallcode.openfasttrace.importer.asciidoc.AsciiDocImporter | grep "major version" | cut -d " " -f5) + + # determine the minimum class file format version needed for running OFT + if [[ ${oft_core_class_file_format_version} -ge ${asciidoc_plugin_class_file_format_version} ]]; then + minimum_class_file_format_version=${oft_core_class_file_format_version} + else + minimum_class_file_format_version=${asciidoc_plugin_class_file_format_version} + fi + echo "OpenFastTrace requires JRE supporting class file format version ${minimum_class_file_format_version}" + + # check if the installed JRE is sufficient + if [[ ${installed_jre_class_file_format_version} -lt ${minimum_class_file_format_version} ]]; then + echo "OpenFastTrace cannot be run with installed JRE, requesting installation of JDK version ${required_java_version}" + echo "REQUIRED_JAVA_VERSION=${required_java_version}" >> $GITHUB_ENV + else + echo "Installed JRE is sufficient for running OpenFastTrace" + fi + + else + echo "OpenFastTrace requires a JRE, requesting installation of Java version ${required_java_version}" + # install latest Java LTS and hope for the best + echo "REQUIRED_JAVA_VERSION=${required_java_version}" >> $GITHUB_ENV + fi + + - name: Set up JDK + if: ${{ env.REQUIRED_JAVA_VERSION != '' }} + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: ${{ env.REQUIRED_JAVA_VERSION }} + + - id: run-oft shell: bash env: + CLASSPATH: ${{ github.workspace }}/lib/* INPUT_FILE_PATTERNS: ${{ inputs.file-patterns }} run: | - if java -cp "${{ github.workspace }}/lib/*" \ + # Run OpenFastTrace + if java -cp "${CLASSPATH}" \ org.itsallcode.openfasttrace.core.cli.CliStarter trace -o html \ - -f "${{ env.TRACING_REPORT_FILE_NAME }}" \ - ${{ env.INPUT_FILE_PATTERNS }}; + -f "${TRACING_REPORT_FILE_NAME}" \ + ${INPUT_FILE_PATTERNS}; then echo "requirements-tracing-exit-code=0" >> $GITHUB_OUTPUT echo "All requirements from uProtocol Specification are covered by crate." >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/check-up-spec-compatibility.yaml b/.github/workflows/check-up-spec-compatibility.yaml index a7fbef0..f17b0f9 100644 --- a/.github/workflows/check-up-spec-compatibility.yaml +++ b/.github/workflows/check-up-spec-compatibility.yaml @@ -12,7 +12,9 @@ # *******************************************************************************/ # Verifies that this crate can be built using the uProtocol Core API from up-spec's main branch. -# Also performs requirements tracing using OpenFastTrace +# Also performs requirements tracing using OpenFastTrace. For that purpose, the workflow requires +# the UP_SPEC_OPEN_FAST_TRACE_FILE_PATTERNS variable to contain the file patterns to use for +# invoking the "run-oft" Action. name: uP Spec Compatibility @@ -51,6 +53,8 @@ jobs: # a tracing report - name: Run OpenFastTrace uses: ./.github/actions/run-oft + with: + file-patterns: ${{ vars.UP_SPEC_OPEN_FAST_TRACE_FILE_PATTERNS }} # now try to build and run the tests which may fail if incomaptible changes # have been introduced in up-spec diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 65e51e7..fb29451 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -53,3 +53,20 @@ jobs: coverage: uses: ./.github/workflows/coverage.yaml + + requirements-tracing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Run OpenFastTrace + id: run-oft + uses: ./.github/actions/run-oft + with: + file-patterns: ${{ vars.UP_SPEC_OPEN_FAST_TRACE_FILE_PATTERNS }} + + - name: "Determine exit code" + run: | + exit ${{ steps.run-oft.outputs.requirements-tracing-exit-code }} diff --git a/.github/workflows/requirements-tracing.yaml b/.github/workflows/requirements-tracing.yaml index a928985..9e2441d 100644 --- a/.github/workflows/requirements-tracing.yaml +++ b/.github/workflows/requirements-tracing.yaml @@ -22,11 +22,13 @@ on: oft-file-patterns: description: | A whitespace separated list of glob patterns which specify the files to include in the OFT trace run. - If not specified, defaults to all files relevant for checking up-rust against the uProtocol Specification. + If not specified, defaults to the value of the `UP_SPEC_OPEN_FAST_TRACE_FILE_PATTERNS` variable. + If that variable is empty, defaults to the _run-oft_ Action's default file pattern(s). type: string outputs: tracing_report_url: - description: 'URL of the requirements tracing report' + description: | + URL of the requirements tracing report. value: ${{ jobs.tracing.outputs.requirements-tracing-report-url }} workflow_dispatch: pull_request: @@ -42,11 +44,15 @@ jobs: with: submodules: "recursive" + - run: | + echo "inputs:" + echo "${{ inputs }}" + echo "oft-file-patterns: ${{ inputs.oft-file-patterns || 'N/A' }}" - name: Run OpenFastTrace id: run-oft uses: ./.github/actions/run-oft with: - file-patterns: ${{ inputs.oft-file-patterns || '*.md *.rs .github examples src tests tools up-spec/*.adoc up-spec/*.md up-spec/basics up-spec/up-l2/api.adoc' }} + file-patterns: ${{ inputs.oft-file-patterns || vars.UP_SPEC_OPEN_FAST_TRACE_FILE_PATTERNS }} - name: "Determine exit code" run: |