├── README.md ├── action.yml └── logo.png /README.md: -------------------------------------------------------------------------------- 1 | # Snaplet Preview Databases Github Action 2 | 3 |

4 | Snappy's paw makes a database appear by snapping their fingers with the title 'SNAP!' 5 |

6 | 7 | > Deploy Snaplet preview databases filled with production-accurate data in no time. 8 | 9 | With this action, you can finally enjoy fully isolated and stateful preview environments. Get a new preview database filled with production-accurate data anytime you need it and plug it into your Jamstack hosting platform of choice like [Vercel](#with-vercel). 10 | 11 | By default, the preview database will be populated with data from your latest Snaplet snapshot. 12 | 13 | Learn more about creating snapshots in our [docs](https://docs.snaplet.dev/). 14 | 15 | ## Usage 16 | 17 | Create a GitHub Action Workflow file in your repository following one of these examples. 18 | 19 | ### Standalone 20 | 21 | ```yaml 22 | # .github/workflows/preview.yml 23 | 24 | name: Preview Environment 25 | 26 | env: 27 | SNAPLET_ACCESS_TOKEN: ${{ secrets.SNAPLET_ACCESS_TOKEN }} 28 | SNAPLET_PROJECT_ID: 29 | 30 | on: 31 | pull_request: 32 | types: [opened, synchronize, closed] 33 | branches: 34 | - main 35 | 36 | jobs: 37 | deploy: 38 | if: ${{ github.event.action == 'opened' || github.event.action == 'synchronize' }} 39 | runs-on: ubuntu-latest 40 | steps: 41 | - id: snaplet 42 | uses: snaplet/action@v1 43 | - run: echo ${{ steps.snaplet.outputs.database-url }} 44 | delete: 45 | if: ${{ github.event.action == 'closed' }} 46 | runs-on: ubuntu-latest 47 | steps: 48 | - uses: snaplet/action@v1 49 | with: 50 | delete: true 51 | ``` 52 | 53 | ### With Vercel 54 | 55 | Using [snaplet/vercel-action](https://github.com/marketplace/actions/vercel-preview-deployments) 56 | 57 | ```yaml 58 | # .github/workflows/preview.yml 59 | 60 | name: Preview Environment 61 | 62 | env: 63 | SNAPLET_ACCESS_TOKEN: ${{ secrets.SNAPLET_ACCESS_TOKEN }} 64 | SNAPLET_PROJECT_ID: 65 | VERCEL_ACCESS_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }} 66 | VERCEL_PROJECT_ID: 67 | 68 | on: 69 | pull_request: 70 | types: [opened, synchronize, closed] 71 | branches: 72 | - main 73 | 74 | jobs: 75 | deploy: 76 | if: ${{ github.event.action == 'opened' || github.event.action == 'synchronize' }} 77 | runs-on: ubuntu-latest 78 | steps: 79 | - id: snaplet 80 | uses: snaplet/action@v1 81 | - uses: snaplet/vercel-action@v1 82 | with: 83 | env: | 84 | DATABASE_URL=${{ steps.snaplet.outputs.database-url }} 85 | delete: 86 | if: ${{ github.event.action == 'closed' }} 87 | runs-on: ubuntu-latest 88 | steps: 89 | - uses: snaplet/action@v1 90 | with: 91 | delete: true 92 | - uses: snaplet/vercel-action@v1 93 | with: 94 | delete: true 95 | ``` 96 | 97 | ## Documentation 98 | 99 | ### Environment variables 100 | 101 | - SNAPLET_ACCESS_TOKEN 102 | - SNAPLET_PROJECT_ID 103 | 104 | ### Inputs 105 | 106 | ```yaml 107 | database-create-command: 108 | description: Command used to generate the instant database 109 | required: false 110 | type: string 111 | default: snaplet preview-database create --git --latest 112 | database-delete-command: 113 | description: Command used to delete the instant database 114 | required: false 115 | type: string 116 | default: snaplet preview-database drop --git 117 | database-url-command: 118 | description: Command used to get the instant database url 119 | required: false 120 | type: string 121 | default: snaplet preview-database url --git 122 | delete: 123 | description: Delete the database 124 | required: false 125 | type: boolean 126 | default: false 127 | reset: 128 | description: Reset the database state on each commit 129 | required: false 130 | type: boolean 131 | default: false 132 | ``` 133 | 134 | ### Outputs 135 | 136 | ```yaml 137 | database-url: 138 | description: Instant database url 139 | ``` -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: Snaplet Preview Databases 2 | 3 | author: Snaplet 4 | 5 | description: Deploy Snaplet preview databases filled with production-accurate data in no time. 6 | 7 | inputs: 8 | database-create-command: 9 | description: Command used to generate the instant database 10 | required: false 11 | type: string 12 | default: snaplet preview-database create --git --latest 13 | database-delete-command: 14 | description: Command used to delete the instant database 15 | required: false 16 | type: string 17 | default: snaplet preview-database drop --git 18 | database-url-command: 19 | description: Command used to get the instant database url 20 | required: false 21 | type: string 22 | default: snaplet preview-database url --git 23 | delete: 24 | description: Delete the database 25 | required: false 26 | type: boolean 27 | default: false 28 | reset: 29 | description: Reset the database state on each commit 30 | required: false 31 | type: boolean 32 | default: false 33 | 34 | outputs: 35 | database-url: 36 | description: Instant database url 37 | value: ${{ steps.deploy.outputs.database-url }} 38 | 39 | runs: 40 | using: composite 41 | steps: 42 | - name: Setup 43 | shell: bash 44 | run: curl -sS "https://app.snaplet.dev/get-cli/" | bash &> "/dev/null" 45 | 46 | - if: ${{ inputs.delete == 'false' }} 47 | id: deploy 48 | name: Deploy 49 | shell: bash 50 | run: | 51 | if [ "${{ inputs.reset }}" == "true" ]; \ 52 | then ${{ inputs.database-delete-command }} && ${{ inputs.database-create-command }}; \ 53 | else ${{ inputs.database-url-command }} &> "/dev/null" || ${{ inputs.database-create-command }}; \ 54 | fi 55 | echo "database-url=$(${{ inputs.database-url-command }})" >> $GITHUB_OUTPUT 56 | 57 | - if: ${{ inputs.delete == 'true' }} 58 | name: Delete 59 | shell: bash 60 | run: ${{ inputs.database-delete-command }} 61 | 62 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snaplet/action/97af02d55e80e9bd845b2bcbcd74eb74189eae28/logo.png --------------------------------------------------------------------------------