Skip to content

Instantly share code, notes, and snippets.

@techwizzdom
Last active October 4, 2024 22:56
Show Gist options
  • Save techwizzdom/87a286b8fad6bd5fb476de7df0e21549 to your computer and use it in GitHub Desktop.
Save techwizzdom/87a286b8fad6bd5fb476de7df0e21549 to your computer and use it in GitHub Desktop.
name: CI/CD
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
on:
push:
branches:
- staging
pull_request:
branches:
- staging
jobs:
build-and-test:
name: πŸ›  Build, lint, and run unit tests
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code and setup node
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: πŸ–οΈ Linting
run: npm run lint
- name: πŸ§ͺ Unit Tests
run: npm run test
deploy-preview-staging:
name: πŸ‘οΈ Deploy to Preview Staging
if: github.ref == 'refs/heads/staging' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Deploy to Vercel (Preview Staging)
run: |
url=$(vercel deploy --skip-domain --prebuilt --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects)
vercel alias --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects set "$url" preview-staging.thesecondbrain.io
e2e-tests-cypress-staging:
name: 🌲 Cypress e2e Tests Staging
if: github.ref == 'refs/heads/staging'
needs: deploy-preview-staging
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: πŸ” Run E2E tests
run: npm run cy:run:preview-staging
- name: Upload Cypress Videos
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-videos
path: cypress/videos
- name: Upload Cypress Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: cypress/screenshots
deploy-staging:
name: 🚧 Deploy to Staging
if: github.ref == 'refs/heads/staging'
needs: e2e-tests-cypress-staging
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Deploy Project Artifacts to Vercel
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects)"
vercel alias --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects set "$url" staging.thesecondbrain.io
merge-to-main:
name: πŸ”„ Merge to main
if: success()
runs-on: ubuntu-latest
needs: deploy-staging
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "GitHub Actions Lad"
git config user.email "<gh@email.io>"
- name: Merge Staging into Main
run: |
git fetch origin staging
git merge --ff-only FETCH_HEAD
git push origin main
- name: Push to Main
run: git push https://${{secrets.MERGE_TO_MAIN_PERSONAL_TOKEN}}@github.com/${{github.repository}} main
deploy-preview-production:
name: πŸ‘οΈ Deploy to Preview Production
needs: merge-to-main
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN_TSB }}
- name: Deploy Project Artifacts to Vercel
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects)"
vercel alias --token=${{ secrets.VERCEL_TOKEN_TSB }} --scope=drombas-projects set "$url" preview-prod.thesecondbrain.io
e2e-tests-cypress-production:
name: 🌲 Cypress e2e Tests Production
needs: deploy-preview-production
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: πŸ” Run E2E tests
run: npm run cy:run:preview-production
- name: Upload Cypress Videos
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-videos
path: cypress/videos
- name: Upload Cypress Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: cypress/screenshots
deploy-main:
name: πŸš€ Deploy to Production
needs: e2e-tests-cypress-production
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v3
- name: πŸ”§ Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: βš™οΈ Install and build
run: |
npm install
npm run build
- name: πŸš€ Deploy to Vercel Production
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN_TSB }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: "--prod"
@Streen9
Copy link

Streen9 commented Oct 2, 2024

hi @techwizzdom

I'm hoping can you help me with integration testing for the services, particularly focusing on ensuring that all services are properly tested before deployment.

Specifically, I need help with:

Setting up integration tests for services using [node, python].
Writing test cases that check the interactions between connected services.
Configuring GitHub Actions to automate running these tests before deployment.

it would be great if you could help me with this, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment