-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (146 loc) · 5.48 KB
/
sync-mlx.yml
File metadata and controls
165 lines (146 loc) · 5.48 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
156
157
158
159
160
161
162
163
164
165
name: Sync MLX
on:
schedule:
- cron: '0 6 * * 1'
workflow_dispatch:
jobs:
update-mlx:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Determine MLX release state
id: mlx
run: |
git submodule update --init --recursive extern/mlx
git -C extern/mlx fetch --tags origin
LATEST_TAG=$(git -C extern/mlx for-each-ref --sort=-version:refname --format='%(refname:strip=2)' refs/tags | grep '^v' | head -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "::error::Failed to determine latest MLX tag"
exit 1
fi
CURRENT_TAG=$(git -C extern/mlx describe --tags --abbrev=0 2>/dev/null || echo "")
echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT"
echo "current_tag=${CURRENT_TAG}" >> "$GITHUB_OUTPUT"
echo "latest_version=${LATEST_TAG#v}" >> "$GITHUB_OUTPUT"
if [ "$CURRENT_TAG" = "$LATEST_TAG" ]; then
echo "MLX submodule already at ${CURRENT_TAG}"
echo "update_needed=false" >> "$GITHUB_OUTPUT"
else
echo "MLX update required: ${CURRENT_TAG:-unknown} -> ${LATEST_TAG}"
echo "update_needed=true" >> "$GITHUB_OUTPUT"
fi
- name: Prepare update branch
if: steps.mlx.outputs.update_needed == 'true'
env:
BRANCH: mlx-sync/${{ steps.mlx.outputs.latest_version }}
run: git checkout -B "$BRANCH"
- name: Update MLX submodule
if: steps.mlx.outputs.update_needed == 'true'
run: |
git -C extern/mlx checkout ${{ steps.mlx.outputs.latest_tag }}
git add extern/mlx
- name: Setup Python
if: steps.mlx.outputs.update_needed == 'true'
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Update package versions
if: steps.mlx.outputs.update_needed == 'true'
env:
VERSION: ${{ steps.mlx.outputs.latest_version }}
run: |
python3 <<'PY'
import os
import re
from pathlib import Path
version = os.environ["VERSION"]
props_path = Path("Directory.Build.props")
text = props_path.read_text()
text = re.sub(r"<Version>[^<]+</Version>", f"<Version>{version}</Version>", text)
text = re.sub(r"<PackageVersion>[^<]+</PackageVersion>", f"<PackageVersion>{version}</PackageVersion>", text)
props_path.write_text(text)
PY
git add Directory.Build.props
- name: Commit changes
if: steps.mlx.outputs.update_needed == 'true'
id: commit
env:
TAG: ${{ steps.mlx.outputs.latest_tag }}
run: |
if git diff --cached --quiet; then
echo "No staged 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 commit -m "mlx: sync to ${TAG}"
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Setup .NET
if: steps.commit.outputs.changed == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Build solution
if: steps.commit.outputs.changed == 'true'
run: |
dotnet restore
dotnet build --configuration Release --no-restore
- name: Push changes
if: steps.commit.outputs.changed == 'true'
env:
BRANCH: mlx-sync/${{ steps.mlx.outputs.latest_version }}
run: |
git push --force --set-upstream origin "$BRANCH"
- name: Create or update pull request
if: steps.commit.outputs.changed == 'true'
uses: actions/github-script@v7
env:
BRANCH: mlx-sync/${{ steps.mlx.outputs.latest_version }}
PR_TITLE: "MLX: sync to ${{ steps.mlx.outputs.latest_tag }}"
PR_BODY: |
- Update `extern/mlx` submodule to `${{ steps.mlx.outputs.latest_tag }}`
- Align package version fields to `${{ steps.mlx.outputs.latest_version }}`
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = process.env.BRANCH;
const title = process.env.PR_TITLE;
const body = process.env.PR_BODY;
const owner = context.repo.owner;
const repo = context.repo.repo;
const base = context.payload.repository.default_branch;
const { data: existing } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: `${owner}:${branch}`,
});
if (existing.length > 0) {
const pr = existing[0];
await github.rest.pulls.update({
owner,
repo,
pull_number: pr.number,
title,
body,
});
core.info(`Updated PR ${pr.html_url}`);
} else {
const { data: pr } = await github.rest.pulls.create({
owner,
repo,
head: branch,
base,
title,
body,
});
core.info(`Created PR ${pr.html_url}`);
}