Skip to content

Commit a9f7534

Browse files
committed
Fix render.yml: configure branch name, use correct boolean type for inputs
1 parent 0b4ff91 commit a9f7534

File tree

3 files changed

+84
-60
lines changed

3 files changed

+84
-60
lines changed

.github/workflows/pull_request_ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,27 @@ jobs:
5151
run: |
5252
python3 tools/check_name_rules.py -s standard_names.xml
5353
54+
#set-branch-name:
55+
# name: Determine branch name for pull request and workflow_dispatch events
56+
# runs-on: ubuntu-latest
57+
# outputs:
58+
# branch_name: ${{ steps.set-branch.outputs.branch_name }}
59+
# steps:
60+
# - id: set-branch
61+
# run: |
62+
# if [ "${{ github.event_name }}" = "pull_request" ]; then
63+
# echo "branch_name=${{ github.head_ref }}" >> $GITHUB_OUTPUT
64+
# else
65+
# echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
66+
# fi
67+
5468
test-rendering:
5569
name: Test rendering xml file to markdown and yaml
5670
needs: [check-unique-standard-names, check-name-rules]
5771
uses: ./.github/workflows/render.yml
5872
with:
5973
commit_to_branch: false
74+
#branch_name: ${{ github.event_name == "pull_request" && github.head_ref || github.ref_name }}
6075
#runs-on: ubuntu-latest
6176
#steps:
6277
# - name: Checkout repository

.github/workflows/pull_request_precommit.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Pull request precommit tasks
22

33
on:
4-
workflow_dispatch:
4+
#workflow_dispatch:
55
pull_request:
66
branches:
77
- main
@@ -16,6 +16,9 @@ jobs:
1616
uses: ./.github/workflows/render.yml
1717
with:
1818
commit_to_branch: true
19+
# github.head_ref is the branch from which a pull request is made
20+
branch_name: ${{ github.head_ref }} # ${{ github.event_name == "pull_request" && github.head_ref || github.ref_name }}
21+
1922
#runs-on: ubuntu-latest
2023
#steps:
2124
# - name: Checkout repository

.github/workflows/render.yml

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,65 @@
1-
name: Render XML to output formats and optionally commit to branch
2-
3-
on:
4-
workflow_call:
5-
inputs:
6-
commit_to_branch:
7-
required: true
8-
type: string
9-
10-
#env:
11-
# #COMMIT_TO_BRANCH: ${{ inputs.commit_to_branch }}
12-
13-
jobs:
14-
15-
render_to_markdown_and_yaml:
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Checkout repository
19-
uses: actions/checkout@v4
20-
21-
- name: Setup Python
22-
uses: actions/setup-python@v4
23-
with:
24-
python-version: "3.x"
25-
26-
- name: Install dependencies
27-
run: |
28-
sudo apt-get update
29-
sudo apt-get -y install libxml2-utils
30-
python -m pip install --upgrade pip
31-
python -m pip install PyYaml
32-
33-
- name: Render xml file to markdown
34-
run: |
35-
tools/write_standard_name_table.py --output-format md standard_names.xml
36-
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; "
37-
echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):"
38-
git diff Metadata-standard-names.md
39-
40-
- name: Rendering xml file to yaml
41-
run: |
42-
tools/write_standard_name_table.py --output-format yaml standard_names.xml
43-
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; "
44-
echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):"
45-
git diff Metadata-standard-names.yaml
46-
47-
- name: Configure git
48-
if: ${{ inputs.commit_to_branch }}
49-
run: |
50-
git config --global user.name "github-actions[bot]"
51-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
52-
53-
- name: Commit and push changes
54-
if: ${{ inputs.commit_to_branch }}
55-
run: |
56-
git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit"
57-
git push
58-
env:
59-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1+
name: Render XML to output formats and optionally commit to branch
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
commit_to_branch:
7+
required: true
8+
type: boolean
9+
branch_name:
10+
required: false
11+
type: string
12+
13+
jobs:
14+
15+
render_to_markdown_and_yaml:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.x"
25+
26+
- name: Install dependencies
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get -y install libxml2-utils
30+
python -m pip install --upgrade pip
31+
python -m pip install PyYaml
32+
33+
- name: Render xml file to markdown
34+
run: |
35+
tools/write_standard_name_table.py --output-format md standard_names.xml
36+
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.md; "
37+
echo "assuming that 'Metadata-standard-names.md' wasn't updated and matches the version in the authoritative branch):"
38+
git diff Metadata-standard-names.md
39+
40+
- name: Rendering xml file to yaml
41+
run: |
42+
tools/write_standard_name_table.py --output-format yaml standard_names.xml
43+
echo "The following changes will be committed when this pull request is merged (git diff Metadata-standard-names.yaml; "
44+
echo "assuming that 'Metadata-standard-names.yaml' wasn't updated and matches the version in the authoritative branch):"
45+
git diff Metadata-standard-names.yaml
46+
47+
- name: Configure git, commit and push changes
48+
if: ${{ inputs.commit_to_branch }}
49+
run: |
50+
git config --global user.name "github-actions[bot]"
51+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
52+
#export BRANCH_NAME=${{ github.event_name == "pull_request" && github.head_ref || github.ref_name }}
53+
if [[ ! -v ${{ inputs.branch_name }} ]]; then
54+
echo "inputs.branch_name not set"
55+
exit 1
56+
fi
57+
git checkout -b ${{ inputs.branch_name }}
58+
#git checkout -b ${BRANCH_NAME}
59+
#git commit -m "Update Metadata-standard-names.{md,yaml} from standard_names.xml" || echo "No changes to commit"
60+
git remote -v show
61+
git status
62+
git push # origin ${BRANCH_NAME}
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
#BRANCH_NAME: ${{ github.event_name == "pull_request" && github.head_ref || github.ref_name }}

0 commit comments

Comments
 (0)