|
| 1 | +name: Vercel |
| 2 | + |
| 3 | +env: |
| 4 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 5 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + - beta |
| 12 | + pull_request: |
| 13 | + |
| 14 | +jobs: |
| 15 | + vercel: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + environment: |
| 19 | + name: ${{ github.ref_name == 'master' && 'Production' || 'Preview' }} |
| 20 | + url: ${{ github.ref_name == 'master' && 'https://stacks-blockchain-api.vercel.app/' || 'https://stacks-blockchain-api-pbcblockstack-blockstack.vercel.app/' }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Use Node.js |
| 28 | + uses: actions/setup-node@v2 |
| 29 | + with: |
| 30 | + node-version-file: '.nvmrc' |
| 31 | + |
| 32 | + - name: Cache node modules |
| 33 | + uses: actions/cache@v2 |
| 34 | + env: |
| 35 | + cache-name: cache-node-modules |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.npm |
| 39 | + **/node_modules |
| 40 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 43 | + ${{ runner.os }}-build- |
| 44 | + ${{ runner.os }}- |
| 45 | +
|
| 46 | + - name: Install deps |
| 47 | + run: npm ci --audit=false |
| 48 | + |
| 49 | + - name: Install Vercel CLI |
| 50 | + run: npm install --global vercel@latest |
| 51 | + |
| 52 | + - name: Pull Vercel environment information |
| 53 | + run: vercel pull --yes --environment=${{ github.ref_name == 'master' && 'production' || 'preview' }} --token=${{ secrets.VERCEL_TOKEN }} |
| 54 | + |
| 55 | + - name: Build project artifacts |
| 56 | + run: vercel build ${{ github.ref_name == 'master' && '--prod' || '' }} --token=${{ secrets.VERCEL_TOKEN }} |
| 57 | + |
| 58 | + - name: Deploy project artifacts to Vercel |
| 59 | + id: deploy |
| 60 | + run: vercel ${{ github.ref_name == 'master' && '--prod' || 'deploy' }} --prebuilt --token=${{ secrets.VERCEL_TOKEN }} | awk '{print "deployment_url="$1}' >> $GITHUB_OUTPUT |
| 61 | + |
| 62 | + - name: Add comment with Vercel deployment URL |
| 63 | + if: ${{ github.event_name == 'pull_request' }} |
| 64 | + uses: thollander/actions-comment-pull-request@v2 |
| 65 | + with: |
| 66 | + comment_tag: vercel |
| 67 | + message: | |
| 68 | + Vercel deployment URL: ${{ steps.deploy.outputs.deployment_url }} :rocket: |
0 commit comments