Skip to content

Commit

Permalink
[.github] - refacto: workflow deploy front qa (#8720)
Browse files Browse the repository at this point in the history
* [.github/workflows] - refactor: streamline QA deployment and testing workflow

 - Removed the previous QA deployment and testing workflow
 - Introduced a new workflow that triggers a component deploy process in a different repository using a dispatch event

* [.github] - feature: add automated playwright tests workflow for dispatched events

 - Introduce a GitHub Actions workflow that triggers Playwright tests via a webhook upon repository dispatch
 - Implement a step to wait for the triggered tests to complete and exit based on their conclusion
 - Add a step to send a Slack notification if the Playwright tests fail

* Update .github/workflows/deploy-front-qa.yml

Co-authored-by: Flavien David <[email protected]>

---------

Co-authored-by: Flavien David <[email protected]>
  • Loading branch information
JulesBelveze and flvndvd authored Nov 27, 2024
1 parent 477cc17 commit 87d9e69
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 68 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/deploy-front-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Deploy Front QA

on:
pull_request:
types: [closed]
branches:
- main
paths-ignore:
- "**.md"
workflow_dispatch:

concurrency:
group: deploy_front_qa
cancel-in-progress: false

env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}

jobs:
build-and-deploy:
runs-on: ubuntu-latest
# We skip running the build and deploy if the PR contains a migration represented by the 'migration-ack' label.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'migration-ack') }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: "Authenticate with Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCLOUD_SA_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"

- name: Build the image on Cloud Build
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh \
--image-name=front-qa \
--dockerfile-path=./front/Dockerfile \
--working-dir=./ \
--dust-client-facing-url=https://front-qa.dust.tt
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.INFRA_DISPATCH_APP_ID }}
private-key: ${{ secrets.INFRA_DISPATCH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
dust-infra
- name: Trigger dust-infra workflow
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
await github.rest.repos.createDispatchEvent({
owner: '${{ github.repository_owner }}',
repo: 'dust-infra',
event_type: 'trigger-component-deploy',
client_payload: {
regions: 'us-central1',
component: 'front-qa',
image_tag: '${{ steps.short_sha.outputs.short_sha }}',
run_playwright: true,
playwright_sha: '${{ github.sha }}',
repository_name: '${{ github.event.repository.name }}'
}
});
Original file line number Diff line number Diff line change
@@ -1,80 +1,19 @@
name: Deploy And test Front Qa
name: Run Playwright Tests

on:
pull_request:
types: [closed]
branches:
- main
paths-ignore:
- "**.md"
workflow_dispatch:

concurrency:
group: deploy_front_qa
cancel-in-progress: false

env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
IMAGE_NAME: front-qa
repository_dispatch:
types: [run-playwright-tests]

jobs:
build-and-deploy:
runs-on: ubuntu-latest

# We skip running the build and deploy if the PR contains a migration represented by the 'migration-ack' label.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'migration-ack') }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: "Authenticate with Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCLOUD_SA_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"

- name: Install gke-gcloud-auth-plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Setup kubectl
run: |
gcloud container clusters get-credentials dust-kube --region us-central1
- name: Build the image on Cloud Build
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh --image-name=$IMAGE_NAME --dockerfile-path=./front/Dockerfile --working-dir=./ --dust-client-facing-url=https://front-qa.dust.tt
- name: Deploy the image on Kubernetes
run: |
chmod +x ./k8s/deploy-image.sh
./k8s/deploy-image.sh gcr.io/$GCLOUD_PROJECT_ID/$IMAGE_NAME-image:${{ steps.short_sha.outputs.short_sha }} front-qa-deployment
- name: Wait for rollout to complete
run: kubectl rollout status deployment/front-qa-deployment --timeout=10m

run-playwright-tests:
needs: build-and-deploy

runs-on: ubuntu-latest

# We skip running the build and deploy if the PR contains a migration represented by the 'migration-ack' label.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'migration-ack') }}

steps:
- name: Run Playwright Tests
id: trigger-tests
env:
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
REPO_NAME: ${{ github.event.client_payload.repository_name }}
run: |
response=$(curl -s -w "\n%{http_code}" -X POST "https://webhook.ranger.net/api/v1/tests/run" \
-H "Content-Type: application/json" \
Expand All @@ -83,7 +22,7 @@ jobs:
"targetUrl": "https://front-qa.dust.tt/",
"ghOwner": "'$REPO_OWNER'",
"ghRepo": "'$REPO_NAME'",
"ghCommitSha": "${{ github.sha }}"
"ghCommitSha": "${{ github.event.client_payload.sha }}"
}')
echo "$response"
http_code=$(echo "$response" | tail -n1)
Expand Down Expand Up @@ -139,13 +78,13 @@ jobs:
with:
payload: |
{
"text": "⚠️ Playwright tests failed! Commit: ${{ github.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"text": "⚠️ Playwright tests failed! Commit: ${{ github.event.client_payload.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "⚠️ Playwright tests failed! Commit: ${{ github.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"text": "⚠️ Playwright tests failed! Commit: ${{ github.event.client_payload.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"emoji": true
},
"accessory": {
Expand Down

0 comments on commit 87d9e69

Please sign in to comment.