Skip to content

Commit 40158a8

Browse files
authored
Add xml to yaml converter, update Markdown and Yaml files automatically when pull requests are merged (#117)
This pull request adds the capability to render the XML standard names dictionary to Yaml, in addition to the existing rendering to Markdown. I decided to render comments into long strings that the Python Yaml library then wraps correctly. I validated the resulting Yaml file using https://yamlchecker.com and it is valid. This pull request further updates the existing GitHub action for consistency and standard Yaml formatting (2-space indentation), and replaces the check if the Markdown is updated with tests to render the xml to both md and yaml. Lastly, a second GitHub workflow is added that automatically renders the xml to md and yaml and commits the files to the repository. This action is only run when the authoritative branch (main) is updated (push = merge a pull request). I tested this action in my fork of ESM standard names (see https://github.com/climbfuji/CCPPStandardNames/actions/runs/15637497788/job/44056347886). What I did not test is how this works with branch protection (my main branch was not protected). We will find out if additional settings/changes are needed once this PR is approved and merged. Closes #113
1 parent 139788b commit 40158a8

File tree

6 files changed

+5917
-106
lines changed

6 files changed

+5917
-106
lines changed

.github/workflows/commit_to_main.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Render xml standard name dictionary to markdown and yaml and commit to repository
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
update-md-and-yaml:
10+
name: Render xml to markdown and yaml and commit
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: "3.x"
24+
25+
- name: Configure git
26+
run: |
27+
git config --global user.name "github-actions[bot]"
28+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
30+
- name: Install dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get -y install libxml2-utils
34+
python -m pip install --upgrade pip
35+
python -m pip install PyYaml
36+
37+
- name: Render xml to markdown
38+
run: |
39+
tools/write_standard_name_table.py --output-format md standard_names.xml
40+
echo "The following changes will be committed (git diff Metadata-standard-names.md):"
41+
git diff Metadata-standard-names.md
42+
git add Metadata-standard-names.md
43+
44+
- name: Rendering xml to yaml
45+
run: |
46+
tools/write_standard_name_table.py --output-format yaml standard_names.xml
47+
echo "The following changes will be committed (git diff Metadata-standard-names.yaml):"
48+
git diff Metadata-standard-names.yaml
49+
git add Metadata-standard-names.yaml
50+
51+
- name: Commit and push changes
52+
run: |
53+
git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit"
54+
git push
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pull_request_ci.yml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
name: Pull request checks
22

33
on:
4-
pull_request:
54
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
- release/*
69

710
jobs:
811
check-unique-standard-names:
12+
name: Check for duplicates in standard names
913
runs-on: ubuntu-latest
1014
steps:
11-
- uses: actions/checkout@v4
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
1217

13-
- uses: actions/setup-python@v4
18+
- name: Setup Python
19+
uses: actions/setup-python@v4
1420
with:
1521
python-version: "3.x"
1622

17-
- name: Install xmllint
23+
- name: Install dependencies
1824
run: |
19-
sudo apt-get update
20-
sudo apt-get -y install libxml2-utils
25+
sudo apt-get update
26+
sudo apt-get -y install libxml2-utils
2127
2228
- name: Check for duplicate standard names
23-
run: tools/check_xml_unique.py standard_names.xml
29+
run: |
30+
tools/check_xml_unique.py standard_names.xml
2431
2532
check-name-rules:
2633
name: Check standard names against rules
@@ -30,42 +37,49 @@ jobs:
3037
- name: Checkout repository
3138
uses: actions/checkout@v4
3239

33-
- uses: actions/setup-python@v4
40+
- name: Setup Python
41+
uses: actions/setup-python@v4
3442
with:
3543
python-version: "3.x"
3644

37-
# Install dependencies
3845
- name: Install dependencies
3946
run: |
4047
sudo apt-get update
4148
sudo apt-get -y install libxml2-utils
4249
43-
4450
- name: Checks standard names against character rules
4551
run: |
4652
python3 tools/check_name_rules.py -s standard_names.xml
4753
48-
check-rerendered-markdown:
54+
test-rendering:
55+
name: Test rendering xml file to markdown and yaml
4956
runs-on: ubuntu-latest
5057
steps:
51-
- uses: actions/checkout@v4
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
5260

53-
- uses: actions/setup-python@v4
61+
- name: Setup Python
62+
uses: actions/setup-python@v4
5463
with:
5564
python-version: "3.x"
5665

57-
- name: Install xmllint
66+
- name: Install dependencies
5867
run: |
59-
sudo apt-get update
60-
sudo apt-get -y install libxml2-utils
68+
sudo apt-get update
69+
sudo apt-get -y install libxml2-utils
70+
python -m pip install --upgrade pip
71+
python -m pip install PyYaml
6172
62-
- name: Check markdown has been rerendered
73+
- name: Test rendering xml file to markdown
6374
run: |
64-
# Checks if the saved markdown matches freshly rendered markdown.
65-
# If this fails you have likely forgotten to rerun the write script
66-
# after adding a new name, or updating its description.
67-
checksum=$(sha256sum Metadata-standard-names.md)
68-
tools/write_standard_name_table.py standard_names.xml
69-
test "$checksum" = "$(sha256sum Metadata-standard-names.md)"
70-
75+
tools/write_standard_name_table.py --output-format md standard_names.xml
76+
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; "
77+
echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):"
78+
git diff Metadata-standard-names.md
7179
80+
- name: Test rendering xml file to yaml
81+
run: |
82+
tools/write_standard_name_table.py --output-format yaml standard_names.xml
83+
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; "
84+
echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):"
85+
git diff Metadata-standard-names.yaml

Metadata-standard-names.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Earth System Modeling Standard Name Library
1+
# Earth System Modeling Standard Name Library - add some chunk here to test auto update
22
#### Table of Contents
33
* [dimensions](#dimensions)
44
* [constants](#constants)

0 commit comments

Comments
 (0)