Skip to content

Merge pull request #157 from Nanle-code/dependabot/npm_and_yarn/dev-d… #10

Merge pull request #157 from Nanle-code/dependabot/npm_and_yarn/dev-d…

Merge pull request #157 from Nanle-code/dependabot/npm_and_yarn/dev-d… #10

Workflow file for this run

name: Deploy
on:
push:
branches: [master, main]
workflow_dispatch:
inputs:
environment:
description: Target environment
required: true
default: staging
type: choice
options: [staging, production]
concurrency:
group: deploy-${{ github.ref }}-${{ github.event.inputs.environment || 'auto' }}
cancel-in-progress: false
env:
NODE_VERSION: '20'
jobs:
pre-deploy-checks:
name: Pre-deployment Checks
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.meta.outputs.sha }}
version: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- run: npm ci
- name: Run tests
run: npm test
- name: Capture build metadata
id: meta
run: |
echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: pre-deploy-checks
environment:
name: staging
url: ${{ steps.deploy.outputs.url }}
if: |
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'))
|| (github.event_name == 'workflow_dispatch' && inputs.environment == 'staging')
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- run: npm ci
- name: Build for staging
run: npm run build
env:
VITE_NETWORK: testnet
VITE_APP_ENV: staging
VITE_BUILD_SHA: ${{ needs.pre-deploy-checks.outputs.sha }}
VITE_BUILD_VERSION: ${{ needs.pre-deploy-checks.outputs.version }}
- name: Upload staging build
uses: actions/upload-artifact@v7
with:
name: staging-dist-${{ needs.pre-deploy-checks.outputs.sha }}
path: dist/
retention-days: 14
- name: Deploy to staging
id: deploy
run: |
echo "Deploying staging build ${{ needs.pre-deploy-checks.outputs.sha }}"
echo "url=https://staging.stellar-dev-dashboard.example.com" >> "$GITHUB_OUTPUT"
# Replace with actual deploy command, e.g.:
# rsync -avz dist/ user@staging-host:/var/www/html/
# aws s3 sync dist/ s3://staging-bucket --delete
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: pre-deploy-checks
environment:
name: production
url: ${{ steps.deploy.outputs.url }}
if: github.event_name == 'workflow_dispatch' && inputs.environment == 'production'
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- run: npm ci
- name: Build for production
run: npm run build
env:
VITE_NETWORK: mainnet
VITE_APP_ENV: production
VITE_BUILD_SHA: ${{ needs.pre-deploy-checks.outputs.sha }}
VITE_BUILD_VERSION: ${{ needs.pre-deploy-checks.outputs.version }}
- name: Upload production build
uses: actions/upload-artifact@v7
with:
name: production-dist-${{ needs.pre-deploy-checks.outputs.sha }}
path: dist/
retention-days: 30
- name: Deploy to production
id: deploy
run: |
echo "Deploying production build ${{ needs.pre-deploy-checks.outputs.sha }}"
echo "url=https://stellar-dev-dashboard.example.com" >> "$GITHUB_OUTPUT"
# Replace with actual production deploy command
- name: Create release tag
if: success()
run: |
TAG="v${{ needs.pre-deploy-checks.outputs.version }}-${{ needs.pre-deploy-checks.outputs.sha }}"
echo "Production deployed: $TAG"
docker-build:
name: Build & Push Docker Image
runs-on: ubuntu-latest
needs: pre-deploy-checks
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=sha-
type=ref,event=branch
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
rollback-on-failure:
name: Rollback Notification
runs-on: ubuntu-latest
needs: [deploy-production]
if: failure() && github.event_name == 'workflow_dispatch' && inputs.environment == 'production'
steps:
- name: Notify rollback required
run: |
echo "::error::Production deployment failed. Manual rollback may be required."
echo "Failed SHA: ${{ github.sha }}"