Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from Lullabot/82-interactive-cli
Browse files Browse the repository at this point in the history
Interactive cli
  • Loading branch information
juampynr authored Jul 7, 2022
2 parents 519a879 + 6309765 commit db09477
Show file tree
Hide file tree
Showing 24 changed files with 899 additions and 148 deletions.
21 changes: 1 addition & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
- image: juampynr/drupal8ci:latest

working_directory: /opt/drupal

- image: alpine:latest
steps:
- checkout

- run:
name: Build Drupal skeleton with Composer Drupal Project
command: |
composer create-project drupal-composer/drupal-project:9.x-dev drupal --stability dev --no-interaction
- run:
name: Run setup script
command: |
cp setup-circleci.sh drupal
cd drupal
./setup-circleci.sh
28 changes: 28 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Create release
on:
push:
branches:
- master
- 82-interactive-cli
jobs:
create-release:
name: Build and create a release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
- name: Build application
run: |
go build
- name: Set short sha
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- uses: marvinpinto/action-automatic-releases@latest
with:
automatic_release_tag: ${{ steps.vars.outputs.sha_short }}
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
drupal9ci
21 changes: 21 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish Docker image
on:
push:
branches:
- master
- 82-interactive-cli

jobs:
publish-docker-image:
name: Publish Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: mr-smithers-excellent/docker-build-push@v5
with:
image: drupal9ci
tags: latest
registry: ghcr.io
githubOrg: lullabot
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test
on:
push:

jobs:
integration:
name: Integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
- name: Build application
run: |
go build
- name: Build Drupal skeleton with Composer Drupal Project
run: |
composer create-project drupal-composer/drupal-project:9.x-dev drupal --stability dev --no-interaction
- name: Copy application binary and run it
run: |
cp drupal9ci drupal
cd drupal
# We can't test interactive mode here so we pass a CI provider.
./drupal9ci Bitbucket
unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
- name: Run tests with coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
- uses: codecov/codecov-action@v3
with:
files: ./coverage.out
fail_ci_if_error: true
verbose: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
drupal9ci
coverage.txt
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM drupal:8.9-apache
FROM drupal:9-apache

RUN apt-get update && apt-get install -y \
git \
Expand Down Expand Up @@ -39,16 +39,16 @@ RUN pecl install xdebug && \
RUN wget https://robo.li/robo.phar && \
chmod +x robo.phar && mv robo.phar /usr/local/bin/robo

# Install node.
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && \
apt install -y nodejs xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2

# Install Dockerize.
ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# Install ImageMagic to take screenshots.
RUN pecl install imagick && \
docker-php-ext-enable imagick

# Install Chrome browser.
RUN apt-get install --yes gnupg2 apt-transport-https && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - && \
Expand Down
57 changes: 0 additions & 57 deletions Dockerfile9

This file was deleted.

69 changes: 28 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Drupal 9 CI

