Skip to content

Commit

Permalink
test: use github api scripts to wait for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 2, 2024
1 parent 9733c49 commit 54bbcac
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
36 changes: 30 additions & 6 deletions .github/workflows/publish-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,37 @@ jobs:
wait-for-tests:
runs-on: ubuntu-latest
steps:
- name: Wait for unit tests to succeed
uses: lewagon/[email protected]
- uses: actions/github-script@v6
with:
ref: ${{ github.ref }}
check-name: 'run-unit-tests'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const ref = context.sha;
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!');
}
}
}
await new Promise(r => setTimeout(r, 10000));
}
docker:
needs: wait-for-tests
Expand Down
36 changes: 30 additions & 6 deletions .github/workflows/publish-swap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,37 @@ jobs:
wait-for-tests:
runs-on: ubuntu-latest
steps:
- name: Wait for unit tests to succeed
uses: lewagon/[email protected]
- uses: actions/github-script@v6
with:
ref: ${{ github.ref }}
check-name: 'run-unit-tests'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const ref = context.sha;
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!');
}
}
}
await new Promise(r => setTimeout(r, 10000));
}
docker:
needs: wait-for-tests
Expand Down

0 comments on commit 54bbcac

Please sign in to comment.