From d70890212bc89f7531a10f539f1e5675e766b8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Advaita=20K=E1=B9=9B=E1=B9=A3=E1=B9=87a=20D=C4=81sa?= Date: Mon, 29 Jul 2024 10:15:44 +0200 Subject: [PATCH] CI/CD Workflow (#10) --- .github/workflows/release.yml | 227 ++++++++++++++++++++++++++++++++++ modules/apps/mobile | 2 +- 2 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6b8794d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,227 @@ +on: + release: + types: [published] + +env: + REGISTRY: ghcr.io + ORGANIZATION: akdasa-studios + VERSION: ${{ github.event.release.tag_name }} + +jobs: + # + # Stage 1: Build backend and staging mobile apps + # + + build-backend: + name: Build / ${{ matrix.config.name }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - config: + name: Gateway + service: gateway + context: ./modules/services/gateway + - config: + name: Database + service: database + context: ./modules/services/database/modules/database + - config: + name: Database Boostrtap + service: database-bootstrap + context: ./modules/services/database/modules/bootstrap + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + + - name: Setup Docker + uses: docker/setup-buildx-action@v2 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Image + uses: docker/build-push-action@v6 + with: + context: ${{ matrix.config.context }} + load: true + tags: | + ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-${{ matrix.config.service }}:${{ env.VERSION }}-dev + + - name: Push Image + run: | + docker push ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-${{ matrix.config.service }}:${{ env.VERSION }}-dev + + build-mobile-staging: + name: Build / ${{ matrix.config.name }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - config: + name: Android + platform: android + # - config: + # name: iOS + # platform: ios + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + + - name: Install tools + run: | + curl -fsSL https://ionic.io/get-appflow-cli | bash + + - name: Get Commit SHA + id: commit_sha + run: | + echo $(git submodule status ./modules/apps/mobile) + echo "::set-output name=sha::$(git submodule status ./modules/apps/mobile | awk '{print $1}' | cut -c 1-7)" + + - name: Build App + run: | + appflow build ${{ matrix.config.platform }} debug --commit=${{ steps.commit_sha.outputs.sha }} --app-id=${{ secrets.IONIC_APP_ID }} --token ${{ secrets.IONIC_TOKEN }} --environment="Staging" --apk-name=app.apk + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: app.apk + path: app.apk + + # + # Stage 2: Deploy backend to staging + # + + deploy-backend-staging: + name: Deploy / Staging + runs-on: ubuntu-latest + environment: Staging + needs: build-backend + permissions: + contents: read + packages: write + + steps: + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Promote Images + run: | + for service in gateway database database-bootstrap; do + docker pull ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-dev + docker tag ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-dev ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-rc + docker push ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-rc + done + + # + # Stage 3: Run E2E tests + # + + tests-e2e: + name: E2E Tests + runs-on: ubuntu-latest + needs: [deploy-backend-staging, build-mobile-staging] + permissions: + contents: read + packages: write + + steps: + - name: Run E2E Tests + run: | + echo "Running E2E tests" + + # + # Stage 4: Build production mobile apps and deploy to production + # + + build-mobile-production: + name: Build / ${{ matrix.config.name }} + runs-on: ubuntu-latest + needs: [tests-e2e] + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - config: + name: Android + - config: + name: iOS + - config: + name: Web + steps: + - name: Build App + run: | + echo "Building ${{ matrix.config.name }} app" + + deploy-backend-production: + name: Deploy / Production + runs-on: ubuntu-latest + environment: Production + needs: [tests-e2e] + permissions: + contents: read + packages: write + + steps: + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Promote Images + run: | + for service in gateway database database-bootstrap; do + docker pull ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-rc + docker tag ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-rc ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }} + docker tag ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }}-rc ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:latest + docker push ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:${{ env.VERSION }} + docker push ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/lectorium-$service:latest + done + + # + # Stage 5: Publish mobile apps + # + + publish-mobile: + name: Publish / ${{ matrix.config.name }} + runs-on: ubuntu-latest + needs: [deploy-backend-production, build-mobile-production] + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - config: + name: Android + - config: + name: iOS + + steps: + - name: Publish App + run: | + echo "Publishing ${{ matrix.config.name }} app" diff --git a/modules/apps/mobile b/modules/apps/mobile index b2c5c34..3ef967d 160000 --- a/modules/apps/mobile +++ b/modules/apps/mobile @@ -1 +1 @@ -Subproject commit b2c5c3408304552d3f9267b6aabf6e65a0dcfa58 +Subproject commit 3ef967d1fad6893124df820acb4a782774b91f0a