chore: mod test watcher #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: publish-api | |
on: | |
push: | |
paths: | |
- apps/api/** | |
- libs/** | |
- package.json | |
- bun.lockb | |
- .github/workflows/publish-api.yml | |
workflow_dispatch: | |
jobs: | |
wait-for-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const { owner, repo } = context.repo; | |
const ref = context.sha; | |
let attempts = 0; | |
const maxAttempts = 30; // 5 minutes max wait time | |
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 | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
bitsacco/api | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=sha | |
- name: Login to Docker Hub | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') | |
uses: docker/login-action@v2 | |
with: | |
username: okjodom | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and push api | |
uses: docker/build-push-action@v4 | |
with: | |
file: apps/api/Dockerfile | |
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Checkout repository content | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') | |
uses: actions/checkout@v4 | |
# This workflow requires the repository content to be locally available to read the README | |
- name: Update the Docker Hub description | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: okjodom | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
repository: bitsacco/api | |
readme-filepath: ./apps/api/README.md |