Skip to content

Use CMake's junit output to augment test results #583

Use CMake's junit output to augment test results

Use CMake's junit output to augment test results #583

Workflow file for this run

name: DSL logs and checks
on:
pull_request:
paths:
# Can not restrict it to jenkins-scripts/dsl/** since there are sanity
# checks on generated XML done on removal/addition of scripts in jenkins-scripts
- 'jenkins-scripts/**'
jobs:
xml_generation:
runs-on: ubuntu-latest
name: Generate XML config from DSL
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Download and setup job dsl jar
run: ./jenkins-scripts/dsl/tools/setup_local_generation.bash
- name: Generate XML files
run: |
# Remove existing logs files. Code is adding content to them but not re-generating
# simulate token for brew_release
sudo mkdir -p /var/lib/jenkins/ && sudo touch /var/lib/jenkins/remote_token
sudo chown -R ${USER} /var/lib/jenkins
pushd jenkins-scripts/dsl
rm -fr logs && mkdir logs
WRITE_JOB_LOG=1 java -jar tools/jobdsl.jar *.dsl
find logs/* -exec sort {} -o {} \;
popd
- name: Checks for existing scripts in docker/
run: |
cd jenkins-scripts/docker
./sanity_checks.bash
- name: Checks for DSL Code
run: |
cd jenkins-scripts/dsl
./dsl_checks.bash
- name: Export XML generated configuration for diff
run: |
cd jenkins-scripts/dsl
# export files for later diff
mkdir /tmp/pr_xml_configuration
mv *.xml /tmp/pr_xml_configuration/
- name: Upload generated logs
uses: actions/upload-artifact@v4
with:
name: dsl_logs
path: jenkins-scripts/dsl/logs/
- name: Generate master DSL files
run: |
git clean -f -e jobdsl.jar
git checkout master
cd jenkins-scripts/dsl
WRITE_JOB_LOG=1 java -jar tools/jobdsl.jar *.dsl
mkdir /tmp/current_xml_configuration
mv *.xml /tmp/current_xml_configuration/
- name: Generating diffs
run: |
# somehow the Jenkins views changed the portlet_ id on every run.
diff -qr -I '.*<id>dashboard_portlet_.*</id>.*' /tmp/current_xml_configuration /tmp/pr_xml_configuration | sort > /tmp/xml_config_files_changed.diff || true
diff -ur -I '.*<id>dashboard_portlet_.*</id>.*' /tmp/current_xml_configuration /tmp/pr_xml_configuration > /tmp/xml_config_content_changed.diff || true
- name: Archive files changes
uses: actions/upload-artifact@v4
with:
name: xml_config_files_changed
path: /tmp/xml_config_files_changed.diff
- name: Archive content changes
uses: actions/upload-artifact@v4
with:
name: xml_config_content_changed
path: /tmp/xml_config_content_changed.diff
publish_results:
runs-on: ubuntu-latest
name: Commit logs and publish diffs
needs: xml_generation
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Download generated logs
uses: actions/download-artifact@v4
with:
name: dsl_logs
path: jenkins-scripts/dsl/logs/
- name: Update and commit logs generated
uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d # v5 sha
with:
file_pattern: jenkins-scripts/dsl/logs/
commit_message: 'Automated change: update logs [skip ci]'
- name: Download files changed diff
uses: actions/download-artifact@v4
with:
name: xml_config_files_changed
path: /tmp/
- name: Download content changed diff
uses: actions/download-artifact@v4
with:
name: xml_config_content_changed
path: /tmp/
- name: Publish diffs in a comment
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const MAX_BODY_SIZE = 60000;
const filesChanged = fs.readFileSync('/tmp/xml_config_files_changed.diff', 'utf8').trim();
let contentChanged = fs.readFileSync('/tmp/xml_config_content_changed.diff', 'utf8').trim();
if (contentChanged.length > MAX_BODY_SIZE) {
contentChanged = contentChanged.substring(0, MAX_BODY_SIZE) +
'\n... (truncated, diff too large for a GitHub comment)';
}
// Use a code fence longer than any backtick sequence in the diff to prevent markdown injection
const maxBt = (contentChanged.match(/`+/g) || []).reduce((max, s) => Math.max(max, s.length), 2);
const fence = '`'.repeat(maxBt + 1);
const output = `### This is an automatic response from the CI system for Jenkins DSL generation.
Below is the list of Jenkins XML configuration files changed by this PR (from changes to DSL) and the content changed in the configuration files:
#### :open_file_folder: XML Jenkins configuration files changed in this PR
<details>
${filesChanged ? filesChanged.split('\n').map(l => '> ' + l).join('\n') : '_No XML configuration files were changed._'}
</details>
#### :bookmark_tabs: Content changed in the XML configuration files in this PR
<details>
${contentChanged ? fence + 'diff\n' + contentChanged + '\n' + fence : '_No content differences detected._'}
</details>
`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})