[![CircleCI](https://circleci.com/gh/Lullabot/drupal9ci.svg?style=svg)](https://circleci.com/gh/Lullabot/drupal9ci)
![Create release](https://github.com/lullabot/drupal9ci/actions/workflows/create-release/badge.svg)
![Publish Docker image](https://github.com/lullabot/drupal9ci/actions/workflows/publish-docker-image/badge.svg)
![Test](https://github.com/lullabot/drupal9ci/actions/workflows/test/badge.svg)
[![codecov](https://codecov.io/gh/Lullabot/drupal9ci/branch/master/graph/badge.svg?token=akwlXfbC0W)](https://codecov.io/gh/Lullabot/drupal9ci)

This repository provides the foundation to implement [Continuous Integration](https://en.wikipedia.org/wiki/Continuous_integration) in a Drupal 9
project using any of the following CI providers:
Expand All @@ -11,9 +14,6 @@ project using any of the following CI providers:
* [GitHub Actions](#github-actions)
* [Bitbucket Pipelines](#bitbucket)

To install, simply run the respective installer and allow the CI provider that you chose to watch repository changes
to start building on every pull request.

If you want to test an individual module instead of a Drupal project, see Andrew Berry's
[drupal_tests](https://github.com/deviantintegral/drupal_tests).

Expand All @@ -27,36 +27,27 @@ structure differs from what _drupal-project_ sets up, you will need to
adjust the CI scripts.

It's also recommended to adjust your project to add a subset of the `settings.php` file into
version control and rely on `settings.local.php` for setting the database connection. See [this
commit](https://github.com/juampynr/drupal8-circleci/commit/817d0b6674c42dba73165b047b6b89d72ee72d11)
which contains these changes among other ones. The CI scripts have their own `settings.local.php`
which is copied at build time into `web/sites/default`.
version control and rely on `settings.local.php` for setting the database connection. The CI scripts
have their own `settings.local.php` which is copied at build time into `web/sites/default`.

#### DocumentRoot: web vs docroot

By default Apache and the rest of the code is set up to have the `DocumentRoot` folder as `web`. If
By default, Apache and the rest of the code is set up to have the `DocumentRoot` folder as `web`. If
your project uses `docroot` instead, the easiest thing to do is to symlink one to the other. This can be
done adding a line like [this one](https://github.com/Lullabot/drupal9ci/blob/master/dist/bitbucket/RoboFile.php#L187)
before running Apache (you will need to adapt paths).

Otherwise you can go through the files and replace as needed. You can see a list of affected files in
Alternatively you can go through the files and replace as needed. You can see a list of affected files in
[this comment](https://github.com/Lullabot/drupal9ci/issues/74#issuecomment-884238645).

## Installation

Each CI tool has its own installer, which extracts the required files to run the jobs. It also
adds a demo module with tests.

Choose a CI tool from the list below and follow its installation steps.

### [CircleCI](https://circleci.com)

[Demo repository](https://github.com/juampynr/drupal8-circleci) | [Deep dive article](https://www.lullabot.com/articles/continuous-integration-drupal-8-circleci)

Open a terminal and run the installer from the root of your project:
```bash
curl -L https://github.com/lullabot/drupal9ci/raw/master/setup-circleci.sh | bash
```
Download the `drupal9ci` binary from https://github.com/Lullabot/drupal9ci/releases into the project root
and run the command as `./drupal9ci` and select CircleCI. Once complete, continue below to complete the setup.

Sign up at [CircleCI](https://circleci.com/) and allow access to your project's repository.

Expand All @@ -73,21 +64,17 @@ For an overview of the CircleCI features, have a look at
#### Using a custom Docker image

The [CircleCI configuration file](dist/circleci/.circleci/config.yml) uses a
[custom Docker image](https://hub.docker.com/r/juampynr/drupal8ci/) that extends from
the [official Drupal image](https://hub.docker.com/_/drupal/) and it is [hosted at
Docker Hub](https://hub.docker.com/r/juampynr/drupal8ci/). If this image
[custom Docker image](https://github.com/Lullabot/drupal9ci/pkgs/container/drupal9ci) that extends from
the [official Drupal image](https://hub.docker.com/_/drupal/). If this image
does not fit your project's architecture then consider [creating your own image](https://circleci.com/docs/2.0/custom-images/)
based out of it.


### [Travis CI](https://travis-ci.org)

[Demo repository](https://github.com/juampynr/drupal8-travis-ci) | [Deep dive article](https://www.lullabot.com/articles/continuous-integration-in-drupal-8-with-travis-ci)

Open a terminal and run the installer from the root of your project:
```bash
curl -L https://github.com/lullabot/drupal9ci/raw/master/setup-travis-ci.sh | bash
```
Download the `drupal9ci` binary from https://github.com/Lullabot/drupal9ci/releases into the project root
and run the command as `./drupal9ci` and select Travis CI. Once complete, continue below to complete the setup.

Sign up at [Travis CI](https://travis-ci.com/) and allow access to your project's repository:

Expand Down Expand Up @@ -128,26 +115,21 @@ at the pull request's status message:

[Demo repository](https://gitlab.com/juampynr/drupal8-gitlab) | [Deep dive article](https://www.lullabot.com/articles/installer-drupal-8-and-gitlab-ci)

Open a terminal and run the installer from the root of your project:
```bash
curl -L https://github.com/lullabot/drupal9ci/raw/master/setup-gitlab-ci.sh | bash
```
Download the `drupal9ci` binary from https://github.com/Lullabot/drupal9ci/releases into the project root
and run the command as `./drupal9ci` and select GitLab CI. Once complete, continue below to complete the setup.

Review, commit, and push the resulting changes. After doing that, navigate to the project's homepage
at GitLab and open the CI / CD >> Pipelines section. You should see a running pipeline like
the following one:

![GitLab pipeline](docs/images/gitlab-pipeline.png)


### [GitHub Actions](https://github.com/features/actions)

[Demo repository](https://github.com/juampynr/drupal8-github-actions)

Open a terminal and run the installer from the root of your project:
```bash
curl -L https://github.com/lullabot/drupal9ci/raw/master/setup-github-actions.sh | bash
```
Download the `drupal9ci` binary from https://github.com/Lullabot/drupal9ci/releases into the project root
and run the command as `./drupal9ci` and select GitHub Actions. Once complete, continue below to complete the setup.

Review, commit, and push the resulting changes. After doing that, navigate to the repository's homepage
at GitHub and open the Actions tab. You should see a running workflow like the following one:
Expand All @@ -157,24 +139,27 @@ at GitHub and open the Actions tab. You should see a running workflow like the f

### [Bitbucket](https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines)

Open a terminal and run the installer from the root of your project:
```bash
curl -L https://github.com/lullabot/drupal9ci/raw/master/setup-bitbucket.sh | bash
```
Download the `drupal9ci` binary from https://github.com/Lullabot/drupal9ci/releases into the project root
and run the command as `./drupal9ci` and select Bitbucket. Once complete, continue below to complete the setup.

Review, commit, and push the resulting changes. After doing that, navigate to the repository's homepage
at Bitbucket and open the Pipelines tab. You should see a running workflow like the following one:

![Bitbucket pipelines](docs/images/bitbucket.png)


### Setting up the Behat and Cypress jobs for all platforms

The Behat and Cypress jobs require a running Drupal 9 site. The repository contains the code, but for running
tests in a realistic environment you need:

##### 1. A recent copy of the production environment's database

There are several ways to accomplish this:

**Using a prepopulated Docker database image**

See [Achieve Rocketship-Fast Jobs in CircleCI by Preinstalling the Database](https://www.lullabot.com/articles/rocket-ship-fast-jobs-circleci-preinstalling-database)

**Travis**

If you have Drush site aliases, and your repository is private, then follow these
Expand All @@ -195,6 +180,8 @@ For example:
![Travis CI db env var](docs/images/travisci-db-var.png)
![CircleCI database via environment variable](docs/images/circleci-db-env.png)

A sample implementation is to use Dropbox API. [See this repository for further details](https://github.com/juampynr/dropbox-api).

##### 2. The production environment's files directory

If you have a site alias, then add `drush rsync @my.alias @self` to the Behat job. Alternatively,
Expand Down
Loading

0 comments on commit db09477

Please sign in to comment.