Run Tests #506
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: Run Tests | |
on: | |
workflow_dispatch: | |
inputs: | |
capgo_clone_url: | |
required: true | |
type: string | |
capgo_clone_branch: | |
required: true | |
type: string | |
cli_clone_url: | |
required: true | |
type: string | |
cli_clone_branch: | |
required: true | |
type: string | |
tests_to_run: | |
required: true | |
type: string | |
commit_sha: | |
required: true | |
type: string | |
repo_owner: | |
required: true | |
type: string | |
repo_name: | |
required: true | |
type: string | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
name: "Run tests" | |
steps: | |
- name: Get Github App Token | |
uses: tibdex/github-app-token@v1 | |
id: get_installation_token | |
with: | |
app_id: 392564 | |
private_key: ${{ secrets.PRIVATE_KEY }} | |
- name: Change Status (start) | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.get_installation_token.outputs.token }} | |
script: | | |
const job = await github.rest.actions.listJobsForWorkflowRun({ | |
repo: 'github-bot', | |
owner: 'Cap-go', | |
run_id: context.runId, | |
}); | |
const jobId = job.data.jobs[0].id | |
if (!jobId) { | |
throw new Error('No job id') | |
} | |
const jobUrl = 'https://github.com/Cap-go/github-bot/actions/runs/RUN_ID/job/RUN_NUMBER'.replace('RUN_ID', context.runId).replace('RUN_NUMBER', jobId) | |
core.exportVariable('JOB_URL', jobUrl) | |
const commentData = `\n<!--- ${JSON.stringify({ capgo_clone_url: '${{ inputs.capgo_clone_url }}', capgo_clone_branch: '${{ inputs.capgo_clone_branch }}', cli_clone_url: '${{ inputs.cli_clone_url }}', cli_clone_branch: '${{ inputs.cli_clone_branch }}', tests_to_run: '${{ inputs.tests_to_run }}', commit_sha: '${{ inputs.commit_sha }}', repo_owner: '${{ inputs.repo_owner }}', repo_name: '${{ inputs.repo_name }}'})} -->` | |
core.exportVariable('COMMENT_DATA', commentData) | |
github.rest.checks.create({ | |
owner: '${{ inputs.repo_owner }}', | |
repo: '${{ inputs.repo_name }}', | |
name: 'E2E tests', | |
status: 'in_progress', | |
head_sha: '${{ inputs.commit_sha }}', | |
details_url: jobUrl, | |
output: { | |
summary: `The detailed output is available [here](${jobUrl})${commentData}`, | |
title: 'Testing E2E', | |
}, | |
}) | |
- name: "Checkout Capgo" | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ inputs.capgo_clone_url }} | |
ref: ${{ inputs.capgo_clone_branch }} | |
path: capgo | |
- name: "Checkout CLI" | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ inputs.cli_clone_url }} | |
ref: ${{ inputs.cli_clone_branch }} | |
path: cli | |
- name: Install Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- uses: pnpm/action-setup@v2 | |
name: Install pnpm | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ env.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: cd ./capgo && pnpm install && cd ../cli && pnpm install && cd .. | |
- name: Install Supabase CLI | |
uses: supabase/setup-cli@v1 | |
with: | |
version: 1.68.6 | |
- name: Install Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: vx.x.x | |
- name: Cache playwright binaries | |
id: playwright-cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/Library/Caches/ms-playwright | |
~/.cache/ms-playwright | |
${{ github.workspace }}/capgo/node_modules/playwright | |
key: cache-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: cache-playwright- | |
- name: Install Playwright | |
shell: bash | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
working-directory: ./capgo | |
run: pnpm exec playwright install --with-deps chromium | |
- name: Run Supabase Start | |
working-directory: ./capgo | |
run: ENV=local supabase start -x studio,imgproxy,inbucket,logflare --ignore-health-check | |
- name: Build CLI | |
working-directory: ./cli | |
run: pnpm run dev | |
- name: Start redis | |
working-directory: ./capgo | |
run: sh ./tests_backend/gh_actions/docker.sh | |
- name: Start minio | |
working-directory: ./capgo | |
run: sh ./tests_backend/gh_actions/minio.sh | |
- name: Set env variables | |
shell: bash | |
run: | | |
echo MINIO_URL=$(docker inspect minio1 | grep 'Gateway' | head -n 1 | sed -e 's/ "Gateway": "//g' | sed -e 's/",//g') >> $GITHUB_ENV | |
echo "CLI_PATH=$(realpath ./cli)" >> $GITHUB_ENV | |
- name: Run CLI Tests | |
working-directory: ./capgo | |
run: deno run --allow-all tests_backend/run_backend_tests.ts ${{ inputs.tests_to_run }} | |
env: | |
USE_LOCAL_REDIS: true | |
UPSTASH_TOKEN: ${{ secrets.UPSTASH_TEST_TOKEN }} | |
UPSTASH_URL: ${{ secrets.UPSTASH_TEST_URL }} | |
- name: Change Status (failed) | |
if: failure() | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.get_installation_token.outputs.token }} | |
script: | | |
const { JOB_URL, COMMENT_DATA } = process.env | |
github.rest.checks.create({ | |
owner: '${{ inputs.repo_owner }}', | |
repo: '${{ inputs.repo_name }}', | |
name: 'E2E tests', | |
status: 'completed', | |
conclusion: 'failure', | |
head_sha: '${{ inputs.commit_sha }}', | |
details_url: JOB_URL, | |
output: { | |
summary: `The detailed output is available [here](${JOB_URL})${COMMENT_DATA}`, | |
title: 'E2E tests failed', | |
}, | |
}) | |
- name: Change Stats (success) | |
if: success() | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.get_installation_token.outputs.token }} | |
script: | | |
const { JOB_URL, COMMENT_DATA } = process.env | |
github.rest.checks.create({ | |
owner: '${{ inputs.repo_owner }}', | |
repo: '${{ inputs.repo_name }}', | |
name: 'E2E tests', | |
status: 'completed', | |
conclusion: 'success', | |
head_sha: '${{ inputs.commit_sha }}', | |
details_url: JOB_URL, | |
output: { | |
summary: `The detailed output is available [here](${JOB_URL})${COMMENT_DATA} `, | |
title: 'E2E tests succeeded', | |
}, | |
}) | |
- uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: playwright-report | |
path: capgo/test-results/ | |
if-no-files-found: warn | |
retention-days: 30 |