Skip to content

Commit

Permalink
chore: mod test watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 2, 2024
1 parent 54bbcac commit ffba0f0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
61 changes: 43 additions & 18 deletions .github/workflows/publish-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,57 @@ jobs:
script: |
const { owner, repo } = context.repo;
const ref = context.sha;
let attempts = 0;
const maxAttempts = 30; // 5 minutes max wait time
while (true) {
const { data: checks } = await github.rest.checks.listForRef({
owner,
repo,
ref,
check_name: 'run-unit-tests'
});
if (checks.check_runs.length > 0) {
const status = checks.check_runs[0].status;
const conclusion = checks.check_runs[0].conclusion;
if (status === 'completed') {
if (conclusion === 'success') {
console.log('Tests passed!');
break;
} else {
throw new Error('Tests failed!');
console.log(`Owner: ${owner}, Repo: ${repo}`);
while (attempts < maxAttempts) {
attempts++;
console.log(`Attempt ${attempts}: Checking test status...`);
try {
// First, list all check runs without filtering by name
const { data: allChecks } = await github.rest.checks.listForRef({
owner,
repo,
ref
});
console.log(`Found ${allChecks.check_runs.length} total check runs.`);
console.log(`Check run names: ${allChecks.check_runs.map(run => run.name).join(', ')}`);
// Then, filter for the specific check run
const testRun = allChecks.check_runs.find(run => run.name === 'run-unit-tests');
if (testRun) {
console.log(`Found 'run-unit-tests' check. Status: ${testRun.status}, conclusion: ${testRun.conclusion}`);
if (testRun.status === 'completed') {
if (testRun.conclusion === 'success') {
console.log('Tests passed!');
process.exit(0);
} else {
throw new Error(`Tests failed with conclusion: ${testRun.conclusion}`);
}
}
} else {
console.log("'run-unit-tests' check not found yet. Waiting...");
}
} catch (error) {
console.error(`Error occurred: ${error.message}`);
if (attempts >= maxAttempts) {
throw error;
}
}
console.log('Waiting 10 seconds before next attempt...');
await new Promise(r => setTimeout(r, 10000));
}
throw new Error('Timeout: Max attempts reached without finding completed tests.');
docker:
needs: wait-for-tests
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup Bun
- name: setup-bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
- name: install-dependencies
run: bun install

- name: Run tests
- name: run-unit-tests
run: bun test

0 comments on commit ffba0f0

Please sign in to comment.