diff --git a/.github/workflows/commit_to_main.yml b/.github/workflows/commit_to_main.yml deleted file mode 100644 index 42ab65f..0000000 --- a/.github/workflows/commit_to_main.yml +++ /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 df746e0..92d7157 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -53,33 +53,9 @@ 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 + 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 new file mode 100644 index 0000000..f4060e6 --- /dev/null +++ b/.github/workflows/pull_request_precommit.yml @@ -0,0 +1,23 @@ +name: Pull request precommit tasks + +on: + # This workflow is only valid for pull_request events + #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 + # 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 new file mode 100644 index 0000000..5601035 --- /dev/null +++ b/.github/workflows/render.yml @@ -0,0 +1,68 @@ +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: true + type: string + remote_url: + required: true + 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: | + set -u + 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 origin ${BRANCH_NAME} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH_NAME: ${{ inputs.branch_name }} + REMOTE_URL: ${{ inputs.remote_url }}