Migrate Core API functionalities to Storage from Database #24 #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Production | |
| on: | |
| push: | |
| branches: | |
| - production | |
| workflow_dispatch: | |
| inputs: | |
| stage: | |
| description: 'Deployment stage' | |
| required: false | |
| default: 'prod' | |
| type: choice | |
| options: | |
| - prod | |
| - dev | |
| permissions: | |
| contents: read | |
| packages: read | |
| env: | |
| NODE_VERSION: '22' | |
| AWS_REGION: 'eu-west-1' | |
| jobs: | |
| setup: | |
| name: Setup and Validate | |
| runs-on: ubuntu-latest | |
| outputs: | |
| stage: ${{ steps.set-stage.outputs.stage }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@taleofddh' | |
| - name: Configure npm for GitHub packages | |
| run: | | |
| echo "@taleofddh:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc | |
| - name: Set deployment stage | |
| id: set-stage | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "stage=${{ github.event.inputs.stage }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "stage=prod" >> $GITHUB_OUTPUT | |
| fi | |
| install: | |
| name: Install Dependencies | |
| runs-on: ubuntu-latest | |
| needs: setup | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@taleofddh' | |
| - name: Configure npm for GitHub packages | |
| run: | | |
| # Use NPM_TOKEN if available, otherwise fall back to GITHUB_TOKEN | |
| if [ -n "${{ secrets.NPM_TOKEN }}" ]; then | |
| echo "Using NPM_TOKEN for authentication" | |
| echo "@taleofddh:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc | |
| else | |
| echo "Using GITHUB_TOKEN for authentication" | |
| echo "@taleofddh:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc | |
| fi | |
| echo "Configured npm for GitHub packages in install job" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install root dependencies | |
| run: | | |
| if [ -f package.json ]; then | |
| npm ci | |
| else | |
| echo "No root package.json found, skipping root install" | |
| fi | |
| - name: Clean stale package locks and node_modules | |
| run: | | |
| echo "Cleaning stale package-lock.json files and node_modules..." | |
| for dir in */; do | |
| if [ -f "${dir}package.json" ] && [ -d "${dir}" ]; then | |
| echo "Cleaning ${dir%/}..." | |
| # Remove package-lock.json to force regeneration with correct versions | |
| if [ -f "${dir}package-lock.json" ]; then | |
| rm "${dir}package-lock.json" | |
| echo " Removed stale package-lock.json" | |
| fi | |
| # Remove node_modules to ensure clean install | |
| if [ -d "${dir}node_modules" ]; then | |
| rm -rf "${dir}node_modules" | |
| echo " Removed node_modules" | |
| fi | |
| fi | |
| done | |
| - name: Create .npmrc files for all modules | |
| run: | | |
| echo "Creating .npmrc files for all Lambda modules..." | |
| for dir in */; do | |
| if [ -f "${dir}package.json" ] && [ -d "${dir}" ]; then | |
| echo "Creating .npmrc for module: ${dir%/}" | |
| if [ -n "${{ secrets.NPM_TOKEN }}" ]; then | |
| cat > "${dir}.npmrc" << EOF | |
| //npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }} | |
| @taleofddh:registry=https://npm.pkg.github.com | |
| EOF | |
| else | |
| cat > "${dir}.npmrc" << EOF | |
| //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} | |
| @taleofddh:registry=https://npm.pkg.github.com | |
| EOF | |
| fi | |
| fi | |
| done | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install module dependencies | |
| run: | | |
| echo "Installing dependencies for all Lambda modules..." | |
| node scripts/install.js | |
| env: | |
| CI: true | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} | |
| - name: Cache node_modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| node_modules | |
| */node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| deploy: | |
| name: Deploy to ${{ needs.setup.outputs.stage }} | |
| runs-on: ubuntu-latest | |
| needs: [setup, install] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@taleofddh' | |
| - name: Configure npm for GitHub packages | |
| run: | | |
| # Use NPM_TOKEN if available, otherwise fall back to GITHUB_TOKEN | |
| if [ -n "${{ secrets.NPM_TOKEN }}" ]; then | |
| echo "Using NPM_TOKEN for authentication" | |
| echo "@taleofddh:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc | |
| else | |
| echo "Using GITHUB_TOKEN for authentication" | |
| echo "@taleofddh:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc | |
| fi | |
| echo "Configured npm for GitHub packages in deploy job" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create .npmrc files for all modules (deploy) | |
| run: | | |
| echo "Creating .npmrc files for all Lambda modules in deploy job..." | |
| for dir in */; do | |
| if [ -f "${dir}package.json" ] && [ -d "${dir}" ]; then | |
| echo "Creating .npmrc for module: ${dir%/}" | |
| if [ -n "${{ secrets.NPM_TOKEN }}" ]; then | |
| cat > "${dir}.npmrc" << EOF | |
| //npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }} | |
| @taleofddh:registry=https://npm.pkg.github.com | |
| EOF | |
| else | |
| cat > "${dir}.npmrc" << EOF | |
| //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} | |
| @taleofddh:registry=https://npm.pkg.github.com | |
| EOF | |
| fi | |
| fi | |
| done | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Restore cached dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| node_modules | |
| */node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Configure AWS Profile | |
| run: | | |
| mkdir -p ~/.aws | |
| cat > ~/.aws/credentials << EOF | |
| [taleofddh] | |
| aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| EOF | |
| cat > ~/.aws/config << EOF | |
| [profile taleofddh] | |
| region = ${{ env.AWS_REGION }} | |
| output = json | |
| EOF | |
| # Export AWS credentials as environment variables for tools that require them | |
| export AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" | |
| export AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" | |
| export AWS_DEFAULT_REGION="${{ env.AWS_REGION }}" | |
| export AWS_PROFILE=taleofddh | |
| # Persist environment variables across workflow steps | |
| echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV | |
| echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV | |
| echo "AWS_DEFAULT_REGION=${{ env.AWS_REGION }}" >> $GITHUB_ENV | |
| echo "AWS_PROFILE=taleofddh" >> $GITHUB_ENV | |
| echo "AWS profile 'taleofddh' configured successfully" | |
| - name: Install Serverless Framework | |
| run: npm install -g serverless | |
| - name: Deploy all modules | |
| run: | | |
| echo "Deploying all modules to ${{ needs.setup.outputs.stage }} environment..." | |
| node scripts/deploy.js ${{ needs.setup.outputs.stage }} | |
| env: | |
| AWS_REGION: ${{ env.AWS_REGION }} | |
| STAGE: ${{ needs.setup.outputs.stage }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} | |
| SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} | |
| - name: Generate deployment summary | |
| if: always() | |
| run: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Stage**: ${{ needs.setup.outputs.stage }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Region**: ${{ env.AWS_REGION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ job.status }}" = "success" ]; then | |
| echo "- **Status**: ✅ Deployment successful" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- **Status**: ❌ Deployment failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| notify: | |
| name: Notify Deployment Status | |
| runs-on: ubuntu-latest | |
| needs: [setup, deploy] | |
| if: always() | |
| steps: | |
| - name: Notify success | |
| if: needs.deploy.result == 'success' | |
| run: | | |
| echo "🎉 Deployment to ${{ needs.setup.outputs.stage }} completed successfully!" | |
| echo "Commit: ${{ github.sha }}" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "Triggered by: ${{ github.actor }}" | |
| - name: Notify failure | |
| if: needs.deploy.result == 'failure' | |
| run: | | |
| echo "❌ Deployment to ${{ needs.setup.outputs.stage }} failed!" | |
| echo "Commit: ${{ github.sha }}" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "Triggered by: ${{ github.actor }}" | |
| echo "Please check the deployment logs for details." | |
| exit 1 | |
| - name: Notify cancellation | |
| if: needs.deploy.result == 'cancelled' | |
| run: | | |
| echo "⚠️ Deployment to ${{ needs.setup.outputs.stage }} was cancelled!" | |
| echo "Commit: ${{ github.sha }}" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "Triggered by: ${{ github.actor }}" |