Skip to content

Deploy Kainoscore to Staging #5

Deploy Kainoscore to Staging

Deploy Kainoscore to Staging #5

name: Deploy Kainoscore to Staging
on:
workflow_dispatch:
inputs:
version:
description: 'Version to deploy to staging (e.g. 1.10.1)'
required: true
env:
AWS_REGION: eu-west-2
DEPLOYMENT_ROLE: arn:aws:iam::975050265283:role/GHA-CodeBuild-Service-Role
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ENVIRONMENT: staging
permissions:
id-token: write
contents: write
jobs:
deploy:
name: Deploy to Staging
runs-on: ubuntu-latest
environment: Staging
outputs:
version: ${{ github.event.inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials via OIDC
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ env.DEPLOYMENT_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: Install Required Tools
run: |
npm install -g typescript
echo "NODE.JS version: $(node -v)"
echo "NPM version: $(npm -v)"
echo "AWS CLI version: $(aws --version)"
- name: Prepare Scripts
run: |
# Make sure the script file exists before making it executable
if [ ! -f "./pipeline_scripts/deploy-to-staging.sh" ]; then
echo "ERROR: deploy-to-staging.sh not found in pipeline_scripts directory"
ls -la ./pipeline_scripts/
exit 1
fi
chmod +x ./pipeline_scripts/deploy-to-staging.sh
chmod +x ./pipeline_scripts/update-lambda-functions.sh
chmod +x ./pipeline_scripts/functions.sh
chmod +x ./pipeline_scripts/deploy-static-files-staging.sh
ls -la ./pipeline_scripts/
- name: Copy Artifacts and Deploy to Staging
run: |
echo "Starting staging deployment for version ${{ github.event.inputs.version }}"
./pipeline_scripts/deploy-to-staging.sh "${{ github.event.inputs.version }}"
./pipeline_scripts/deploy-static-files-staging.sh "${{ github.event.inputs.version }}"
- name: Deployment Summary
run: |
echo "✅ Successfully deployed version v${{ github.event.inputs.version }} to staging"
echo " • Deployment Time: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
echo " • Deployed by: ${{ github.actor }}"
# Create an artifact with deployment details for tracking
mkdir -p deployment-info
cat > deployment-info/staging-deployment.txt << EOF
Version: v${{ github.event.inputs.version }}
Time: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
Actor: ${{ github.actor }}
Workflow Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
EOF
- name: Upload Deployment Info
uses: actions/[email protected]
with:
name: staging-deployment-v${{ github.event.inputs.version }}-${{ github.run_id }}
path: deployment-info
retention-days: 90
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: deploy
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate release notes
id: release-notes
run: |
echo "Generating release notes for v${{ needs.deploy.outputs.version }}"
# Extract commits since last release
git fetch --tags
# Get the last tag (could be production or staging)
PREV_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "none")
echo "Previous tag: $PREV_TAG"
if [ "$PREV_TAG" == "none" ] || [ -z "$PREV_TAG" ]; then
echo "No previous release found, getting last 15 commits"
COMMITS=$(git log --pretty=format:"- **%s** (%h) by %an" -15)
else
echo "Getting commits since $PREV_TAG"
COMMITS=$(git log --pretty=format:"- **%s** (%h) by %an" ${PREV_TAG}..HEAD)
fi
# Count commits
COMMIT_COUNT=$(echo "$COMMITS" | wc -l)
# Create release notes file
cat > release-notes.md << EOF
# 🚧 Staging Release v${{ needs.deploy.outputs.version }}
> ⚠️ **This is a pre-release for staging environment**
## 📋 What's Changed
${COMMITS}
**Total commits in this release:** $COMMIT_COUNT
## 🚧 Deployment Information
- **Environment:** Staging
- **Deployment time:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")
- **Deployed by:** ${{ github.actor }}
- **Workflow run:** [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
## 🔗 Links
- [Compare changes](https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v${{ needs.deploy.outputs.version }})
- [Full changelog](https://github.com/${{ github.repository }}/commits/v${{ needs.deploy.outputs.version }})
EOF
echo "Generated release notes:"
cat release-notes.md
- name: Create GitHub Release
uses: softprops/[email protected]
with:
name: "🚧 v${{ needs.deploy.outputs.version }} (Staging)"
tag_name: "v${{ needs.deploy.outputs.version }}"
body_path: release-notes.md
draft: false
prerelease: true
make_latest: false
token: ${{ secrets.GITHUB_TOKEN }}