|
| 1 | +name: Deploy AWS Lambda with Serverless |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Set up Node.js |
| 17 | + uses: actions/setup-node@v3 |
| 18 | + with: |
| 19 | + node-version: 18 |
| 20 | + |
| 21 | + - name: Install npm dependencies |
| 22 | + run: npm install |
| 23 | + |
| 24 | + - name: Configure AWS Credentials |
| 25 | + uses: aws-actions/configure-aws-credentials@v2 |
| 26 | + with: |
| 27 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 28 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 29 | + aws-region: ${{ secrets.AWS_REGION }} |
| 30 | + |
| 31 | + - name: Compile TypeScript |
| 32 | + run: npm run build |
| 33 | + |
| 34 | + - name: Run ESLint to check code quality |
| 35 | + run: npm run lint |
| 36 | + |
| 37 | + |
| 38 | + - name: Run Jest tests |
| 39 | + run: npm test |
| 40 | + |
| 41 | + - name: Install only production dependencies |
| 42 | + run: npm ci --only=production |
| 43 | + |
| 44 | + - name: Install Serverless Framework |
| 45 | + run: | |
| 46 | + npm install -g serverless@3.40.0 |
| 47 | + serverless --version # Debugging: Check installed version |
| 48 | + |
| 49 | + - name: Installing the prune Plugin |
| 50 | + run: npm install serverless-prune-plugin |
| 51 | + |
| 52 | + - name: Create .env file |
| 53 | + run: | |
| 54 | + echo "MONGO_URI=${{ secrets.MONGO_URI }}" >> .env |
| 55 | + echo "SERVERLESS_ACCESS_KEY=${{ secrets.SERVERLESS_ACCESS_KEY }}" >> .env |
| 56 | + echo "MONGO_URI is set to $MONGO_URI" # Debugging: Print the MONGO_URI value |
| 57 | + cat .env # Show file contents |
| 58 | + |
| 59 | + - name: Deploy with Serverless |
| 60 | + env: |
| 61 | + MONGO_URI: ${{ secrets.MONGO_URI }} |
| 62 | + SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} |
| 63 | + run: serverless deploy --verbose |
0 commit comments