Skip to content

Deploy wildcat-dashboard-ui (Cloudflare Pages) #9

Deploy wildcat-dashboard-ui (Cloudflare Pages)

Deploy wildcat-dashboard-ui (Cloudflare Pages) #9

Workflow file for this run

name: Deploy wildcat-dashboard-ui (Cloudflare Pages)
on:
push:
tags:
- 'v*'
branches:
- 'master'
workflow_dispatch:
inputs:
environment:
description: 'target'
required: true
default: 'production'
type: choice
options:
- dev
- staging
- production
jobs:
######################################################################
# ENV: dev
# CF project: wildcat-dashboard
######################################################################
deploy-dev:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
concurrency:
group: 'deploy-dev-${{ github.ref_name }}'
cancel-in-progress: true
# SET ENVIRONMENT
environment: dev
name: Deploy to dev (wildcat-dashboard)
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev'
##############################################################################
# keep section similar, dev has different validation step
env:
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
NODE_VERSION: ${{ vars.NODE_VERSION }}
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
steps:
- name: Checkout ${{ github.ref_name }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.ref }}
fetch-depth: 0
# for dev: only allow dev branch
- name: Validate correct branch on manual dispatch
run: |
if [[ "${{ github.ref_name }}" != 'dev' ]]; then
echo "::error::Manual deployments to the 'dev' environment must be triggered from the 'dev' branch."
echo "::error::Please select the 'dev' branch from the 'Use workflow from' dropdown."
exit 1
fi
echo "Validation successful: Running from 'dev' branch."
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build
##############################################################################
# Customize deployment triggers
# DEV: manual dispatch, branch dev
- name: Deploy ${{ github.ref_name }} to DEV of ${{ env.CLOUDFLARE_PROJECT }} project
id: deploy-dev-dispatch
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=dev --commit-message="MANUAL DISPATCH ${{ github.sha }}" --commit-hash=${{ github.sha }} --commit-dirty=true
######################################################################
# ENV: staging
# CF project: wildcat-dashboard-staging
######################################################################
deploy-staging:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
concurrency:
group: 'deploy-staging-${{ github.ref_name }}'
cancel-in-progress: true
# SET ENVIRONMENT
environment: staging
name: Deploy to staging (wildcat-dashboard-staging)
if: |
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
##############################################################################
# keep section similar
env:
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
NODE_VERSION: ${{ vars.NODE_VERSION }}
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
steps:
- name: Checkout ${{ github.ref_name }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Validate tag on manual dispatch
if: github.event_name == 'workflow_dispatch'
run: |
if [[ "${{ github.ref_type }}" != 'tag' ]]; then
echo "::error::Manual deployments must be triggered from a tag."
echo "::error::Please select a tag from the 'Use workflow from' dropdown, not a branch."
exit 1
fi
echo "Validation successful: Running from tag '${{ github.ref_name }}'."
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build
##############################################################################
# Customize deployment triggers
# STAGING PREVIEW: on push, branch master
- name: Deploy ${{ github.ref_name }} to STAGING PREVIEW of ${{ env.CLOUDFLARE_PROJECT }} project
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
id: deploy-staging-preview-push-master
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=preview --commit-message="PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
# STAGING PROD: on push, with tag
- name: Deploy ${{ github.ref_name }} to STAGING PROD of ${{ env.CLOUDFLARE_PROJECT }} project
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
id: deploy-staging-push-tag
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }} (TAG PUSH)" --commit-hash=${{ github.sha }} --commit-dirty=true
# STAGING PROD: on manual dispatch
- name: Deploy ${{ github.ref_name }} to STAGING PROD of ${{ env.CLOUDFLARE_PROJECT }} project
id: deploy-staging-dispatch
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging'
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }} (DISPATCH)" --commit-hash=${{ github.sha }} --commit-dirty=true
######################################################################
# ENV: production
# CF project: wildcat-dashboard-production
######################################################################
deploy-production:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
concurrency:
group: 'deploy-production-${{ github.ref_name }}'
cancel-in-progress: true
# SET ENVIRONMENT
environment: production
name: Deploy to production (wildcat-dashboard-production)
if: |
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
##############################################################################
# keep section similar
env:
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
NODE_VERSION: ${{ vars.NODE_VERSION }}
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
steps:
- name: Checkout ${{ github.ref_name }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Validate tag on manual dispatch
if: github.event_name == 'workflow_dispatch'
run: |
if [[ "${{ github.ref_type }}" != 'tag' ]]; then
echo "::error::Manual deployments must be triggered from a tag."
echo "::error::Please select a tag from the 'Use workflow from' dropdown, not a branch."
exit 1
fi
echo "Validation successful: Running from tag '${{ github.ref_name }}'."
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build
##############################################################################
# Customize deployment triggers
# PRODUCTION PREVIEW: on push, with tag
- name: Deploy ${{ github.ref_name }} to PRODUCTION PREVIEW of ${{ env.CLOUDFLARE_PROJECT }} project
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
id: deploy-production-preview-push-tag
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=preview --commit-message="PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
# PRODUCTION PROD: manual dispatch, with tag
- name: Deploy ${{ github.ref_name }} to PRODUCTION PROD of ${{ env.CLOUDFLARE_PROJECT }} project
id: deploy-production-dispatch
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production'
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true