|
44 | 44 | echo "update_needed=true" >> "$GITHUB_OUTPUT"
|
45 | 45 | fi
|
46 | 46 |
|
| 47 | + - name: Prepare update branch |
| 48 | + if: steps.mlx.outputs.update_needed == 'true' |
| 49 | + env: |
| 50 | + BRANCH: chore/sync-mlx-${{ steps.mlx.outputs.latest_version }} |
| 51 | + run: git checkout -B "$BRANCH" |
| 52 | + |
47 | 53 | - name: Update MLX submodule
|
48 | 54 | if: steps.mlx.outputs.update_needed == 'true'
|
49 | 55 | run: |
|
@@ -74,31 +80,86 @@ jobs:
|
74 | 80 | props_path.write_text(text)
|
75 | 81 | PY
|
76 | 82 | git add Directory.Build.props
|
77 |
| - - name: Setup .NET |
| 83 | +
|
| 84 | + - name: Commit changes |
78 | 85 | if: steps.mlx.outputs.update_needed == 'true'
|
| 86 | + id: commit |
| 87 | + env: |
| 88 | + TAG: ${{ steps.mlx.outputs.latest_tag }} |
| 89 | + run: | |
| 90 | + if git diff --cached --quiet; then |
| 91 | + echo "No staged changes to commit" |
| 92 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 93 | + exit 0 |
| 94 | + fi |
| 95 | + git config user.name "github-actions[bot]" |
| 96 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 97 | + git commit -m "chore: sync MLX to ${TAG}" |
| 98 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 99 | +
|
| 100 | + - name: Setup .NET |
| 101 | + if: steps.commit.outputs.changed == 'true' |
79 | 102 | uses: actions/setup-dotnet@v4
|
80 | 103 | with:
|
81 | 104 | dotnet-version: 9.0.x
|
82 | 105 |
|
83 | 106 | - name: Build solution
|
84 |
| - if: steps.mlx.outputs.update_needed == 'true' |
| 107 | + if: steps.commit.outputs.changed == 'true' |
85 | 108 | run: |
|
86 | 109 | dotnet restore
|
87 | 110 | dotnet build --configuration Release --no-restore
|
88 | 111 |
|
89 |
| - - name: Prepare PR |
90 |
| - if: steps.mlx.outputs.update_needed == 'true' |
| 112 | + - name: Push changes |
| 113 | + if: steps.commit.outputs.changed == 'true' |
| 114 | + env: |
| 115 | + BRANCH: chore/sync-mlx-${{ steps.mlx.outputs.latest_version }} |
91 | 116 | run: |
|
92 |
| - git status -s |
| 117 | + git push --force --set-upstream origin "$BRANCH" |
93 | 118 |
|
94 |
| - - name: Create pull request |
95 |
| - if: steps.mlx.outputs.update_needed == 'true' |
96 |
| - uses: peter-evans/create-pull-request@v6 |
97 |
| - with: |
98 |
| - branch: "chore/sync-mlx-${{ steps.mlx.outputs.latest_version }}" |
99 |
| - commit-message: "chore: sync MLX to ${{ steps.mlx.outputs.latest_tag }}" |
100 |
| - title: "chore: sync MLX to ${{ steps.mlx.outputs.latest_tag }}" |
101 |
| - body: | |
| 119 | + - name: Create or update pull request |
| 120 | + if: steps.commit.outputs.changed == 'true' |
| 121 | + uses: actions/github-script@v7 |
| 122 | + env: |
| 123 | + BRANCH: chore/sync-mlx-${{ steps.mlx.outputs.latest_version }} |
| 124 | + PR_TITLE: chore: sync MLX to ${{ steps.mlx.outputs.latest_tag }} |
| 125 | + PR_BODY: | |
102 | 126 | - Update `extern/mlx` submodule to `${{ steps.mlx.outputs.latest_tag }}`
|
103 | 127 | - Align package version fields to `${{ steps.mlx.outputs.latest_version }}`
|
104 |
| - signoff: false |
| 128 | + with: |
| 129 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + script: | |
| 131 | + const branch = process.env.BRANCH; |
| 132 | + const title = process.env.PR_TITLE; |
| 133 | + const body = process.env.PR_BODY; |
| 134 | + const owner = context.repo.owner; |
| 135 | + const repo = context.repo.repo; |
| 136 | + const base = context.payload.repository.default_branch; |
| 137 | +
|
| 138 | + const { data: existing } = await github.rest.pulls.list({ |
| 139 | + owner, |
| 140 | + repo, |
| 141 | + state: 'open', |
| 142 | + head: `${owner}:${branch}`, |
| 143 | + }); |
| 144 | +
|
| 145 | + if (existing.length > 0) { |
| 146 | + const pr = existing[0]; |
| 147 | + await github.rest.pulls.update({ |
| 148 | + owner, |
| 149 | + repo, |
| 150 | + pull_number: pr.number, |
| 151 | + title, |
| 152 | + body, |
| 153 | + }); |
| 154 | + core.info(`Updated PR ${pr.html_url}`); |
| 155 | + } else { |
| 156 | + const { data: pr } = await github.rest.pulls.create({ |
| 157 | + owner, |
| 158 | + repo, |
| 159 | + head: branch, |
| 160 | + base, |
| 161 | + title, |
| 162 | + body, |
| 163 | + }); |
| 164 | + core.info(`Created PR ${pr.html_url}`); |
| 165 | + } |
0 commit comments