diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dfdd3c7..603bb5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,20 +1,13 @@ -name: Deploy main branch +name: Deploy Prod on: push: branches: - main - pull_request: - branches: - - main - pull_request_target: - types: - - closed jobs: deploy: - name: deploy - if: github.event_name != 'pull_request_target' || github.event.pull_request.merged != true + name: deploy-prod runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -22,10 +15,9 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20.x - - name: Install Serverless Framework - run: npm install serverless --global + cache: "npm" - name: Install Dependencies - run: npm install + run: npm ci - name: Update domain settings uses: mikefarah/yq@master with: @@ -35,35 +27,7 @@ jobs: - name: Serverless Deploy uses: serverless/github-action@v4 with: - args: deploy --stage ${{ github.event.pull_request.number && 'pr-${{ github.event.pull_request.number }}' || 'prod' }} - env: - SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - remove: - name: remove - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: 20.x - - name: Install Serverless Framework - run: npm install serverless --global - - uses: bahmutov/npm-install@v1 - with: - working-directory: | - ai-chat-api - auth - business-api - business-worker - website - - name: serverless remove - uses: serverless/github-action@v4 - with: - args: remove --stage pr-${{ github.event.pull_request.number }} + args: deploy --stage prod env: SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml new file mode 100644 index 0000000..d7b1756 --- /dev/null +++ b/.github/workflows/pr-deploy.yml @@ -0,0 +1,28 @@ +name: Deploy PR Preview + +on: + pull_request: + branches: + - main + +jobs: + remove: + name: deploy-pr-preview + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: "npm" + - name: Install dependencies + run: npm ci + - name: serverless deploy + uses: serverless/github-action@v4 + with: + args: deploy --stage pr-${{ github.event.pull_request.number }} + env: + SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/pr-remove.yml b/.github/workflows/pr-remove.yml new file mode 100644 index 0000000..d93890b --- /dev/null +++ b/.github/workflows/pr-remove.yml @@ -0,0 +1,28 @@ +name: Remove PR Preview + +on: + pull_request_target: + types: + - closed + +jobs: + remove: + name: remove-pr-preview + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: "npm" + - name: Install dependencies + run: npm ci + - name: serverless remove + uses: serverless/github-action@v4 + with: + args: remove --stage pr-${{ github.event.pull_request.number }} + env: + SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}