Building and (optionally) deploying for dev #430
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
| # SPDX-FileCopyrightText: Copyright (C) 2025 Opal Health Informatics Group at the Research Institute of the McGill University Health Centre <john.kildea@mcgill.ca> | |
| # | |
| # SPDX-License-Identifier: AGPL-3.0-or-later | |
| name: Build and Deploy | |
| # Default to dev when running automatically (see also "env" below) | |
| run-name: Building and (optionally) deploying for ${{ inputs.ENVIRONMENT || 'dev' }} | |
| on: | |
| # When pushing to main, automatically build for dev | |
| push: | |
| branches: | |
| - main | |
| # When updating a pull request or adding a pull request to a merge queue, automatically build for dev | |
| pull_request: | |
| merge_group: | |
| # Offer a manual interface to build for all other environments as needed | |
| workflow_dispatch: | |
| inputs: | |
| ENVIRONMENT: | |
| description: 'Environment in which to build' | |
| type: choice | |
| required: true | |
| default: 'dev' | |
| options: | |
| - dev | |
| - prod | |
| DEPLOY: | |
| description: 'Deploy the site' | |
| required: true | |
| default: true | |
| type: boolean | |
| env: | |
| # Read the target environment from workflow_dispatch inputs, or default to dev | |
| ENVIRONMENT: ${{ inputs.ENVIRONMENT || 'dev' }} | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Setup | |
| - name: Print environment | |
| run: echo "Environment = $ENVIRONMENT" | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - name: Set up build | |
| uses: ./.github/actions/build-setup | |
| with: | |
| CONFIG: ${{ vars[format('{0}_CONFIG', env.ENVIRONMENT)] }} | |
| # Build | |
| - name: Build the registration website | |
| run: npm run build | |
| - name: Organize the folder structure for the output | |
| run: | | |
| mkdir web-build | |
| cp -r dist web-build | |
| - name: Archive build output | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: web-build | |
| path: web-build | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: environments | |
| deployment: false | |
| # Deploy manually via inputs, or automatically (to dev) when building on main | |
| if: ${{ inputs.DEPLOY || github.ref_name == 'main' }} | |
| steps: | |
| # Setup | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - name: Download build artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: web-build | |
| run-id: ${{ github.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install lftp | |
| run: | | |
| sudo apt-get install lftp | |
| lftp --version | |
| - name: List contents of `dist` | |
| run: ls -la dist | |
| - name: Ensure $ENVIRONMENT is defined to avoid destructive mirroring on the server | |
| run: | | |
| echo "Environment = $ENVIRONMENT; target folder for upload is ./registration/${ENVIRONMENT}/" | |
| if [ -z "$ENVIRONMENT" ]; then exit 1; fi | |
| shell: bash | |
| # Upload web files | |
| # See: https://www.cyberciti.biz/faq/lftp-mirror-example/ | |
| # See: https://linuxconfig.org/lftp-tutorial-on-linux-with-examples | |
| - name: Upload files using lftp | |
| working-directory: dist | |
| run: > | |
| lftp -c " | |
| set cmd:fail-exit yes; | |
| open $FTP_HOST | |
| user $FTP_USER $FTP_PASSWORD; | |
| mirror --reverse --delete --parallel=10 --verbose ./ ./registration/${ENVIRONMENT}/; | |
| ls -la ./registration/${ENVIRONMENT}; | |
| bye | |
| " | |
| env: | |
| FTP_HOST: ${{ vars.FTP_HOST }} | |
| FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} | |
| FTP_USER: ${{ vars.FTP_USER }} |