-
Notifications
You must be signed in to change notification settings - Fork 43
182 lines (157 loc) · 6.37 KB
/
v0.7.0_mono_prepare_validate.yaml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: 0.7.0 - Mono (Prepare, Validate)
on:
workflow_dispatch:
concurrency:
group: dev-branch-prepare-workflow
cancel-in-progress: false
jobs:
set-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies for matrix generation
run: pip install toml
- name: Get workspace members
id: get-matrix
run: |
cd pkgs
python - <<'EOF'
import toml, json, os
# Open the root pyproject.toml file
with open("pyproject.toml", "r") as f:
config = toml.load(f)
# Extract the workspace members from tool.uv.workspace.members
members = config.get("tool", {}).get("uv", {}).get("workspace", {}).get("members", [])
if not isinstance(members, list):
raise Exception("The 'members' entry is not a list.")
# Build a matrix with one entry per member
matrix = {"include": [{"member": member} for member in members]}
print(f"Matrix: {json.dumps(matrix)}")
# Write the matrix JSON to the GitHub Actions output
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"matrix={json.dumps(matrix)}", file=fh)
EOF
test:
needs: set-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies for testing
run: pip install uv pytest toml
- name: Bump Version Placeholder
run: |
MEMBER="${{ matrix.member }}"
echo "Running tests for workspace member: $MEMBER"
# Read the package name from the member's pyproject.toml
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])")
echo "Package name: $PACKAGE_NAME"
uv run --active scripts/bump_pyproject_version.py --bump patch ${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml
- name: Ruff format
run: |
cd pkgs
MEMBER="${{ matrix.member }}"
echo "Running tests for workspace member: $MEMBER"
# Read the package name from the member's pyproject.toml
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])")
echo "Package name: $PACKAGE_NAME"
# Run the test command with uv
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active ruff format .
- name: Ruff lint check & fix
run: |
cd pkgs
MEMBER="${{ matrix.member }}"
echo "Running tests for workspace member: $MEMBER"
# Read the package name from the member's pyproject.toml
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])")
echo "Package name: $PACKAGE_NAME"
# Run the test command with uv
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active ruff check . --fix
- name: Run tests for member ${{ matrix.member }}
run: |
cd pkgs
MEMBER="${{ matrix.member }}"
echo "Running tests for workspace member: $MEMBER"
# Read the package name from the member's pyproject.toml
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])")
echo "Package name: $PACKAGE_NAME"
# Run the test command with uv
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active pytest -vvv
- name: Create patch for changes
if: always()
run: |
mkdir -p patches
MEMBER="${{ matrix.member }}"
# Replace "/" with "-" to ensure a safe filename
SAFE_MEMBER=$(echo "$MEMBER" | tr '/' '-')
# Check for changes in the member directory (located under pkgs)
if [ -n "$(git -C pkgs status --porcelain "$MEMBER")" ]; then
git -C pkgs diff "$MEMBER" > patches/patch_${SAFE_MEMBER}.patch
else
echo "No changes in ${MEMBER} to create a patch."
fi
- name: Set safe member variable
id: set_safe_member
run: |
echo "SAFE_MEMBER=$(echo '${{ matrix.member }}' | tr '/' '-')" >> $GITHUB_OUTPUT
- name: Upload patch artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: patch-${{ steps.set_safe_member.outputs.SAFE_MEMBER }}
path: patches/patch_${{ steps.set_safe_member.outputs.SAFE_MEMBER }}.patch
if-no-files-found: warn
commit:
name: Commit Changes
needs: test
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Download patch artifacts
uses: actions/download-artifact@v4
with:
# This will download all artifacts that start with "patch
path: patches
- name: Apply patches
run: |
for patch in patches/*.patch; do
if [ -f "$patch" ]; then
echo "Applying patch $patch"
git apply --directory=pkgs "$patch" || true
fi
done
- name: Git Commit and Push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
rm -rf patches
git add .
if ! git diff-index --quiet HEAD; then
git commit -m "chore: apply automatic formatting and lint fixes"
git pull --rebase origin "${{ github.ref }}"
git push origin HEAD:"${{ github.ref }}"
else
echo "No changes to commit."
fi