Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions .github/workflows/opencode-test-writer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
id: select-module
env:
INPUT_MODULE: ${{ inputs.module }}
run: |

Check failure on line 29 in .github/workflows/opencode-test-writer.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2129:style:49:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects [shellcheck] Raw Output: e:.github/workflows/opencode-test-writer.yml:29:9: shellcheck reported issue in this script: SC2129:style:49:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects [shellcheck]
GRAPHICS_MODULES=(
"graphics/vulkan-device"
"graphics/vulkan-resources"
Expand Down Expand Up @@ -77,6 +77,7 @@
BRANCH_NAME="test/$(echo "${SELECTED}" | tr '/' '-')"
echo "module=${SELECTED}" >> "$GITHUB_OUTPUT"
echo "branch=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
echo "base_branch=${{ github.event.repository.default_branch }}" >> "$GITHUB_OUTPUT"

case "$SELECTED" in
graphics/vulkan-device)
Expand Down Expand Up @@ -135,7 +136,7 @@
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
ref: ${{ steps.select-module.outputs.base_branch }}
fetch-depth: 0
token: ${{ secrets.OPENCODE_PAT }}

Expand All @@ -154,7 +155,7 @@
run: |
MODULE="${{ steps.select-module.outputs.module }}"
EXISTING=$(gh pr list \
--base ${{ github.event.repository.default_branch }} \
--base ${{ steps.select-module.outputs.base_branch }} \
--label "automated-test" \
--state open \
--limit 20 \
Expand Down Expand Up @@ -226,20 +227,47 @@
5. Commit your changes: `git add` and `git commit` with message `test: add {area} tests for ${{ steps.select-module.outputs.module }}`
6. STOP. Do not push or create a PR.

- name: Trigger downstream workflows
- name: Find and label created PR
if: steps.check-existing.outputs.skip != 'true'
id: find-pr
run: |
sleep 5
BRANCH="${{ steps.select-module.outputs.branch }}"
PR_NUM=$(gh pr list --base dev --head "$BRANCH" --label automated-test --state open --json number --jq '.[0].number')
BASE="${{ steps.select-module.outputs.base_branch }}"
MAX_RETRIES=8
PAT_USER=$(gh api user --jq '.login')
PR_NUM=""
for i in $(seq 1 "$MAX_RETRIES"); do
sleep $((i * 3))
echo "Attempt $i/$MAX_RETRIES: searching for PR by ${PAT_USER} targeting ${BASE}..."
PR_NUM=$(gh pr list \
--base "$BASE" \
--state open \
--limit 10 \
--json number,createdAt,author \
--jq "[.[] | select(.author.login == \"${PAT_USER}\")] | sort_by(.createdAt) | reverse | .[0].number")
if [ -n "$PR_NUM" ]; then
break
fi
done
if [ -n "$PR_NUM" ]; then
echo "Triggering Build and opencode review for PR #$PR_NUM"
SHA=$(gh api repos/OpenStaticFish/ZigCraft/pulls/$PR_NUM --jq '.head.sha')
BRANCH=$(gh api repos/OpenStaticFish/ZigCraft/pulls/$PR_NUM --jq '.head.ref')
gh workflow run build.yml --field ref="$BRANCH" || echo "Build trigger attempted"
gh workflow run opencode-pr.yml --field pr_number="$PR_NUM" --field head_sha="$SHA"
echo "Found newly created PR #$PR_NUM (author: ${PAT_USER})"
if ! gh pr edit "$PR_NUM" --add-label "automated-test" 2>/dev/null; then
echo "::warning::Failed to add automated-test label to PR #$PR_NUM"
fi
echo "pr_number=${PR_NUM}" >> "$GITHUB_OUTPUT"
else
echo "No PR found to trigger workflows"
echo "No PR found authored by ${PAT_USER} after $MAX_RETRIES attempts"
fi
env:
GH_TOKEN: ${{ secrets.OPENCODE_PAT }}

- name: Trigger downstream workflows
if: steps.find-pr.outputs.pr_number != ''
run: |
PR_NUM="${{ steps.find-pr.outputs.pr_number }}"
echo "Triggering Build and opencode review for PR #$PR_NUM"
SHA=$(gh api repos/OpenStaticFish/ZigCraft/pulls/$PR_NUM --jq '.head.sha')
BRANCH=$(gh api repos/OpenStaticFish/ZigCraft/pulls/$PR_NUM --jq '.head.ref')
gh workflow run build.yml --field ref="$BRANCH" || echo "Build trigger attempted"
gh workflow run opencode-pr.yml --field pr_number="$PR_NUM" --field head_sha="$SHA"
env:
GH_TOKEN: ${{ secrets.OPENCODE_PAT }}
Loading