fix: resolve deployment issues with nx command and force build flag #67
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 Dev Environment | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| workflow_dispatch: | |
| inputs: | |
| force_build_all: | |
| description: 'Force build all sites (Portal + all standards)' | |
| required: false | |
| default: 'false' | |
| type: boolean | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages-dev" | |
| cancel-in-progress: false | |
| jobs: | |
| detect-and-build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| affected-projects: ${{ steps.affected.outputs.projects }} | |
| has-affected: ${{ steps.affected.outputs.has-affected }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for NX affected | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'pnpm' | |
| - name: Get pnpm store directory | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - name: Setup pnpm cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install dependencies | |
| run: pnpm install --no-frozen-lockfile | |
| - name: Setup NX Cloud | |
| uses: nrwl/nx-set-shas@v4 | |
| - name: Debug NX setup | |
| run: | | |
| echo "NX_BASE: $NX_BASE" | |
| echo "NX_HEAD: $NX_HEAD" | |
| echo "Current HEAD: $(git rev-parse HEAD)" | |
| echo "Previous commits:" | |
| git log --oneline -5 | |
| - name: Detect affected projects | |
| id: affected | |
| run: | | |
| # Check for force build flag (handle empty string as false) | |
| FORCE_BUILD="${{ inputs.force_build_all }}" | |
| if [ "$FORCE_BUILD" = "true" ]; then | |
| echo "Force building all projects..." | |
| projects=$(pnpm nx show projects --type=app | tr '\n' ' ') | |
| echo "projects=$projects" >> $GITHUB_OUTPUT | |
| echo "has-affected=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Detecting affected projects..." | |
| echo "Base SHA: $NX_BASE" | |
| echo "Head SHA: $NX_HEAD" | |
| # Show what would be affected (including libraries for debugging) | |
| echo "All affected projects:" | |
| pnpm nx show projects --affected || echo "Failed to get affected projects" | |
| # Get affected apps for deployment | |
| affected=$(pnpm nx show projects --affected --type=app 2>/dev/null | tr '\n' ' ' || echo "") | |
| if [ -z "$affected" ]; then | |
| echo "No affected app projects found" | |
| echo "Trying with explicit base SHA..." | |
| if [ -n "$NX_BASE" ]; then | |
| affected=$(pnpm nx show projects --affected --type=app --base=$NX_BASE 2>/dev/null | tr '\n' ' ' || echo "") | |
| fi | |
| # Special handling for theme changes - if theme is affected, all apps should rebuild | |
| if [ -z "$affected" ]; then | |
| echo "Checking if theme package is affected..." | |
| theme_affected=$(pnpm nx show projects --affected | grep "@ifla/theme" || echo "") | |
| if [ -n "$theme_affected" ]; then | |
| echo "Theme package is affected - rebuilding all sites" | |
| affected=$(pnpm nx show projects --type=app | tr '\n' ' ') | |
| echo "All projects due to theme change: $affected" | |
| echo "projects=$affected" >> $GITHUB_OUTPUT | |
| echo "has-affected=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No affected projects found - setting has-affected=false" | |
| echo "has-affected=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "Found affected projects with explicit base: $affected" | |
| echo "projects=$affected" >> $GITHUB_OUTPUT | |
| echo "has-affected=true" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "Affected projects: $affected" | |
| echo "projects=$affected" >> $GITHUB_OUTPUT | |
| echo "has-affected=true" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| - name: Build affected projects | |
| if: steps.affected.outputs.has-affected == 'true' | |
| run: | | |
| FORCE_BUILD="${{ inputs.force_build_all }}" | |
| if [ "$FORCE_BUILD" = "true" ]; then | |
| echo "Force building all projects" | |
| pnpm nx run-many --target=build --all --parallel=1 --configuration=development | |
| else | |
| echo "Building affected projects" | |
| pnpm nx affected --target=build --parallel=1 --configuration=development | |
| fi | |
| env: | |
| DOCS_ENV: development | |
| NODE_ENV: production | |
| BASE_URL_PREFIX: /standards-dev/ | |
| - name: Upload artifacts for each built project | |
| if: steps.affected.outputs.has-affected == 'true' | |
| run: | | |
| # Upload each built project as a separate artifact | |
| for project in ${{ steps.affected.outputs.projects }}; do | |
| if [ "$project" = "portal" ]; then | |
| project_path="portal" | |
| else | |
| project_path="standards/${project}" | |
| fi | |
| if [ -d "${project_path}/build" ]; then | |
| echo "Uploading artifact for $project..." | |
| # Use actions/upload-artifact@v4 programmatically | |
| mkdir -p /tmp/artifacts | |
| cp -r ${project_path}/build /tmp/artifacts/${project} | |
| fi | |
| done | |
| - name: Upload combined artifact | |
| if: steps.affected.outputs.has-affected == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: all-builds | |
| path: | | |
| portal/build | |
| standards/*/build | |
| retention-days: 1 | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: detect-and-build | |
| if: needs.detect-and-build.outputs.has-affected == 'true' | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: all-builds | |
| path: . | |
| - name: Combine builds | |
| run: | | |
| mkdir -p combined-build | |
| # Copy portal to root if it exists | |
| if [ -d "portal/build" ]; then | |
| cp -r portal/build/* combined-build/ | |
| mkdir -p combined-build/portal | |
| cp -r portal/build/* combined-build/portal/ | |
| fi | |
| # Copy all standards builds | |
| for standard_dir in standards/*/build; do | |
| if [ -d "$standard_dir" ]; then | |
| standard_name=$(basename $(dirname "$standard_dir")) | |
| mkdir -p combined-build/${standard_name} | |
| cp -r $standard_dir/* combined-build/${standard_name}/ | |
| fi | |
| done | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Upload to Pages | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: combined-build | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |