Skip to content

Commit

Permalink
Automatically update jobs.txt log on pull request changes in DSL (#1089)
Browse files Browse the repository at this point in the history
* Automatically update jobs.txt log on pull request changes in DSL
* Automated change: update logs [skip ci]

---------

Signed-off-by: Jose Luis Rivero <[email protected]>
Co-authored-by: Steven! Ragnarök <[email protected]>
  • Loading branch information
j-rivero and nuclearsandwich authored Dec 12, 2023
1 parent 8f16617 commit bf7fb65
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 34 deletions.
49 changes: 17 additions & 32 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,51 @@ on:
- 'jenkins-scripts/dsl/**'

jobs:
dsl_ci:
xml_generation:
runs-on: ubuntu-latest
name: Diff for DSL code
name: Generate XML config from DSL
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Download and setup job dsl jar
run: ./jenkins-scripts/dsl/tools/setup_local_generation.bash
- name: Generate all DSL files
- 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
cd jenkins-scripts/dsl
pushd jenkins-scripts/dsl
rm -fr logs && mkdir logs
WRITE_JOB_LOG=1 java -jar tools/jobdsl.jar *.dsl
- 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 && mkdir /tmp/pr_log_generated/
# sort jobs.txt
sort jobs.txt -o jobs.txt
mv *.xml /tmp/pr_xml_configuration/
mv *.txt /tmp/pr_log_generated/
find logs/* -exec sort {} -o {} \;
popd
- 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: 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 && mkdir /tmp/current_log_generated/
# sort jobs.txt
sort jobs.txt -o jobs.txt
mkdir /tmp/current_xml_configuration
mv *.xml /tmp/current_xml_configuration/
mv *.txt /tmp/current_log_generated/ || true
- 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
diff -ur /tmp/current_log_generated /tmp/pr_log_generated > /tmp/log_content_changed.diff || true
- name: Archive files changes
uses: actions/upload-artifact@v3
with:
Expand All @@ -71,8 +61,3 @@ jobs:
with:
name: xml_config_content_changed
path: /tmp/xml_config_content_changed.diff
- name: Archive log changes
uses: actions/upload-artifact@v3
with:
name: log_content_changed
path: /tmp/log_content_changed.diff
2 changes: 1 addition & 1 deletion jenkins-scripts/dsl/gazebo_libs.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pkgconf_per_src_index.each { pkg_src, pkg_src_configs ->
}

if (WRITE_JOB_LOG) {
File log_file = new File("jobs.txt")
File log_file = new File("logs/generated_jobs.txt")
logging_list.each { log_type, items ->
items.each { log_file.append("${log_type} ${it.collection} ${it.job_name}\n") }
}
Expand Down
Loading

0 comments on commit bf7fb65

Please sign in to comment.