diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..01e80df --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,57 @@ +# .github/workflows/ci-cd.yml +name: CI/CD + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + deploy: + needs: build-and-test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' # Deploy only from the main branch + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Sync files to S3 + uses: aws-actions/s3-sync@v2 + with: + source-dir: src + destination-bucket: ${{ secrets.AWS_S3_BUCKET_NAME }} + delete: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 0cb6f39..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,38 +0,0 @@ -# .github/workflows/ci.yml -name: CI - -on: - push: - branches: - - main - - master - - develop - pull_request: - branches: - - main - - master - - develop - -jobs: - build-and-test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - - name: Install dependencies - run: npm ci - - - name: Run tests - run: npm test