Skip to content

Commit 188a56a

Browse files
committed
fix: merge workflows to avoid GITHUB_TOKEN limitation
1 parent f232b78 commit 188a56a

File tree

3 files changed

+131
-200
lines changed

3 files changed

+131
-200
lines changed

.github/workflows/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Llama Stack uses GitHub Actions for Continuous Integration (CI). Below is a tabl
1212
| Integration Tests (Replay) | [integration-tests.yml](integration-tests.yml) | Run the integration test suites from tests/integration in replay mode |
1313
| Vector IO Integration Tests | [integration-vector-io-tests.yml](integration-vector-io-tests.yml) | Run the integration test suite with various VectorIO providers |
1414
| Pre-commit | [pre-commit.yml](pre-commit.yml) | Run pre-commit checks |
15-
| Pre-commit Bot - Execute | [precommit-execute.yml](precommit-execute.yml) | Pre-commit bot execution for PR |
16-
| Pre-commit Bot - Trigger | [precommit-trigger.yml](precommit-trigger.yml) | Pre-commit bot trigger |
15+
| Pre-commit Bot | [precommit-trigger.yml](precommit-trigger.yml) | Pre-commit bot for PR |
1716
| Test Llama Stack Build | [providers-build.yml](providers-build.yml) | Test llama stack build |
1817
| Python Package Build Test | [python-build-test.yml](python-build-test.yml) | Test building the llama-stack PyPI project |
1918
| Integration Tests (Record) | [record-integration-tests.yml](record-integration-tests.yml) | Run the integration test suite from tests/integration |

.github/workflows/precommit-execute.yml

Lines changed: 0 additions & 179 deletions
This file was deleted.

.github/workflows/precommit-trigger.yml

Lines changed: 130 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: Pre-commit Bot - Trigger
1+
name: Pre-commit Bot
22

3-
run-name: Pre-commit bot trigger
3+
run-name: Pre-commit bot for PR #${{ github.event.issue.number }}
44

55
on:
66
issue_comment:
77
types: [created]
88

99
jobs:
10-
trigger:
10+
pre-commit:
1111
# Only run on pull request comments
1212
if: github.event.issue.pull_request && contains(github.event.comment.body, '@github-actions run precommit')
1313
runs-on: ubuntu-latest
1414
permissions:
15-
contents: read
15+
contents: write
1616
pull-requests: write
1717

