This repository was archived by the owner on Feb 24, 2026. It is now read-only.
Generate WebApp dependencies image #4
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: Generate WebApp dependencies image | |
| on: | |
| workflow_call: | |
| inputs: | |
| ref: | |
| description: 'The branch, tag or SHA to checkout' | |
| required: false | |
| type: string | |
| default: '' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| type: choice | |
| required: true | |
| default: 'staging' | |
| options: | |
| - staging | |
| - production | |
| force_rebuild: | |
| description: 'Force rebuild even if no changes detected' | |
| type: boolean | |
| required: false | |
| default: false | |
| jobs: | |
| check-web-changes: | |
| name: Check for dependency changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changes_detected: ${{ steps.check-web-changes.outputs.changes_detected }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ inputs.ref || github.ref }} | |
| fetch-depth: 0 | |
| - name: Check for changes in dependency files | |
| id: check-web-changes | |
| run: | | |
| # If force_rebuild is true, skip detection | |
| if [ "${{ inputs.force_rebuild || false }}" = "true" ]; then | |
| echo "changes_detected=true" >> $GITHUB_OUTPUT | |
| echo "Force rebuild requested - skipping change detection" | |
| exit 0 | |
| fi | |
| # For manual triggers or workflow calls, check if files have changed | |
| if git rev-parse --verify HEAD^1 >/dev/null 2>&1; then | |
| # If we have a parent commit, compare with it | |
| CHANGED_FILES=$(git diff --name-only HEAD^1 HEAD) | |
| else | |
| # If this is the first commit or we're on a different branch | |
| # List all tracked files | |
| CHANGED_FILES=$(git ls-tree -r --name-only HEAD) | |
| fi | |
| # Define the pattern for dependency-related files | |
| DEPENDENCY_PATTERN="^package\.json$|^yarn\.lock$|^apps\/gauzy\/package\.json$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/(contracts|ui-auth|ui-config|ui-core)\/.*package\.json$" | |
| # Detect changes in UI and contracts source code that affect compilation | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/contracts\/src\/.*\.ts$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/ui-auth\/src\/.*\.ts$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/ui-config\/src\/.*\.ts$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/ui-core\/src\/.*\.ts$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^packages\/plugins\/[a-z\-]+(-ui)\/.*package\.json$" | |
| DEPENDENCY_PATTERN="$DEPENDENCY_PATTERN|^\.deploy\/dependencies\/webapp\/|^\.github\/workflows\/webapp-dependencies\.yml$" | |
| if echo "$CHANGED_FILES" | grep -q -E "$DEPENDENCY_PATTERN"; then | |
| echo "changes_detected=true" >> $GITHUB_OUTPUT | |
| echo "Dependency changes detected" | |
| else | |
| echo "changes_detected=false" >> $GITHUB_OUTPUT | |
| echo "No dependency changes detected" | |
| fi | |
| handle-no-changes: | |
| name: Handle no changes | |
| needs: check-web-changes | |
| if: needs.check-web-changes.outputs.changes_detected != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: No changes required | |
| run: | | |
| echo "No dependency changes detected. No rebuild required." | |
| exit 0 | |
| generate-dependencies: | |
| name: Generate dependencies image | |
| needs: check-web-changes | |
| if: needs.check-web-changes.outputs.changes_detected == 'true' | |
| runs-on: ubuntu-latest | |
| # Determine environment based on manual input or ref | |
| environment: ${{ inputs.environment || (startsWith(github.ref, 'refs/tags/v') && 'production' || 'staging') }} | |
| permissions: | |
| contents: read | |
| id-token: write | |
| # Environment variables are defined at the job level | |
| env: | |
| # These values come from the environment configuration in GitHub | |
| AWS_REGION: ${{ vars.AWS_REGION }} | |
| ECR_REGISTRY: ${{ vars.ECR_REGISTRY }} | |
| ECR_REPOSITORY_DEPENDENCIES: ${{ vars.ECR_REPOSITORY_DEPENDENCIES }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ inputs.ref || github.ref }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Build dependency images | |
| run: | | |
| docker build \ | |
| -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_DEPENDENCIES }}:latest-webapp \ | |
| -f .deploy/dependencies/webapp/Dockerfile \ | |
| . | |
| - name: Push images to Amazon ECR | |
| run: | | |
| docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_DEPENDENCIES }} --all-tags |