forked from ufs-community/ufs-srweather-app
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.24 KB
/
Copy pathconfig_docs_autofix.yaml
File metadata and controls
101 lines (91 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Config Docs Autofix
on:
pull_request_target:
types:
- labeled
- synchronize
- reopened
- ready_for_review
defaults:
run:
shell: bash -leo pipefail {0}
permissions:
contents: write
pull-requests: write
jobs:
config_docs_autofix:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && contains(github.event.pull_request.labels.*.name, 'autofix-config-docs') }}
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Fetch base branch
run: git fetch origin "${{ github.event.pull_request.base.ref }}"
- name: Apply config doc autofix
run: |
python scripts/autofix_configworkflow_docs.py \
--base-ref "origin/${{ github.event.pull_request.base.ref }}"
- name: Commit and push changes
id: commit_changes
run: |
if git diff --quiet -- doc/UsersGuide/CustomizingTheWorkflow/ConfigWorkflow.rst; then
echo "No autofix changes to commit"
echo "changed=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add doc/UsersGuide/CustomizingTheWorkflow/ConfigWorkflow.rst
git commit -m "docs: autofix ConfigWorkflow sync"
git push
echo "changed=true" >> "${GITHUB_OUTPUT}"
- name: Comment on PR
if: ${{ !cancelled() && steps.commit_changes.outputs.changed == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const body = [
'<!-- configworkflow-doc-autofix -->',
'Applied the ConfigWorkflow doc autofix workflow.',
'',
'- Updated stale inline defaults when possible',
'- Added or refreshed an autogenerated stub section for still-undocumented variables',
'',
'Review the generated changes before merging.'
].join('\n');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body &&
comment.body.includes('<!-- configworkflow-doc-autofix -->')
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}