diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index 72e61c9..3f80572 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -1,5 +1,22 @@ + + 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..c6f3283 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -72,14 +72,31 @@ jobs: - name: Test rendering xml file to markdown run: | + # Checks if the saved markdown matches freshly rendered markdown. + # If this fails, prompt user to update 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 + if ! git diff --exit-code --quiet; then + echo "❌ Detected that Metadata-standard-names.md is not consistent with standard_names.xml" + echo "✅ To fix: Run the following command locally and commit the result:" + echo " tools/write_standard_name_table.py --output-format md standard_names.xml" + echo "📘 This script requires the pyyaml Python package; to install with pip use command:" + echo " python -m pip install PyYaml" + echo "📘 For conda users, environment file tools/environment.yml is provided." + echo + exit 1 + fi - 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 + if ! git diff --exit-code --quiet; then + echo "❌ Detected that Metadata-standard-names.yaml is not consistent with standard_names.xml" + echo "✅ To fix: Run the following command locally and commit the result:" + echo " tools/write_standard_name_table.py --output-format yaml standard_names.xml" + echo "📘 This script requires the pyyaml Python package; to install with pip use command:" + echo " python -m pip install PyYaml" + echo "📘 For conda users, environment file tools/environment.yml is provided." + echo + exit 1 + fi + diff --git a/Metadata-standard-names.md b/Metadata-standard-names.md index 35c7921..a8b9f45 100644 --- a/Metadata-standard-names.md +++ b/Metadata-standard-names.md @@ -1,4 +1,4 @@ -# Earth System Modeling Standard Name Library - add some chunk here to test auto update +# Earth System Modeling Standard Name Library #### Table of Contents * [dimensions](#dimensions) * [constants](#constants) diff --git a/Metadata-standard-names.yaml b/Metadata-standard-names.yaml index 88fd9db..d7f8f85 100644 --- a/Metadata-standard-names.yaml +++ b/Metadata-standard-names.yaml @@ -1,4 +1,4 @@ -library_name: Earth System Modeling Standard Name Library - add some chunk here to test auto update +library_name: Earth System Modeling Standard Name Library sections: - name: dimensions comment: 'Dimension standard names may come in sets of six related standard names diff --git a/README.md b/README.md index 138c7c9..dfbd491 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ The Earth System Modeling Standard Names Repository contains community-accepted Rules governing the designation and format of standard names can be found in [StandardNamesRules.rst](https://github.com/ESCOMP/ESMStandardNames/blob/main/StandardNamesRules.rst) -A [Markdown file describing the standard names is included](https://github.com/ESCOMP/ESMStandardNames/blob/main/Metadata-standard-names.md), as well as a [Yaml version of the XML file](https://github.com/ESCOMP/ESMStandardNames/blob/main/Metadata-standard-names.yaml). +A [Markdown file describing the standard names is included](https://github.com/ESCOMP/ESMStandardNames/blob/main/Metadata-standard-names.md), as well as a [YAML version of the XML file](https://github.com/ESCOMP/ESMStandardNames/blob/main/Metadata-standard-names.yaml). -Edits to standard names must be made in the xml file `standard_names.xml` only. When pull requests are merged into the authoritative branch, a tool is run in GitHub actions that automatically updates the human-readable standard name Markdown file and the Yaml version. +Edits to standard names must be made in the xml file `standard_names.xml` only. When a pull request is opened into the main branch, the YAML and Markdown files should be updated using the `tools/write_standard_name_table.py` script. This can be done manually by the pull request author, or by activating the GitHub action available on an open pull request. diff --git a/tools/environment.yml b/tools/environment.yml new file mode 100644 index 0000000..2090fcd --- /dev/null +++ b/tools/environment.yml @@ -0,0 +1,5 @@ +name: test +channels: + - conda-forge +dependencies: + - pyyaml