feat: add target url from vercel prview and run the tests only if the… #6
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: "Shortest Tests" | ||
on: | ||
deployment_status | ||
jobs: | ||
shortest: | ||
# Only run when: | ||
# 1. It's a successful deployment | ||
# 2. It's from Vercel (vercel.app in URL) | ||
# 3. It's a preview deployment (not production) | ||
if: | | ||
github.event.deployment_status.state == 'success' && | ||
contains(github.event.deployment_status.target_url, 'vercel.app') && | ||
github.event.deployment.environment == 'Preview' | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Add timeout to ensure we don't wait forever | ||
timeout-minutes: 15 | ||
# Cancel any in-progress jobs if a new deployment comes in | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
- name: Install dependencies | ||
run: pnpm install | ||
- name: Get Vercel preview URL | ||
id: vercel_url | ||
run: | | ||
DEPLOY_URL="${{ github.event.deployment_status.target_url }}" | ||
# Verify the URL is accessible | ||
curl --retry 3 --retry-delay 1 -f "$DEPLOY_URL" || exit 1 | ||
echo "url=$DEPLOY_URL" >> $GITHUB_OUTPUT | ||
- name: Run Shortest tests | ||
env: | ||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
run: pnpm shortest --headless --target=${{ steps.vercel_url.outputs.url }} |