Setup the repo #10
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
| # | |
| # This workflow is for testing your server's config. | |
| # | |
| # It will launch a docker-based test server, run your ansible playbook, and launch a site with ddev. | |
| # | |
| # This allows you to create pull requests to alter server config, with CI/CD to ensure it works. | |
| # | |
| name: Server Test | |
| on: | |
| pull_request: | |
| env: | |
| # To install github runners automatically, you need a personal access token with admin:write permissions on your repository. | |
| GITHUB_TOKEN: "${{ secrets.OUR_GITHUB_TOKEN_RUNNER_ADMIN }}" | |
| # The playbook to run. | |
| # You can use the one included in the site-runn ansible roles or make your own. | |
| # ANSIBLE_PLAYBOOK: ansible/site-runner/playbook.yml | |
| ANSIBLE_PLAYBOOK: ansible/playbook.example.yml | |
| RUNNER_NAME: platform@server.mysite.com | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.number }} | |
| cancel-in-progress: false | |
| jobs: | |
| create-server: | |
| name: Launch test runner | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| submodules: 'recursive' | |
| # run-with-summary, etc | |
| - uses: jonpugh/goatscripts@main | |
| # Site runner ansible roles now sets SSH config to allow hosts to become known on first connection. | |
| - name: Set ansible variables | |
| run: | | |
| echo "operations_platform_ssh_private_key: \"${{ secrets.SSH_PRIVATE_KEY }}\"" > vars.ci.yml | |
| cat vars.ci.yml | |
| - name: Inventory | |
| run: run-with-summary ansible-playbook ${ANSIBLE_PLAYBOOK} --list-hosts | |
| env: | |
| SUCCESS: "Ansible inventory" | |
| ERROR: "Ansible inventory list failed" | |
| HIDE: true | |
| - name: Playbook | |
| env: | |
| SUCCESS: "Ansible playbook completed successfully." | |
| ERROR: "Ansible playbook failed!" | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| run: | | |
| run-with-summary \ | |
| ansible-playbook ${ANSIBLE_PLAYBOOK} \ | |
| --extra-vars operations_github_api_token=${RUNNER_GITHUB_TOKEN} | |
| # Kick off the runner script over and over until there are no more queued jobs. | |
| # Each runner is --ephemeral, runs one job. | |
| - name: "Launch runner script." | |
| run: | | |
| while [[ $(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" | jq -r '.jobs[] | select(.status=="queued") | .id' | wc -l) -gt 0 ]]; do | |
| sleep 2 | |
| ./github-runner-starter \ | |
| --run \ | |
| --name=github.actions.runner.${{ github.run_id }}.${{ matrix.runner }} \ | |
| --labels=github.actions.runner.${{ github.run_id }} \ | |
| --config-sh-options=--ephemeral | |
| sleep 2 | |
| done | |
| create-site: | |
| name: Create Preview Site | |
| uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.deploy.ddev.yml@feature/reusable-workflows | |
| with: | |
| # Configure your site here. | |
| git_root: /home/runner/ourproject/pr${{ github.event.number }} | |
| # Use the http URL. | |
| git_repository: ${{ github.event.repository.clone_url }} | |
| # Must be unique per server. | |
| ddev_project_name: ourproject.pr${{ github.event.number }} | |
| # Used to create a system domain. | |
| ddev_project_tld: sites.server.mysite.com | |
| # Tell the remote workflow what to run on. | |
| github_runs_on: platform@server.mysite.com | |
| # Define the github environment name, to be displayed in the UI. | |
| github_environment_name: pr${{ github.event.number }} | |
| # Define a github environment url, a link to be shown on the pull request. | |
| github_environment_url: http://pr${{ github.event.number }}.sites.server.mysite.com | |
| # To persist a site's data, set "run_prepare_command" to false. | |
| run_prepare_command: true | |
| prepare_command: echo "Preparing site..." | |
| # Command to run after deploying code. | |
| deploy_command: ddev exec echo "Hello from $(hostname)!" | |
| # Additional ddev config to apply to the environment. | |
| # Will be saved to .ddev/config.zzz.runner.yaml | |
| ddev_config: | | |
| additional_fqdns: | |
| - admin.pr${{ github.event.number }}.sites.server.mysite.com | |
| - ddev-runner.ddev.site | |
| run-command: | |
| name: DDEV Status | |
| uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.command.yml@feature/reusable-workflows | |
| needs: create-site | |
| with: | |
| working_directory: /home/runner/ourproject/pr${{ github.event.number }} | |
| github_runs_on: github.actions.runner.${{ github.run_id }} | |
| command: ddev status | |
| env: | | |
| SUCCESS="DDEV Status" | |
| HIDE=1 | |
| test-site: | |
| name: Run tests | |
| needs: create-site | |
| runs-on: github.actions.runner.${{ github.run_id }} | |
| steps: | |
| - uses: jonpugh/goatscripts@main | |
| - name: Check homepage for Hello World. | |
| env: | |
| SUCCESS: "Tests passed! DDEV webserver is online. :boom:" | |
| ERROR: "Unable to load DDEV website. :x:" | |
| run: | | |
| run-with-summary curl https://ddev-runner.ddev.site | |
| curl -s https://ddev-runner.ddev.site | grep "Hello World!" | |
| remove-site: | |
| name: Remove Site | |
| uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.destroy.ddev.yml@feature/reusable-workflows | |
| needs: test-site | |
| with: | |
| git_root: /home/runner/ourproject/pr${{ github.event.number }} | |
| github_runs_on: github.actions.runner.${{ github.run_id }} |