From 0b4ff918713af15362701a69f6cd863b3ed83bd7 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 17 Jul 2025 14:46:57 -0600 Subject: [PATCH 1/5] Test render+commit based on label --- ...mit_to_main.yml => commit_to_main.yml.off} | 0 .github/workflows/pull_request_ci.yml | 64 ++++++++++--------- .github/workflows/pull_request_precommit.yml | 48 ++++++++++++++ .github/workflows/render.yml | 59 +++++++++++++++++ 4 files changed, 141 insertions(+), 30 deletions(-) rename .github/workflows/{commit_to_main.yml => commit_to_main.yml.off} (100%) create mode 100644 .github/workflows/pull_request_precommit.yml create mode 100644 .github/workflows/render.yml diff --git a/.github/workflows/commit_to_main.yml b/.github/workflows/commit_to_main.yml.off similarity index 100% rename from .github/workflows/commit_to_main.yml rename to .github/workflows/commit_to_main.yml.off diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml index df746e0..81c6a5b 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -53,33 +53,37 @@ jobs: test-rendering: name: Test rendering xml file to markdown and yaml - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get -y install libxml2-utils - python -m pip install --upgrade pip - python -m pip install PyYaml - - - name: Test rendering xml file to markdown - run: | - tools/write_standard_name_table.py --output-format md standard_names.xml - echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " - echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" - git diff Metadata-standard-names.md - - - name: Test rendering xml file to yaml - run: | - tools/write_standard_name_table.py --output-format yaml standard_names.xml - echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " - echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" - git diff Metadata-standard-names.yaml + needs: [check-unique-standard-names, check-name-rules] + uses: ./.github/workflows/render.yml + with: + commit_to_branch: false + #runs-on: ubuntu-latest + #steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + # + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: "3.x" + # + # - name: Install dependencies + # run: | + # sudo apt-get update + # sudo apt-get -y install libxml2-utils + # python -m pip install --upgrade pip + # python -m pip install PyYaml + # + # - name: Test rendering xml file to markdown + # run: | + # tools/write_standard_name_table.py --output-format md standard_names.xml + # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " + # echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" + # git diff Metadata-standard-names.md + # + # - name: Test rendering xml file to yaml + # run: | + # tools/write_standard_name_table.py --output-format yaml standard_names.xml + # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " + # echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" + # git diff Metadata-standard-names.yaml diff --git a/.github/workflows/pull_request_precommit.yml b/.github/workflows/pull_request_precommit.yml new file mode 100644 index 0000000..0884c31 --- /dev/null +++ b/.github/workflows/pull_request_precommit.yml @@ -0,0 +1,48 @@ +name: Pull request precommit tasks + +on: + workflow_dispatch: + pull_request: + branches: + - main + - release/* + types: [labeled] + +jobs: + + render-and-commit: + name: Rendering xml file to markdown and yaml, and commit to branch + if: ${{ github.event.label.name == 'render-and-commit' }} + uses: ./.github/workflows/render.yml + with: + commit_to_branch: true + #runs-on: ubuntu-latest + #steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + # + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: "3.x" + # + # - name: Install dependencies + # run: | + # sudo apt-get update + # sudo apt-get -y install libxml2-utils + # python -m pip install --upgrade pip + # python -m pip install PyYaml + # + # - name: Test rendering xml file to markdown + # run: | + # tools/write_standard_name_table.py --output-format md standard_names.xml + # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " + # echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" + # git diff Metadata-standard-names.md + # + # - name: Test rendering xml file to yaml + # run: | + # tools/write_standard_name_table.py --output-format yaml standard_names.xml + # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " + # echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" + # git diff Metadata-standard-names.yaml diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml new file mode 100644 index 0000000..8998483 --- /dev/null +++ b/.github/workflows/render.yml @@ -0,0 +1,59 @@ +name: Render XML to output formats and optionally commit to branch + +on: + workflow_call: + inputs: + commit_to_branch: + required: true + type: string + +#env: +# #COMMIT_TO_BRANCH: ${{ inputs.commit_to_branch }} + +jobs: + + render_to_markdown_and_yaml: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get -y install libxml2-utils + python -m pip install --upgrade pip + python -m pip install PyYaml + + - name: Render xml file to markdown + run: | + tools/write_standard_name_table.py --output-format md standard_names.xml + echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " + echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" + git diff Metadata-standard-names.md + + - name: Rendering xml file to yaml + run: | + tools/write_standard_name_table.py --output-format yaml standard_names.xml + echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " + echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" + git diff Metadata-standard-names.yaml + + - name: Configure git + if: ${{ inputs.commit_to_branch }} + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Commit and push changes + if: ${{ inputs.commit_to_branch }} + run: | + git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d91ae113b90a8703f8bed1d6beacafeaeb739896 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 17 Jul 2025 17:15:36 -0600 Subject: [PATCH 2/5] Fix render.yml: configure branch name, use correct boolean type for inputs --- .github/workflows/commit_to_main.yml.off | 56 --------- .github/workflows/pull_request_ci.yml | 30 ----- .github/workflows/pull_request_precommit.yml | 35 +----- .github/workflows/render.yml | 121 ++++++++++--------- 4 files changed, 66 insertions(+), 176 deletions(-) delete mode 100644 .github/workflows/commit_to_main.yml.off diff --git a/.github/workflows/commit_to_main.yml.off b/.github/workflows/commit_to_main.yml.off deleted file mode 100644 index 42ab65f..0000000 --- a/.github/workflows/commit_to_main.yml.off +++ /dev/null @@ -1,56 +0,0 @@ -name: Render xml standard name dictionary to markdown and yaml and commit to repository - -on: - push: - branches: - - main - -jobs: - update-md-and-yaml: - name: Render xml to markdown and yaml and commit - runs-on: ubuntu-latest - - permissions: - contents: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Configure git - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get -y install libxml2-utils - python -m pip install --upgrade pip - python -m pip install PyYaml - - - name: Render xml to markdown - run: | - tools/write_standard_name_table.py --output-format md standard_names.xml - echo "The following changes will be committed (git diff Metadata-standard-names.md):" - git diff Metadata-standard-names.md - git add Metadata-standard-names.md - - - name: Rendering xml to yaml - run: | - tools/write_standard_name_table.py --output-format yaml standard_names.xml - echo "The following changes will be committed (git diff Metadata-standard-names.yaml):" - git diff Metadata-standard-names.yaml - git add Metadata-standard-names.yaml - - - name: Commit and push changes - run: | - git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" - git push - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml index 81c6a5b..1cf8aac 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -57,33 +57,3 @@ jobs: uses: ./.github/workflows/render.yml with: commit_to_branch: false - #runs-on: ubuntu-latest - #steps: - # - name: Checkout repository - # uses: actions/checkout@v4 - # - # - name: Setup Python - # uses: actions/setup-python@v4 - # with: - # python-version: "3.x" - # - # - name: Install dependencies - # run: | - # sudo apt-get update - # sudo apt-get -y install libxml2-utils - # python -m pip install --upgrade pip - # python -m pip install PyYaml - # - # - name: Test rendering xml file to markdown - # run: | - # tools/write_standard_name_table.py --output-format md standard_names.xml - # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " - # echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" - # git diff Metadata-standard-names.md - # - # - name: Test rendering xml file to yaml - # run: | - # tools/write_standard_name_table.py --output-format yaml standard_names.xml - # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " - # echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" - # git diff Metadata-standard-names.yaml diff --git a/.github/workflows/pull_request_precommit.yml b/.github/workflows/pull_request_precommit.yml index 0884c31..536601f 100644 --- a/.github/workflows/pull_request_precommit.yml +++ b/.github/workflows/pull_request_precommit.yml @@ -1,7 +1,8 @@ name: Pull request precommit tasks on: - workflow_dispatch: + # This workflow is only valid for pull_request events + #workflow_dispatch: pull_request: branches: - main @@ -16,33 +17,5 @@ jobs: uses: ./.github/workflows/render.yml with: commit_to_branch: true - #runs-on: ubuntu-latest - #steps: - # - name: Checkout repository - # uses: actions/checkout@v4 - # - # - name: Setup Python - # uses: actions/setup-python@v4 - # with: - # python-version: "3.x" - # - # - name: Install dependencies - # run: | - # sudo apt-get update - # sudo apt-get -y install libxml2-utils - # python -m pip install --upgrade pip - # python -m pip install PyYaml - # - # - name: Test rendering xml file to markdown - # run: | - # tools/write_standard_name_table.py --output-format md standard_names.xml - # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " - # echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" - # git diff Metadata-standard-names.md - # - # - name: Test rendering xml file to yaml - # run: | - # tools/write_standard_name_table.py --output-format yaml standard_names.xml - # echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " - # echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" - # git diff Metadata-standard-names.yaml + # github.head_ref is the branch from which a pull request is made + branch_name: ${{ github.head_ref }} diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 8998483..0195a32 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -1,59 +1,62 @@ -name: Render XML to output formats and optionally commit to branch - -on: - workflow_call: - inputs: - commit_to_branch: - required: true - type: string - -#env: -# #COMMIT_TO_BRANCH: ${{ inputs.commit_to_branch }} - -jobs: - - render_to_markdown_and_yaml: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get -y install libxml2-utils - python -m pip install --upgrade pip - python -m pip install PyYaml - - - name: Render xml file to markdown - run: | - tools/write_standard_name_table.py --output-format md standard_names.xml - echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " - echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" - git diff Metadata-standard-names.md - - - name: Rendering xml file to yaml - run: | - tools/write_standard_name_table.py --output-format yaml standard_names.xml - echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " - echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" - git diff Metadata-standard-names.yaml - - - name: Configure git - if: ${{ inputs.commit_to_branch }} - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - - name: Commit and push changes - if: ${{ inputs.commit_to_branch }} - run: | - git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" - git push - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +name: Render XML to output formats and optionally commit to branch + +on: + workflow_call: + inputs: + commit_to_branch: + required: true + type: boolean + branch_name: + required: false + type: string + +jobs: + + render_to_markdown_and_yaml: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get -y install libxml2-utils + python -m pip install --upgrade pip + python -m pip install PyYaml + + - name: Render xml file to markdown + run: | + tools/write_standard_name_table.py --output-format md standard_names.xml + echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; " + echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):" + git diff Metadata-standard-names.md + + - name: Rendering xml file to yaml + run: | + tools/write_standard_name_table.py --output-format yaml standard_names.xml + echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; " + echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):" + git diff Metadata-standard-names.yaml + + - name: Configure git, commit and push changes + if: ${{ inputs.commit_to_branch }} + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + if [[ ! -v ${{ inputs.branch_name }} ]]; then + echo "inputs.branch_name not set" + exit 1 + fi + git checkout -b ${{ inputs.branch_name }} + git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" + git remote -v show + git status + git push # origin ${BRANCH_NAME} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 94cf4066d930b37707b3a2cb487a0ec964781fed Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Fri, 18 Jul 2025 05:59:59 -0600 Subject: [PATCH 3/5] Debugging render+commit --- .github/workflows/pull_request_ci.yml | 1 + .github/workflows/render.yml | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml index 1cf8aac..aedc68c 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -57,3 +57,4 @@ jobs: uses: ./.github/workflows/render.yml with: commit_to_branch: false + branch_name: "invalid_branch_name" diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 0195a32..a89319b 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -7,7 +7,7 @@ on: required: true type: boolean branch_name: - required: false + required: true type: string jobs: @@ -49,14 +49,17 @@ jobs: run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - if [[ ! -v ${{ inputs.branch_name }} ]]; then - echo "inputs.branch_name not set" - exit 1 - fi - git checkout -b ${{ inputs.branch_name }} - git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" - git remote -v show - git status - git push # origin ${BRANCH_NAME} + echo "BRANCH_NAME is '${{ inputs.branch_name }}'" + if [[ ! -v ${BRANCH_NAME} ]]; then + ### if [[ -z "$DEPLOY_ENV" ]]; then + ### echo "BRANCH_NAME is not defined" + ### exit 1 + ### fi + ### git checkout -b ${{ inputs.branch_name }} + ### git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" + ### git remote -v show + ### git status + ### git push # origin ${BRANCH_NAME} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH_NAME: ${{ inputs.branch_name }} From 7512cbffc58594db96ce6e71b86990e3f1a8dc47 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Fri, 18 Jul 2025 06:06:45 -0600 Subject: [PATCH 4/5] Debugging render+commit --- .github/workflows/render.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index a89319b..bbd2a3c 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -47,19 +47,16 @@ jobs: - name: Configure git, commit and push changes if: ${{ inputs.commit_to_branch }} run: | + set -u + echo "Submitting rendered standard name dictionaries to branch ${BRANCH_NAME}" + set +u git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - echo "BRANCH_NAME is '${{ inputs.branch_name }}'" - if [[ ! -v ${BRANCH_NAME} ]]; then - ### if [[ -z "$DEPLOY_ENV" ]]; then - ### echo "BRANCH_NAME is not defined" - ### exit 1 - ### fi - ### git checkout -b ${{ inputs.branch_name }} - ### git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" - ### git remote -v show - ### git status - ### git push # origin ${BRANCH_NAME} + git checkout -b ${BRANCH_NAME} + git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" + git remote -v show + git status + git push env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_NAME: ${{ inputs.branch_name }} From 5fb3b5b66e2b07191c1ea081b863eebaae781e6f Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Fri, 18 Jul 2025 06:20:56 -0600 Subject: [PATCH 5/5] Debugging render+commit --- .github/workflows/pull_request_ci.yml | 1 + .github/workflows/pull_request_precommit.yml | 2 ++ .github/workflows/render.yml | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml index aedc68c..92d7157 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -58,3 +58,4 @@ jobs: with: commit_to_branch: false branch_name: "invalid_branch_name" + remote_url: "invalid_remote_url" diff --git a/.github/workflows/pull_request_precommit.yml b/.github/workflows/pull_request_precommit.yml index 536601f..f4060e6 100644 --- a/.github/workflows/pull_request_precommit.yml +++ b/.github/workflows/pull_request_precommit.yml @@ -19,3 +19,5 @@ jobs: commit_to_branch: true # github.head_ref is the branch from which a pull request is made branch_name: ${{ github.head_ref }} + # github.event.pull_request.head.repo.clone_url is the URL from where the pull request is made + remote_url: ${{ github.event.pull_request.head.repo.clone_url }} diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index bbd2a3c..5601035 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -9,7 +9,10 @@ on: branch_name: required: true type: string - + remote_url: + required: true + type: string + jobs: render_to_markdown_and_yaml: @@ -48,15 +51,18 @@ jobs: if: ${{ inputs.commit_to_branch }} run: | set -u - echo "Submitting rendered standard name dictionaries to branch ${BRANCH_NAME}" + echo "Submitting rendered standard name dictionaries to branch ${BRANCH_NAME} in ${REMOTE_URL}" set +u git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" + git remote set-url origin ${REMOTE_URL} git checkout -b ${BRANCH_NAME} + git add . git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit" git remote -v show git status - git push + git push origin ${BRANCH_NAME} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_NAME: ${{ inputs.branch_name }} + REMOTE_URL: ${{ inputs.remote_url }}