Playwright #5
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: CICD | |
on: | |
push: | |
branches: [main] | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
AZURE_RESOURCE_GROUP: "gh-personal-portfolio" | |
AZURE_STORAGE_ACCOUNT: "ghpersonalportfolio" | |
LOCATION: "West Europe" | |
jobs: | |
setup-azure-resource: | |
name: Setup Azure Resource | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Create Resource Group | |
run: | | |
az group create \ | |
--name ${{ env.AZURE_RESOURCE_GROUP }} \ | |
--location "${{ env.LOCATION }}" | |
- name: Create Azure Storage Account | |
run: | | |
az storage account create \ | |
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \ | |
--name ${{ env.AZURE_STORAGE_ACCOUNT }} \ | |
--sku Standard_LRS | |
- name: Grant Blob Data Contributor permissions to the Service Principal | |
run: | | |
az role assignment create \ | |
--assignee ${{ secrets.AZURE_CLIENT_ID }} \ | |
--role "Storage Blob Data Contributor" \ | |
--scope /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.AZURE_RESOURCE_GROUP }}/providers/Microsoft.Storage/storageAccounts/${{ env.AZURE_STORAGE_ACCOUNT }} | |
- name: Create Azure Storage Container for the current commit | |
run: | | |
az storage container create \ | |
--account-name ${{ env.AZURE_STORAGE_ACCOUNT }} \ | |
--name ${{ github.sha }} \ | |
--public-access blob \ | |
--auth-mode login | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Build application | |
run: npm run build | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nextjs-artifacts | |
path: .next/ | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run linter | |
run: npm run lint | |
unit-tests: | |
name: Unit Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Run tests | |
run: npm run test:ci | |
e2e-tests: | |
name: E2E Tests | |
needs: [setup-azure-resource, build] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: nextjs-artifacts | |
path: .next/ | |
- name: Install dependencies | |
run: npm install | |
- name: Install Browsers | |
run: npx playwright install --with-deps | |
- name: Run E2E tests | |
id: e2e_tests | |
run: | | |
echo "status=failed" >> $GITHUB_OUTPUT | |
xvfb-run npm run test:e2e | |
echo "status=success" >> $GITHUB_OUTPUT | |
continue-on-error: true | |
- name: Log in to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Upload current commit E2E tests reports | |
run: | | |
az storage blob upload-batch \ | |
--account-name ${{ env.AZURE_STORAGE_ACCOUNT }} \ | |
--destination ${{ github.sha }} \ | |
--destination-path playwright-report \ | |
--source ./playwright-report \ | |
--overwrite \ | |
--auth-mode login | |
- name: Generate Job summary with E2E reports link | |
run: | | |
cat <<- EOM >> $GITHUB_STEP_SUMMARY | |
[View E2E Tests report](https://${{ env.AZURE_STORAGE_ACCOUNT }}.blob.core.windows.net/${{ github.sha }}/playwright-report/index.html) | |
EOM | |
- name: Check E2E test result | |
run: | | |
if [ "${{ steps.e2e_tests.outputs.status }}" == "failed" ]; then | |
exit 1 | |
fi | |
deploy: | |
name: Deploy | |
needs: [build, lint, unit-tests, e2e-tests] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: nextjs-artifacts | |
path: .next/ | |
- name: Deploy build artifacts to Vercel | |
env: | |
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
run: npx vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }} |