1515 paths :
1616 - ' 3.2/**'
1717 - ' scripts/**'
18- - ' .github/workflows/combine-schema.yml'
18+ - ' .github/workflows/combine-schema.v3.2. yml'
1919
2020jobs :
2121 combine-schema :
@@ -30,61 +30,79 @@ jobs:
3030 steps :
3131 - name : Checkout repository
3232 uses : actions/checkout@v4
33+ with :
34+ token : ${{ secrets.GITHUB_TOKEN }}
35+
36+ - name : Set up Git
37+ run : |
38+ git config user.name "github-actions"
39+ git config user.email "[email protected] " 3340
3441 - name : Set up Python
3542 uses : actions/setup-python@v5
3643 with :
3744 python-version : ' 3.x'
3845
39- - name : Install Python dependencies
40- run : pip install -r scripts/requirements.txt
41-
42- - name : Install xmlstarlet
43- run : sudo apt-get update && sudo apt-get install -y xmlstarlet
44-
45- - name : Combine XSD schema into single file
46- run : python scripts/combine_schema.py $INPUT_FILE $OUTPUT_FILE
47-
48- - name : Beautify and normalize XSD with xmlstarlet
46+ - name : Install dependencies
4947 run : |
50- xmlstarlet fo --omit-decl $OUTPUT_FILE > tmp.xml && mv tmp.xml $OUTPUT_FILE
51- xmlstarlet ed -P -L -u "//xs:documentation/text()" -x "normalize-space(.)" $OUTPUT_FILE
52- rm -f tmp.xml
48+ sudo apt-get update && sudo apt-get install -y xmlstarlet
49+ pip install -r scripts/requirements.txt
5350
54- - name : Set artifact path
55- id : vars
56- run : echo "path=$OUTPUT_FILE" >> "$GITHUB_OUTPUT"
51+ - name : Combine and clean XSD schema
52+ run : |
53+ set -e
54+ echo "Combining input schema: $INPUT_FILE"
55+ python scripts/combine_schema.py $INPUT_FILE $OUTPUT_FILE
5756
58- - name : Upload merged XSD as artifact
59- uses : actions/upload-artifact@v4
60- with :
61- name : combined-xsd
62- path : ${{ steps.vars.outputs.path }}
57+ echo "Cleaning and formatting schema file..."
58+ xmlstarlet ed -N xs="http://www.w3.org/2001/XMLSchema" \
59+ -u '//xs:documentation' -x 'normalize-space(.)' "$OUTPUT_FILE" | \
60+ xmlstarlet fo > "${OUTPUT_FILE}.tmp"
61+ mv "${OUTPUT_FILE}.tmp" "$OUTPUT_FILE"
6362
64- - name : Commit combined schema
65- id : commit
63+ - name : Show file content before pull request
6664 run : |
67- git config --global user.name "GitHub Action"
68- git config --global user.email "[email protected] " 69- git checkout -b auto/schema-update
70- git add $OUTPUT_FILE || echo "No changes to add"
71- git status
72- if ! git diff --cached --quiet; then
73- git commit -m "Auto-update combined schema"
74- git push origin auto/schema-update
75- echo "changes_present=true" >> "$GITHUB_OUTPUT"
76- else
77- echo "No changes to commit."
78- echo "changes_present=false" >> "$GITHUB_OUTPUT"
79- fi
65+ echo "Head:"
66+ head -n 20 "$OUTPUT_FILE"
67+ echo "Tail:"
68+ tail -n 20 "$OUTPUT_FILE"
8069
81- - name : Create pull request with updated schema
82- if : success() && steps.commit.outputs.changes_present == 'true'
83- uses : peter-evans/create-pull-request@v5
70+ - name : Create pull request
71+ id : create-pull-request
72+ uses : peter-evans/create-pull-request@v6
8473 with :
8574 token : ${{ secrets.GITHUB_TOKEN }}
86- commit-message : Auto-update combined schema
87- branch : auto/schema-update
88- title : ' Auto-update combined schema '
89- body : ' This PR was automatically created by the Combine XSD Schema workflow. '
75+ commit-message : " Auto: Update itop_design.xsd "
76+ committer : github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
77+ author : ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
78+ branch : auto/update-schema
9079 base : main
80+ title : " Auto: Update itop_design.xsd"
81+ body : " This PR was automatically created by a GitHub Action."
82+ labels : auto-update
83+ draft : false
84+ delete-branch : true
85+
86+ - name : Enable automerge
87+ uses : " peter-evans/enable-pull-request-automerge@v3"
88+ with :
89+ token : ${{ secrets.GITHUB_TOKEN }}
90+ pull-request-number : ${{ steps.create-pull-request.outputs.pull-request-number }}
91+ merge-method : squash
92+
93+ - name : Delete branch after merge
94+ if : ${{ steps.create-pull-request.outputs.pull-request-operation == 'updated' || steps.create-pull-request.outputs.pull-request-operation == 'created' }}
95+ run : |
96+ echo "Waiting for merge..."
97+ for i in {1..30}; do
98+ MERGED_AT=$(gh pr view ${{ steps.create-pull-request.outputs.pull-request-url }} --json mergedAt --jq .mergedAt)
99+ if [ "$MERGED_AT" != "null" ]; then
100+ echo "PR merged at $MERGED_AT, deleting branch..."
101+ git push origin --delete auto/update-schema
102+ break
103+ fi
104+ echo "Not merged yet, retrying in 10s... ($i/30)"
105+ sleep 10
106+ done
107+ env :
108+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments