diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 9a4b816..7cfb1bb 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -87,6 +87,11 @@ on: required: false default: 'build/gcovr-coverage' type: string + coverage_xml_path: + description: 'The path to the coverage xml, relative to the github workspace' + required: false + default: 'build/coverage.xml' + type: string coverage_deploy_target_repo: description: 'The repository to deploy the coverage report to' required: true @@ -148,6 +153,11 @@ on: required: false default: 'true' type: string + run_coverage_badge_creation: + description: 'Run coverage badge creation' + required: false + default: '${{ inputs.run_coverage == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}' + type: string run_install: description: 'Run install' required: false @@ -298,16 +308,23 @@ jobs: if-no-files-found: error name: coverage-report path: ${{ inputs.coverage_report_path }} + - name: Archive coverage xml + if: ${{ steps.run_coverage.outcome == 'success' || steps.run_coverage.outcome == 'failure' }} + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + name: coverage-xml + path: ${{ inputs.coverage_xml_path}} - name: Deploy html coverage report id: deploy_coverage_report if: ${{ steps.run_coverage.outcome == 'success' || steps.run_coverage.outcome == 'failure' }} # LTODO update tag - uses: everest/everest-ci/github-actions/deploy-ci-logs@feature/add-reusable-ci-workflow + uses: everest/everest-ci/github-actions/deploy-ci-artifact@feature/add-reusable-ci-workflow with: target_repo: ${{ inputs.coverage_deploy_target_repo }} - target_logs_name: coverage-report - logs_dir: ${{ inputs.coverage_report_path }} github_token: ${{ secrets.coverage_deploy_token }} + artifact_name: coverage-report + artifact_directory: ${{ inputs.coverage_report_path }} - name: Write summary coverage if: ${{ steps.run_coverage.outcome == 'success' || steps.run_coverage.outcome == 'failure' }} run: | @@ -413,3 +430,30 @@ jobs: display-options: fEX fail-on-empty: True title: Test results + create_coverage_badge: + name: Create Coverage Badge + needs: + - build + runs-on: ${{ inputs.runner }} + if: ${{ inputs.run_coverage_badge_creation == 'true' }} + steps: + - name: Download coverage report + uses: actions/download-artifact@v4.1.2 + with: + if-no-files-found: error + name: coverage-xml + path: coverage-xml + - name: Generate coverage badge + run: | + # LTODO install in docker image + pip install genbadge[all] + mkdir -p ${{ github.workspace }}/coverage-badge/ + genbadge -i ${{ github.workspace }}/coverage-xml/gcovr-coverage-xml.xml -o ${{ github.workspace }}/coverage-badge/coverage-badge.svg -n "Coverage" --local -v + - name: Deploy coverage badge + # LTODO update version + uses: everest/everest-ci/github-actions/deploy-ci-artifact@feature/add-reusable-ci-workflow + with: + target_repo: ${{ github.repository }} + github_token: ${{ secrets.SA_GITHUB_PAT }} + artifact_name: coverage-badge + artifact_directory: ${{ github.workspace }}/coverage-badge/ diff --git a/github-actions/deploy-ci-artifact/action.yaml b/github-actions/deploy-ci-artifact/action.yaml new file mode 100644 index 0000000..a91b7a9 --- /dev/null +++ b/github-actions/deploy-ci-artifact/action.yaml @@ -0,0 +1,76 @@ +name: 'Deploy CI Artifact' +description: 'Deploy CI artifact to a github pages repository' +inputs: + target_repo: + description: 'Repository to deploy artifact to' + required: true + github_token: + description: 'Github token, with write access to the target repository' + required: true + source_repo: + description: 'Repository to deploy artifact from' + required: true + default: ${{ github.repository }} + workflow_run_id: + description: 'Workflow run id to deploy logs from' + required: true + default: ${{ github.run_id }} + deploy_global_artifact: + description: 'Deploy global artifact, without workflow_run_id' + required: false + default: false + artifact_name: + description: 'Name of the artifact to deploy' + required: true + artifact_directory: + description: 'Directory or containing the artifact to deploy' + required: true +outputs: + deployed_path: + description: 'Path to the deployed logs' + value: ${{ steps.determine_target_path.outputs.target_path }} +runs: + using: "composite" + steps: + - name: Configure git + shell: bash + run: | + git config --global user.email "compiler@pionix.de" + git config --global user.name "Github Service Account" + - name: Checkout target repository + uses: actions/checkout@v3.0.0 + with: + repository: ${{ inputs.target_repo }} + path: gh-pages-repo + token: ${{ inputs.github_token }} + ref: main + - name: Determine target path + id: determine_target_path + shell: bash + run: | + if [ "${{ inputs.deploy_global_artifact }}" = "true" ]; then + target_path="ci-artifacts/${{ inputs.source_repo }}/${{ inputs.artifact_name }}" + else + target_path="ci-artifacts/${{ inputs.source_repo }}/${{ inputs.workflow_run_id }}/${{ inputs.artifact_name }}" + fi + echo "target_path=$target_path" >> $GITHUB_OUTPUT + - name: Copy Artifact + shell: bash + run: | + mkdir -p gh-pages-repo/${{ steps.determine_target_path.outputs.target_path }} + if [ "${{ inputs.deploy_global_artifact }}" = "true" ]; then + rm -rf gh-pages-repo/${{ steps.determine_target_path.outputs.target_path }}/* + fi + cp -r ${{ inputs.artifact_directory }}/* gh-pages-repo/${{ steps.determine_target_path.outputs.target_path }} + - name: Commit and push logs + shell: bash + run: | + git add ${{ steps.determine_target_path.outputs.target_path }} + if [ "${{ inputs.deploy_global_artifact }}" = "true" ]; then + commit_message="Deploy global artifact and remove old one: ${{ inputs.source_repo }}/${{ inputs.artifact_name }}" + else + git commit -m "Deploy new artifact: ${{ inputs.source_repo }}/${{ inputs.workflow_run_id }}/${{ inputs.artifact_name }}" + fi + git commit -m "$commit_message" + git push + working-directory: gh-pages-repo diff --git a/github-actions/deploy-ci-logs/action.yaml b/github-actions/deploy-ci-logs/action.yaml deleted file mode 100644 index c0ef4e6..0000000 --- a/github-actions/deploy-ci-logs/action.yaml +++ /dev/null @@ -1,60 +0,0 @@ -name: 'Deploy CI Logs' -description: 'Deploy CI logs to a github pages repository' -inputs: - target_repo: - description: 'Repository to deploy logs to' - required: true - source_repo: - description: 'Repository to deploy logs from' - required: true - default: ${{ github.repository }} - workflow_run_id: - description: 'Workflow run id to deploy logs from' - required: true - default: ${{ github.run_id }} - target_logs_name: - description: 'Name of the logs to deploy' - required: true - logs_dir: - description: 'Directory containing the logs to deploy' - required: true - github_token: - description: 'Github token, with write access to the target repository' - required: true -outputs: - deployed_path: - description: 'Path to the deployed logs' - value: ${{ steps.determine_target_path.outputs.target_path }} -runs: - using: "composite" - steps: - - name: Configure git - shell: bash - run: | - git config --global user.email "compiler@pionix.de" - git config --global user.name "Github Service Account" - - name: Checkout target repository - uses: actions/checkout@v3.0.0 - with: - repository: ${{ inputs.target_repo }} - path: gh-pages-repo - token: ${{ inputs.github_token }} - ref: main - - name: Determine target path - id: determine_target_path - shell: bash - run: | - target_path="ci-logs/${{ inputs.source_repo }}/${{ inputs.workflow_run_id }}/${{ inputs.target_logs_name }}" - echo "target_path=$target_path" >> $GITHUB_OUTPUT - - name: Copy logs - shell: bash - run: | - mkdir -p gh-pages-repo/${{ steps.determine_target_path.outputs.target_path }} - cp -r ${{ inputs.logs_dir }}/* gh-pages-repo/${{ steps.determine_target_path.outputs.target_path }} - - name: Commit and push logs - shell: bash - run: | - git add ${{ steps.determine_target_path.outputs.target_path }} - git commit -m "Deploy logs: ${{ inputs.source_repo }}/${{ inputs.workflow_run_id }}/${{ inputs.target_logs_name }}" - git push - working-directory: gh-pages-repo