> For the complete documentation index, see [llms.txt](https://serverlessguru.gitbook.io/sls-jest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://serverlessguru.gitbook.io/sls-jest/cookbooks/github-actions.md).

# Github Actions

## Deploy feauture ephemeral stacks

You can use Github Actions to run your tests against an ephemeral stack each time you open a new Pull Request and push new code to it.

```yaml
name: Deploy and run tests

on:
  pull_request:
    branches:
      - main

# avoid running several deployments in parallel
concurrency: ${{ github.ref }}

# Grant GA the required permissions to assume the IAM role
permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: '16.x'

      - name: Install dependencies
        run: npm ci

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-deployer # the role to assume
          role-duration-seconds: 3600

      # Deploy to a unique stack for each Pull Request
      - name: Deploy
        run: sls deploy --stage ci${{ github.event.pull_request.number }} # or cdk deploy --all or a deploy command that makes sense for your stack

      # run tests
      - name: Integration tests
        env:
          # specify a unique SLS_JEST_TAG for this PR
          SLS_JEST_TAG: ci${{ github.event.pull_request.number }}
        run: npx jest --runInBand
```

## Teardown the ephemeral stack on merge

When you are happy with your PR, you can teardown your stack and cleanup `sls-jest` artifacts after you merge it.

```yaml
name: Teardown stack

on:
  pull_request:
    types: [closed]
    branches:
      - main

# Grant GA the required permissions to assume the IAM role
permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: '16.x'

      - name: Install dependencies
        run: npm ci

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-deployer # the role to assume
          role-duration-seconds: 3600

      - name: Cleanup sls-jest artifacts
        run: npx sls-jest destroy --tag ci${{ github.event.pull_request.number }}

      - name: Destroy stack
        run: sls remove --stage ci${{ github.event.pull_request.number }} # or cdk destroy --all --force or a remove/destroy command that makes sense for your stack
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://serverlessguru.gitbook.io/sls-jest/cookbooks/github-actions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