1818
steps:
19-
- name: Check comment author
19+
- name: Check comment author and get PR details
2020
id: check_author
2121
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
2222
with:
@@ -67,12 +67,13 @@ jobs:
6767
return;
6868
}
6969
70-
// Save PR info for the execution workflow
70+
// Save PR info for later steps
7171
core.setOutput('pr_number', context.issue.number);
7272
core.setOutput('pr_head_ref', pr.data.head.ref);
7373
core.setOutput('pr_head_sha', pr.data.head.sha);
7474
core.setOutput('pr_head_repo', pr.data.head.repo.full_name);
7575
core.setOutput('pr_base_ref', pr.data.base.ref);
76+
core.setOutput('is_fork', pr.data.head.repo.full_name !== context.payload.repository.full_name);
7677
core.setOutput('authorized', 'true');
7778
7879
- name: React to comment
@@ -88,29 +89,139 @@ jobs:
8889
content: 'rocket'
8990
});
9091
91-
- name: Trigger execution workflow
92+
- name: Comment starting
9293
if: steps.check_author.outputs.authorized == 'true'
9394
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
9495
with:
9596
github-token: ${{ secrets.GITHUB_TOKEN }}
9697
script: |
97-
await github.rest.actions.createWorkflowDispatch({
98+
await github.rest.issues.createComment({
9899
owner: context.repo.owner,
99100
repo: context.repo.repo,
100-
workflow_id: 'precommit-execute.yml',
101-
ref: context.payload.repository.default_branch,
102-
inputs: {
103-
pr_number: '${{ steps.check_author.outputs.pr_number }}',
104-
pr_head_ref: '${{ steps.check_author.outputs.pr_head_ref }}',
105-
pr_head_sha: '${{ steps.check_author.outputs.pr_head_sha }}',
106-
pr_head_repo: '${{ steps.check_author.outputs.pr_head_repo }}',
107-
pr_base_ref: '${{ steps.check_author.outputs.pr_base_ref }}'
108-
}
101+
issue_number: ${{ steps.check_author.outputs.pr_number }},
102+
body: `⏳ Running pre-commit hooks on PR #${{ steps.check_author.outputs.pr_number }}...`
103+
});
104+
105+
- name: Checkout PR branch (same-repo)
106+
if: steps.check_author.outputs.authorized == 'true' && steps.check_author.outputs.is_fork == 'false'
107+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
108+
with:
109+
ref: ${{ steps.check_author.outputs.pr_head_ref }}
110+
fetch-depth: 0
111+
token: ${{ secrets.GITHUB_TOKEN }}
112+
113+
- name: Checkout PR branch (fork)
114+
if: steps.check_author.outputs.authorized == 'true' && steps.check_author.outputs.is_fork == 'true'
115+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
116+
with:
117+
repository: ${{ steps.check_author.outputs.pr_head_repo }}
118+
ref: ${{ steps.check_author.outputs.pr_head_ref }}
119+
fetch-depth: 0
120+
token: ${{ secrets.GITHUB_TOKEN }}
121+
122+
- name: Verify checkout
123+
if: steps.check_author.outputs.authorized == 'true'
124+
run: |
125+
echo "Current SHA: $(git rev-parse HEAD)"
126+
echo "Expected SHA: ${{ steps.check_author.outputs.pr_head_sha }}"
127+
if [[ "$(git rev-parse HEAD)" != "${{ steps.check_author.outputs.pr_head_sha }}" ]]; then
128+
echo "::error::Checked out SHA does not match expected SHA"
129+
exit 1
130+
fi
131+
132+
- name: Set up Python
133+
if: steps.check_author.outputs.authorized == 'true'
134+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
135+
with:
136+
python-version: '3.12'
137+
cache: pip
138+
cache-dependency-path: |
139+
**/requirements*.txt
140+
.pre-commit-config.yaml
141+
142+
- name: Set up Node.js
143+
if: steps.check_author.outputs.authorized == 'true'
144+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
145+
with:
146+
node-version: '20'
147+
cache: 'npm'
148+
cache-dependency-path: 'llama_stack/ui/'
149+
150+
- name: Install npm dependencies
151+
if: steps.check_author.outputs.authorized == 'true'
152+
run: npm ci
153+
working-directory: llama_stack/ui
154+
155+
- name: Run pre-commit
156+
if: steps.check_author.outputs.authorized == 'true'
157+
id: precommit
158+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
159+
continue-on-error: true
160+
env:
161+
SKIP: no-commit-to-branch
162+
RUFF_OUTPUT_FORMAT: github
163+
164+
- name: Check for changes
165+
if: steps.check_author.outputs.authorized == 'true'
166+
id: changes
167+
run: |
168+
if ! git diff --exit-code || [ -n "$(git ls-files --others --exclude-standard)" ]; then
169+
echo "has_changes=true" >> $GITHUB_OUTPUT
170+
echo "Changes detected after pre-commit"
171+
else
172+
echo "has_changes=false" >> $GITHUB_OUTPUT
173+
echo "No changes after pre-commit"
174+
fi
175+
176+
- name: Commit and push changes
177+
if: steps.check_author.outputs.authorized == 'true' && steps.changes.outputs.has_changes == 'true'
178+
run: |
179+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
180+
git config --local user.name "github-actions[bot]"
181+
182+
git add -A
183+
git commit -m "style: apply pre-commit fixes
184+
185+
🤖 Applied by @github-actions bot via pre-commit workflow"
186+
187+
# Push changes
188+
git push origin HEAD:${{ steps.check_author.outputs.pr_head_ref }}
189+
190+
- name: Comment success with changes
191+
if: steps.check_author.outputs.authorized == 'true' && steps.changes.outputs.has_changes == 'true'
192+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
193+
with:
194+
github-token: ${{ secrets.GITHUB_TOKEN }}
195+
script: |
196+
await github.rest.issues.createComment({
197+
owner: context.repo.owner,
198+
repo: context.repo.repo,
199+
issue_number: ${{ steps.check_author.outputs.pr_number }},
200+
body: `✅ Pre-commit hooks completed successfully!\n\n🔧 Changes have been committed and pushed to the PR branch.`
109201
});
110202
203+
- name: Comment success without changes
204+
if: steps.check_author.outputs.authorized == 'true' && steps.changes.outputs.has_changes == 'false' && steps.precommit.outcome == 'success'
205+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
206+
with:
207+
github-token: ${{ secrets.GITHUB_TOKEN }}
208+
script: |
209+
await github.rest.issues.createComment({
210+
owner: context.repo.owner,
211+
repo: context.repo.repo,
212+
issue_number: ${{ steps.check_author.outputs.pr_number }},
213+
body: `✅ Pre-commit hooks passed!\n\n✨ No changes needed - your code is already formatted correctly.`
214+
});
215+
216+
- name: Comment failure
217+
if: failure()
218+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
219+
with:
220+
github-token: ${{ secrets.GITHUB_TOKEN }}
221+
script: |
111222
await github.rest.issues.createComment({
112223
owner: context.repo.owner,
113224
repo: context.repo.repo,
114-
issue_number: context.issue.number,
115-
body: `🚀 Pre-commit workflow triggered! Check the [Actions tab](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/workflows/precommit-execute.yml) for progress.`
225+
issue_number: ${{ steps.check_author.outputs.pr_number }},
226+
body: ` Pre-commit workflow failed!\n\nPlease check the [workflow logs](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.`
116227
});

0 commit comments

Comments
 (0)