Merge pull request #91 from rudnerbjoern/dev #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # GitHub Actions Workflow: Combine XSD Schema v3.2 | |
| # | |
| # This workflow runs on every push to the 'main' branch. | |
| # It combines modular XSD files into a single file, formats the result | |
| # using xmlstarlet, uploads it as an artifact, and creates a pull request. | |
| # | |
| name: Combine XSD Schema v3.2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '3.2/**' | |
| - 'scripts/**' | |
| - '.github/workflows/combine-schema.v3.2.yml' | |
| jobs: | |
| combine-schema: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| INPUT_FILE: 3.2/itop_design.xsd | |
| OUTPUT_FILE: dist/3.2/itop_design.xsd | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Git | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update && sudo apt-get install -y xmlstarlet | |
| pip install -r scripts/requirements.txt | |
| - name: Combine and clean XSD schema | |
| run: | | |
| set -e | |
| echo "Combining input schema: $INPUT_FILE" | |
| python scripts/combine_schema.py $INPUT_FILE $OUTPUT_FILE | |
| echo "Cleaning and formatting schema file..." | |
| xmlstarlet ed -N xs="http://www.w3.org/2001/XMLSchema" \ | |
| -u '//xs:documentation' -x 'normalize-space(.)' "$OUTPUT_FILE" | \ | |
| xmlstarlet fo > "${OUTPUT_FILE}.tmp" | |
| mv "${OUTPUT_FILE}.tmp" "$OUTPUT_FILE" | |
| - name: Show file content before pull request | |
| run: | | |
| echo "Head:" | |
| head -n 20 "$OUTPUT_FILE" | |
| echo "Tail:" | |
| tail -n 20 "$OUTPUT_FILE" | |
| - name: Create pull request | |
| id: create-pull-request | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "Auto: Update itop_design.xsd" | |
| committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
| author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> | |
| branch: auto/update-schema | |
| base: main | |
| title: "Auto: Update itop_design.xsd" | |
| body: "This PR was automatically created by a GitHub Action." | |
| labels: auto-update | |
| draft: false | |
| delete-branch: true | |
| - name: Wait for PR to be mergeable | |
| run: | | |
| echo "Waiting for PR to be mergeable..." | |
| for i in {1..30}; do | |
| MERGEABLE=$(gh pr view ${{ steps.create-pull-request.outputs.pull-request-url }} --json mergeable --jq .mergeable) | |
| echo "MERGEABLE = $MERGEABLE" | |
| if [[ "$MERGEABLE" == "MERGEABLE" || "$MERGEABLE" == "mergeable" ]]; then | |
| break | |
| fi | |
| echo "Still not mergeable, retrying in 10s... ($i/30)" | |
| sleep 10 | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Enable automerge | |
| uses: "peter-evans/enable-pull-request-automerge@v3" | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| pull-request-number: ${{ steps.create-pull-request.outputs.pull-request-number }} | |
| merge-method: squash | |
| - name: Delete branch after merge | |
| if: ${{ steps.create-pull-request.outputs.pull-request-operation == 'updated' || steps.create-pull-request.outputs.pull-request-operation == 'created' }} | |
| run: | | |
| echo "Waiting for merge..." | |
| for i in {1..30}; do | |
| MERGED_AT=$(gh pr view ${{ steps.create-pull-request.outputs.pull-request-url }} --json mergedAt --jq .mergedAt) | |
| if [ "$MERGED_AT" != "null" ]; then | |
| echo "PR merged at $MERGED_AT, deleting branch..." | |
| git push origin --delete auto/update-schema | |
| break | |
| fi | |
| echo "Not merged yet, retrying in 10s... ($i/30)" | |
| sleep 10 | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |