Skip to content

feat(gha): add playwright tests & GHA workflow #54

feat(gha): add playwright tests & GHA workflow

feat(gha): add playwright tests & GHA workflow #54

Workflow file for this run

name: Deploy PR
on:
issue_comment:
types:
- created
- edited
pull_request:
types:
- opened
- synchronize
defaults:
run:
shell: bash -exuo pipefail {0}
concurrency:
group: deployment
cancel-in-progress: false
jobs:
get-ref:
name: Get ref
runs-on: ubuntu-22.04
outputs:
ref: ${{ steps.get-ref-from-pr.outputs.ref || steps.get-ref-from-issue.outputs.ref }}
sha: ${{ steps.get-ref-from-pr.outputs.sha || steps.get-ref-from-issue.outputs.sha }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- id: get-ref-from-pr
name: Get ref from PR
if: github.event_name == 'pull_request'
run: |
echo "ref=${{ github.event.pull_request.head.ref }}" >> "$GITHUB_OUTPUT"
echo "sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
- id: get-ref-from-issue
name: Get ref from issue
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.comment.body == '/deploy'
run: |
echo "ref=$(gh pr view ${{ github.event.issue.number }} --json headRefName | jq -r .headRefName)" >> "$GITHUB_OUTPUT"
echo "sha=$(gh pr view ${{ github.event.issue.number }} --json headRefOid | jq -r .headRefOid)" >> "$GITHUB_OUTPUT"
deploy:
name: Deploy
needs: get-ref
uses: arikkfir/delivery/.github/workflows/deploy-to-environment.yml@main
if: needs.get-ref.outputs.ref && needs.get-ref.outputs.sha
with:
branch: ${{ needs.get-ref.outputs.ref }}
images: |-
ghcr.io/${{ github.repository }}/backend: ${{ needs.get-ref.outputs.sha }}
ghcr.io/${{ github.repository }}/frontend: ${{ needs.get-ref.outputs.sha }}
ghcr.io/${{ github.repository }}/migrations: ${{ needs.get-ref.outputs.sha }}
ghcr.io/${{ github.repository }}/neo4j: ${{ needs.get-ref.outputs.sha }}
secrets: inherit
e2e-tests:
name: End-to-end Tests
needs: [ get-ref, deploy ]
runs-on: ubuntu-22.04
permissions:
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: arikkfir/delivery-env-name@v1
id: env
with:
branch: ${{ needs.get-ref.outputs.ref }}
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: npm
cache-dependency-path: e2e/package-lock.json
- uses: google-github-actions/auth@v1
with:
workload_identity_provider: projects/8909046976/locations/global/workloadIdentityPools/github-actions/providers/github-oidc
service_account: playwright-uploader@arikkfir.iam.gserviceaccount.com
- uses: google-github-actions/setup-gcloud@v1
with:
version: 443.0.0
- run: |
npm ci
npx playwright install --with-deps
working-directory: e2e
- id: test
run: npx playwright test
continue-on-error: true
working-directory: e2e
- run: |
UPLOAD_URL="gs://${BUCKET_NAME}/${BUCKET_PATH}/"
WEB_URL="https://playwright.kfirs.com/${BUCKET_PATH}/html/index.html"
gcloud storage cp -r -P ./playwright-report/* "${UPLOAD_URL}"
touch comment.txt
echo "End to end tests *"${{ steps.test.outcome == 'success' && 'succeeded' || 'failed' }}"*." >> comment.txt
echo "[Click here for a full report](${WEB_URL})." >> comment.txt
echo "---" >> comment.txt
cat custom-summary.txt >> comment.txt
gh pr comment ${PR} --body comment.txt --edit-last
if [[ "${FAILURE}" == "true" ]]; then
exit 1
fi
env:
BUCKET_NAME: arikkfir-playwright-reports
BUCKET_PATH: ${{ github.repository }}/actions/${{ github.run_number }}/${{ github.run_attempt }}/
ENV_NAME: ${{ steps.env.outputs.name }}
PR: ${{ github.event.pull_request.number || github.event.issue.number }}
FAILURE: ${{ steps.test.outcome == 'failure' }}
working-directory: e2e