diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7214c6f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + + - name: Build application + run: npm run build \ No newline at end of file diff --git a/.github/workflows/deploy-live.yml b/.github/workflows/deploy-live.yml new file mode 100644 index 0000000..589e766 --- /dev/null +++ b/.github/workflows/deploy-live.yml @@ -0,0 +1,28 @@ +name: Live Deployment + +on: + push: + branches: + - main + - staging + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + deploy-preproduction-preview: + uses: ./.github/workflows/deploy.yml + if: github.ref_name == 'staging' + with: + environment: preproduction + preview: false + secrets: inherit + deploy-production-preview: + uses: ./.github/workflows/deploy.yml + if: github.ref_name == 'main' + with: + environment: production + preview: false + secrets: inherit + diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 0000000..ed75eb0 --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,28 @@ +name: Preview Deployment + +on: + pull_request: + branches: + - main + - staging + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + deploy-preproduction-preview: + uses: ./.github/workflows/deploy.yml + if: github.base_ref == 'staging' + with: + environment: preproduction + preview: true + secrets: inherit + deploy-production-preview: + uses: ./.github/workflows/deploy.yml + if: github.base_ref == 'main' + with: + environment: production + preview: true + secrets: inherit + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e6fbe4e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,60 @@ +name: Deploy to Vercel +on: + workflow_call: + inputs: + environment: + required: true + type: string + preview: + required: false + type: boolean + default: true + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + - name: Install dependencies + run: npm install + - name: Run tests + run: npm test + deploy-preview: + runs-on: ubuntu-latest + needs: test + environment: ${{ inputs.environment }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up environment variables + run: | + echo "VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}" >> $GITHUB_ENV + echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}" >> $GITHUB_ENV + if [ ${{ inputs.preview }} = true ]; then + echo "VERCEL_ENVIRONMENT=preview" >> $GITHUB_ENV + echo "VERCEL_DEPLOYMENT_FLAG=" >> $GITHUB_ENV + else + echo "VERCEL_ENVIRONMENT=production" >> $GITHUB_ENV + echo "VERCEL_DEPLOYMENT_FLAG=--prod" >> $GITHUB_ENV + fi + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + - name: Install dependencies + run: npm install + - name: Install Vercel CLI + run: npm install -g vercel + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy to Vercel Preview + run: vercel $VERCEL_DEPLOYMENT_FLAG --token=${{ secrets.VERCEL_TOKEN }}