-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (139 loc) · 4.67 KB
/
source-sync.yml
File metadata and controls
155 lines (139 loc) · 4.67 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: source-sync
on:
workflow_call:
inputs:
logic_repository:
description: Repository that contains the generator logic.
required: true
type: string
logic_ref:
description: Ref to check out from the generator repository.
required: true
type: string
source_repository:
description: Repository that contains the source .msra tree.
required: true
type: string
source_ref:
description: Branch or ref to read from the source repository.
required: true
type: string
source_msra_path:
description: Path to the root .msra file within the source repository.
required: true
type: string
target_repository:
description: Repository that should receive the generated artifact.
required: true
type: string
target_ref:
description: Branch to update in the target repository.
required: true
type: string
generator_python_version:
description: Python version for the generator runtime.
required: false
type: string
default: "3.12"
generator_requirements_path:
description: Relative path to the generator requirements file.
required: false
type: string
default: "msra_codegen/requirements.txt"
commit_user_name:
description: Git user.name used for generated commits.
required: false
type: string
default: "msra-sync-bot"
commit_user_email:
description: Git user.email used for generated commits.
required: false
type: string
default: "msra-sync-bot@users.noreply.github.com"
secrets:
repo_token:
required: true
permissions:
contents: read
concurrency:
group: source-sync-${{ inputs.target_repository }}-${{ inputs.target_ref }}
cancel-in-progress: true
jobs:
source-sync:
runs-on: ubuntu-latest
steps:
- name: Check out generator repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.logic_repository }}
ref: ${{ inputs.logic_ref }}
path: logic
token: ${{ secrets.repo_token }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.generator_python_version }}
- name: Install generator dependencies
working-directory: logic
run: |
python -m pip install --upgrade pip
python -m pip install -r "${{ inputs.generator_requirements_path }}"
- name: Check out source branch
uses: actions/checkout@v4
with:
repository: ${{ inputs.source_repository }}
ref: ${{ inputs.source_ref }}
path: source
token: ${{ secrets.repo_token }}
fetch-depth: 0
- name: Check out target branch
uses: actions/checkout@v4
with:
repository: ${{ inputs.target_repository }}
ref: ${{ inputs.target_ref }}
path: target
token: ${{ secrets.repo_token }}
fetch-depth: 0
- name: Generate artifact into a staging tree
working-directory: logic
run: |
source_msra_path="${{ inputs.source_msra_path }}"
python -m msra_codegen generate "../source/$source_msra_path" -o ../generated
- name: Replace target tree contents
run: |
python - <<'PY'
from pathlib import Path
import shutil
target = Path("target")
generated = Path("generated")
for child in list(target.iterdir()):
if child.name == ".git":
continue
if child.is_dir():
shutil.rmtree(child)
else:
child.unlink()
for item in generated.iterdir():
destination = target / item.name
if item.is_dir():
shutil.copytree(item, destination, dirs_exist_ok=True)
else:
shutil.copy2(item, destination)
PY
- name: Validate generated project
working-directory: logic
run: |
python -m msra_codegen validate ../target
- name: Commit and push
working-directory: target
run: |
git config user.name "${{ inputs.commit_user_name }}"
git config user.email "${{ inputs.commit_user_email }}"
git add -A
if git diff --cached --quiet; then
echo "No generated changes to commit."
exit 0
fi
git commit -m "Regenerate artifact from source"
git push origin HEAD:${{ inputs.target_ref }}