|
| 1 | +# Do not edit this file! Make a pull request on changing |
| 2 | +# github/workflows/drupal/site.yaml in |
| 3 | +# https://github.com/itk-dev/devops_itkdev-docker if need be. |
| 4 | + |
| 5 | +### ### Drupal |
| 6 | +### |
| 7 | +### Checks that site can be installed and can be updated (from base branch on |
| 8 | +### pull request). |
| 9 | +### |
| 10 | +### #### Assumptions |
| 11 | +### |
| 12 | +### 1. A docker compose service named `phpfpm` can be run and `composer` can be |
| 13 | +### run inside the `phpfpm` service. |
| 14 | +### 2. The docker setup contains a database container and other the dependent |
| 15 | +### services and the default settings match connection credentials for these |
| 16 | +### services. |
| 17 | +### 3. The Drupal site can be installed from existing config. |
| 18 | + |
| 19 | +name: Drupal |
| 20 | + |
| 21 | +env: |
| 22 | + COMPOSE_USER: root |
| 23 | + |
| 24 | +on: |
| 25 | + pull_request: |
| 26 | + push: |
| 27 | + branches: |
| 28 | + - main |
| 29 | + - develop |
| 30 | + |
| 31 | +jobs: |
| 32 | + install-site: |
| 33 | + name: Check that site can be installed |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Start docker and install dependencies |
| 39 | + run: | |
| 40 | + docker network create frontend |
| 41 | + docker compose pull |
| 42 | + docker compose up --detach |
| 43 | +
|
| 44 | + # Important: Use --no-interaction to make https://getcomposer.org/doc/06-config.md#discard-changes have effect. |
| 45 | + docker compose exec phpfpm composer install --no-interaction |
| 46 | +
|
| 47 | + - name: Install site |
| 48 | + run: | |
| 49 | + # Add some local settings. |
| 50 | + cat > web/sites/default/settings.local.php <<'EOF' |
| 51 | + <?php |
| 52 | +
|
| 53 | + $settings['hash_salt'] = '${{ github.head_ref }}'; |
| 54 | + EOF |
| 55 | +
|
| 56 | + # Install the site from config |
| 57 | + docker compose exec phpfpm vendor/bin/drush site:install --existing-config --yes |
| 58 | +
|
| 59 | + - name: Show site URL |
| 60 | + run: | |
| 61 | + echo $(docker compose exec phpfpm vendor/bin/drush --uri=http://$(docker compose port nginx 8080) user:login) |
| 62 | +
|
| 63 | + update-site: |
| 64 | + # Check updating site only on pull request. |
| 65 | + if: github.event_name == 'pull_request' |
| 66 | + name: Check that site can be updated |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + # Install site from our base ref |
| 70 | + - uses: actions/checkout@v4 |
| 71 | + with: |
| 72 | + ref: ${{ github.base_ref }} |
| 73 | + |
| 74 | + - name: Start docker and install dependencies |
| 75 | + run: | |
| 76 | + docker network create frontend |
| 77 | + docker compose pull |
| 78 | + docker compose up --detach |
| 79 | +
|
| 80 | + # Important: Use --no-interaction to make https://getcomposer.org/doc/06-config.md#discard-changes have effect. |
| 81 | + docker compose exec phpfpm composer install --no-interaction |
| 82 | +
|
| 83 | + - name: Install site |
| 84 | + run: | |
| 85 | + # Add some local settings. |
| 86 | + cat > web/sites/default/settings.local.php <<'EOF' |
| 87 | + <?php |
| 88 | +
|
| 89 | + $settings['hash_salt'] = '${{ github.head_ref }}'; |
| 90 | + EOF |
| 91 | +
|
| 92 | + # Install the site from config |
| 93 | + docker compose exec phpfpm vendor/bin/drush site:install --existing-config --yes |
| 94 | +
|
| 95 | + - name: Show site URL |
| 96 | + run: | |
| 97 | + echo $(docker compose exec phpfpm vendor/bin/drush --uri=http://$(docker compose port nginx 8080) user:login) |
| 98 | +
|
| 99 | + - name: Clean up root stuff |
| 100 | + run: | |
| 101 | + sudo chown -Rv $USER:$USER vendor/ web/ private-files/ || true |
| 102 | + sudo chmod -Rv a+w web/sites/default || true |
| 103 | +
|
| 104 | + # Install site with our current ref |
| 105 | + - uses: actions/checkout@v4 |
| 106 | + with: |
| 107 | + ref: ${{ github.head_ref }} |
| 108 | + # Keep our local settings (cf. |
| 109 | + # https://github.com/actions/checkout?tab=readme-ov-file#usage) |
| 110 | + clean: false |
| 111 | + |
| 112 | + - name: Start docker and install dependencies |
| 113 | + run: | |
| 114 | + docker network create frontend || true |
| 115 | + docker compose pull |
| 116 | + docker compose up --detach |
| 117 | +
|
| 118 | + # Important: Use --no-interaction to make https://getcomposer.org/doc/06-config.md#discard-changes have effect. |
| 119 | + docker compose exec phpfpm composer install --no-interaction |
| 120 | +
|
| 121 | + - name: Update site |
| 122 | + run: | |
| 123 | + docker compose exec phpfpm vendor/bin/drush deploy --yes |
| 124 | +
|
| 125 | + - name: Show site URL |
| 126 | + run: | |
| 127 | + echo $(docker compose exec phpfpm vendor/bin/drush --uri=http://$(docker compose port nginx 8080) user:login) |
0 commit comments