Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action compositions #16

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/actions/deploy-vercel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy Vercel
description: Deploy Vercel in two modes

inputs:
vercel-token:
description: 'Vercel token'
required: true
mode:
description: 'Deployment mode'
required: true
default: 'production'

runs:
using: 'composite'
steps:
- name: Install Vercel CLI
run: npm install --global vercel@canary
shell: bash

- name: PROD Vercel Deployment
if: ${{ inputs.mode == 'production' }}
run: |
vercel pull --yes --environment=production --token=${{ inputs.vercel-token }}
vercel build --prod --token=${{ inputs.vercel-token }}
vercel deploy --prebuilt --prod --token=${{ inputs.vercel-token }}
shell: bash

- name: PREVIEW Vercel Deployment
if: ${{ inputs.mode == 'preview' }}
run: |
vercel pull --yes --environment=preview --token=${{ inputs.vercel-token }}
vercel build --token=${{ inputs.vercel-token }}
DEPLOY_OUTPUT="$(vercel deploy --token=${{ inputs.vercel-token }})"
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep http | tail -n 1)
echo "DEPLOY_URL=$DEPLOY_URL" >> $GITHUB_ENV
shell: bash

- name: Comment with preview URL
if: ${{ inputs.mode == 'preview' }}
uses: actions/github-script@v7
with:
script: |
const { DEPLOY_URL } = process.env;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🔍 Preview URL: ${DEPLOY_URL}`
});
14 changes: 14 additions & 0 deletions .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Setup
description: Setup node project

runs:
using: 'composite'
steps:
- name: Configure node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npm ci
shell: bash
23 changes: 6 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ jobs:
uses: actions/checkout@v4

- name: Configure node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npm ci
uses: ./.github/actions/setup-project

- name: Build the app
run: npm run build
Expand All @@ -38,17 +33,11 @@ jobs:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1

- name: Install Vercel CLI
run: npm install --global vercel@canary

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy app to Vercel production env
uses: ./.github/actions/deploy-vercel
with:
mode: 'production'
vercel-token: ${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
23 changes: 6 additions & 17 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ jobs:
uses: actions/checkout@v4

- name: Configure node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npm ci
uses: ./.github/actions/setup-project

- name: Lint code
run: npm run lint
Expand All @@ -29,17 +24,11 @@ jobs:
- name: Build the app
run: npm run build

- name: Install Vercel CLI
run: npm install --global vercel@canary

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy app to Vercel preview env
uses: ./.github/actions/deploy-vercel
with:
mode: 'preview'
vercel-token: ${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}