2022-12-06 19:22:54 +01:00
name : Tests and delivery
2020-04-28 06:28:33 +02:00
on :
2021-01-30 02:02:05 +01:00
schedule :
- cron : '0 8 * * *' # Run at 8AM UTC.
2020-04-28 06:28:33 +02:00
push :
branches :
2020-06-05 15:41:28 +02:00
- '2.x'
2020-11-23 21:08:08 +01:00
- '2.x-**'
2022-04-08 03:37:35 +02:00
tags :
- '2.*'
2020-12-23 00:32:47 +01:00
pull_request :
branches :
- '2.x'
2020-04-28 06:28:33 +02:00
jobs :
build :
2021-12-10 21:05:48 +01:00
name : Build Docker images
runs-on : ubuntu-latest
steps :
- name : Checkout the repository
2022-10-12 13:24:36 +02:00
uses : actions/checkout@v3
2022-04-18 21:45:31 +02:00
- name : Set default FARMOS_REPO and FARMOS_VERSION.
run : |
echo "FARMOS_REPO=${GITHUB_REPOSITORY}" >> $GITHUB_ENV
echo "FARMOS_VERSION=2.x" >> $GITHUB_ENV
2022-04-08 03:27:36 +02:00
- name : Set FARMOS_VERSION for branch push event.
if : github.event_name == 'push' && github.ref_type == 'branch'
run : echo "FARMOS_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
2022-04-08 03:37:35 +02:00
- name : Set FARMOS_VERSION for tag push event.
if : github.event_name == 'push' && github.ref_type == 'tag'
run : echo "FARMOS_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
2022-04-08 03:27:36 +02:00
- name : Set FARMOS_VERSION and FARMOS_REPO for pull request event.
if : github.event_name == 'pull_request'
2021-12-10 21:05:48 +01:00
run : |
echo "FARMOS_VERSION=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
echo "FARMOS_REPO=${{ github.event.pull_request.head.repo.full_name }}" >> $GITHUB_ENV
2022-04-08 02:51:24 +02:00
- name : Build and save farmOS 2.x Docker image
run : |
docker build --build-arg FARMOS_REPO=https://github.com/${FARMOS_REPO} --build-arg FARMOS_VERSION=${FARMOS_VERSION} -t farmos/farmos:2.x docker
docker save farmos/farmos:2.x > /tmp/farmos-2x.tar
- name : Cache farmOS 2.x Docker image
uses : actions/cache@v3
with :
path : /tmp/farmos-2x.tar
key : farmos-2x-${{ github.run_id }}
2021-12-10 21:05:48 +01:00
# This builds the dev Docker image using the specified FARMOS_VERSION,
# but notably it does NOT override the default PROJECT_VERSION, so the
# farmOS Composer project 2.x branch is always used.
2022-04-07 16:23:40 +02:00
- name : Build and save farmOS 2.x-dev Docker image
2021-12-10 21:05:48 +01:00
run : |
2022-04-07 16:23:40 +02:00
docker build --build-arg FARMOS_REPO=https://github.com/${FARMOS_REPO} --build-arg FARMOS_VERSION=${FARMOS_VERSION} -t farmos/farmos:2.x-dev docker/dev
docker save farmos/farmos:2.x-dev > /tmp/farmos-2x-dev.tar
- name : Cache farmOS 2.x-dev Docker image
uses : actions/cache@v3
2021-12-10 21:05:48 +01:00
with :
2022-04-07 16:23:40 +02:00
path : /tmp/farmos-2x-dev.tar
key : farmos-2x-dev-${{ github.run_id }}
2022-04-08 03:37:35 +02:00
outputs :
farmos_version : ${{ env.FARMOS_VERSION }}
2022-01-06 23:22:47 +01:00
sniff :
2022-09-12 16:37:59 +02:00
name : Run PHP Codesniffer and PHPStan
2022-01-06 23:22:47 +01:00
runs-on : ubuntu-latest
needs : build
steps :
- name : Checkout the repository
2022-10-12 13:24:36 +02:00
uses : actions/checkout@v3
2022-04-07 16:23:40 +02:00
- name : Restore farmOS 2.x-dev Docker image from cache
uses : actions/cache@v3
2022-01-06 23:22:47 +01:00
with :
2022-04-07 16:23:40 +02:00
path : /tmp/farmos-2x-dev.tar
key : farmos-2x-dev-${{ github.run_id }}
2022-01-06 23:22:47 +01:00
- name : Load farmos/farmos:2.x-dev image
2022-04-07 16:23:40 +02:00
run : docker load < /tmp/farmos-2x-dev.tar
2022-01-06 23:22:47 +01:00
- name : Run PHP CodeSniffer
run : docker run farmos/farmos:2.x-dev phpcs /opt/drupal/web/profiles/farm
2022-09-12 16:37:59 +02:00
- name : Run PHPStan
run : docker run farmos/farmos:2.x-dev phpstan analyze /opt/drupal/web/profiles/farm
2022-11-12 16:57:26 +01:00
- name : Check PHP compatibility of contrib modules and themes (ignore warnings).
run : |
docker run farmos/farmos:2.x-dev phpcs --standard=PHPCompatibility --runtime-set testVersion 7.4- --warning-severity=0 /opt/drupal/web/modules
docker run farmos/farmos:2.x-dev phpcs --standard=PHPCompatibility --runtime-set testVersion 7.4- --warning-severity=0 /opt/drupal/web/themes
2021-12-10 21:05:48 +01:00
test :
2020-04-28 06:28:33 +02:00
name : Run PHPUnit tests
runs-on : ubuntu-latest
2021-12-10 21:05:48 +01:00
needs : build
2021-01-12 21:36:32 +01:00
strategy :
matrix :
dbms :
- pgsql
- mariadb
- sqlite
include :
2021-01-19 16:32:55 +01:00
- dbms : pgsql
2021-01-12 21:36:32 +01:00
DB_URL : pgsql://farm:farm@db/farm
2022-01-11 15:44:14 +01:00
processes : auto
2021-01-19 16:32:55 +01:00
- dbms : mariadb
2021-01-12 21:36:32 +01:00
DB_URL : mysql://farm:farm@db/farm
2022-01-11 15:44:14 +01:00
processes : auto
2021-01-19 16:32:55 +01:00
- dbms : sqlite
2021-01-12 21:36:32 +01:00
DB_URL : sqlite://localhost/sites/default/files/db.sqlite
2022-01-11 15:44:14 +01:00
processes : 1
2020-04-28 06:28:33 +02:00
steps :
2021-01-19 16:32:55 +01:00
- name : Print test matrix variables
run : echo "matrix.dbms=${{ matrix.dbms }}, matrix.DB_URL=${{ matrix.DB_URL }}"
2020-07-31 16:39:44 +02:00
- name : Checkout the repository
2022-10-12 13:24:36 +02:00
uses : actions/checkout@v3
2022-04-07 16:23:40 +02:00
- name : Restore farmOS 2.x-dev Docker image from cache
uses : actions/cache@v3
2021-12-10 21:05:48 +01:00
with :
2022-04-07 16:23:40 +02:00
path : /tmp/farmos-2x-dev.tar
key : farmos-2x-dev-${{ github.run_id }}
2021-12-10 21:05:48 +01:00
- name : Load farmos/farmos:2.x-dev image
2022-04-07 16:23:40 +02:00
run : docker load < /tmp/farmos-2x-dev.tar
2021-08-17 00:09:27 +02:00
# Build a new docker-compose.yml file from docker-compose.testing.common + docker-compose.testing.{dbms}.yml.
# Copy to the current directory so that farmOS volume mounts don't change to the docker/www folder.
2020-04-28 06:28:33 +02:00
- name : Create docker-compose.yml
2021-01-12 21:36:32 +01:00
env :
DB_URL : ${{ matrix.DB_URL }}
2021-08-17 00:09:27 +02:00
run : |
cp docker/docker-compose.testing.* .
2023-01-23 23:26:17 +01:00
docker compose -f docker-compose.testing.common.yml -f docker-compose.testing.${{ matrix.dbms }}.yml config > docker-compose.yml
2021-08-17 00:09:27 +02:00
- name : Start containers
2023-01-23 23:26:17 +01:00
run : docker compose up -d
2021-09-02 20:44:26 +02:00
- name : Wait until www container is ready
# The www-container-fs-ready file is only created once we expect the containers to be online
2020-11-26 18:13:09 +01:00
# so waiting for that lets us know it is safe to start the tests
2021-09-02 20:44:26 +02:00
run : until [ -f ./www/www-container-fs-ready ]; do sleep 0.1; done
2020-08-18 14:40:41 +02:00
- name : Run PHPUnit tests
2023-01-23 23:26:17 +01:00
run : docker compose exec -u www-data -T www paratest -vv --processes=${{ matrix.processes }} /opt/drupal/web/profiles/farm
2021-03-08 16:34:51 +01:00
- name : Test Drush site install with all modules
2023-01-23 23:26:17 +01:00
run : docker compose exec -u www-data -T www drush site-install --db-url=${{ matrix.DB_URL }} farm farm.modules='all'
2022-04-08 03:37:35 +02:00
release :
name : Create GitHub release
if : github.event_name == 'push' && github.ref_type == 'tag'
runs-on : ubuntu-latest
needs :
- build
- sniff
- test
steps :
- name : Set FARMOS_VERSION from previous output.
run : echo "FARMOS_VERSION=${{ needs.build.outputs.farmos_version }}" >> $GITHUB_ENV
- name : Restore farmOS 2.x Docker image from cache
uses : actions/cache@v3
with :
path : /tmp/farmos-2x.tar
key : farmos-2x-${{ github.run_id }}
- name : Load farmos/farmos:2.x image
run : docker load < /tmp/farmos-2x.tar
- name : Run farmOS Docker container
run : docker run --rm -v /tmp/farmOS:/opt/drupal farmos/farmos:2.x true
- name : Create artifact
run : cd /tmp && tar -czf farmOS-${FARMOS_VERSION}.tar.gz farmOS
- name : Create GitHub release
2023-03-16 16:20:30 +01:00
uses : softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 #0.1.15
2022-04-08 03:37:35 +02:00
with :
body : |
For full release notes, see [CHANGELOG.md](https://github.com/farmOS/farmOS/blob/${{ env.FARMOS_VERSION }}/CHANGELOG.md).
files : /tmp/farmOS-${{ env.FARMOS_VERSION }}.tar.gz
draft : false
prerelease : false
2022-04-08 16:56:31 +02:00
publish :
name : Publish to Docker Hub
# We only publish to Docker Hub if this is a tag or 2.x branch push event
# to the official repository.
if : github.repository == 'farmOS/farmOS' && github.event_name == 'push' && (github.ref_type == 'tag' || (github.ref_type == 'branch' && needs.build.outputs.farmos_version == '2.x'))
runs-on : ubuntu-latest
needs :
- build
- sniff
- test
steps :
- name : Set FARMOS_VERSION from previous output.
run : echo "FARMOS_VERSION=${{ needs.build.outputs.farmos_version }}" >> $GITHUB_ENV
- name : Restore farmOS 2.x Docker image from cache
uses : actions/cache@v3
with :
path : /tmp/farmos-2x.tar
key : farmos-2x-${{ github.run_id }}
- name : Load farmos/farmos:2.x image
run : docker load < /tmp/farmos-2x.tar
- name : Restore farmOS 2.x-dev Docker image from cache
uses : actions/cache@v3
with :
path : /tmp/farmos-2x-dev.tar
key : farmos-2x-dev-${{ github.run_id }}
- name : Load farmos/farmos:2.x-dev image
run : docker load < /tmp/farmos-2x-dev.tar
- name : Login to Docker Hub.
2022-11-26 15:02:48 +01:00
uses : docker/login-action@v2
2022-04-08 16:56:31 +02:00
with :
username : ${{ secrets.DOCKER_USERNAME }}
password : ${{ secrets.DOCKER_PASSWORD }}
# If the 2.x branch was pushed...
- name : Publish farmos/farmos:2.x image to Docker Hub.
if : github.ref_type == 'branch' && env.FARMOS_VERSION == '2.x'
run : docker push farmos/farmos:2.x
- name : Publish farmos/farmos:2.x-dev image to Docker Hub.
if : github.ref_type == 'branch' && env.FARMOS_VERSION == '2.x'
run : docker push farmos/farmos:2.x-dev
# If a tag was pushed, tag the Docker image and push to Docker Hub.
# If the tag is a valid semantic versioning string, also tag "latest".
# Semver regex from https://github.com/semver/semver/issues/199#issuecomment-43640395
2022-11-13 20:54:28 +01:00
# If "latest" is tagged, we will also announce the release in a followup job.
2022-04-08 16:56:31 +02:00
- name : Tag and publish farmos/farmos:{tag} image to Docker Hub.
if : github.ref_type == 'tag'
run : |
docker tag farmos/farmos:2.x farmos/farmos:${{ env.FARMOS_VERSION }}
docker push farmos/farmos:${{ env.FARMOS_VERSION }}
if echo ${{ env.FARMOS_VERSION }} | grep -Pq '^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then
docker tag farmos/farmos:2.x farmos/farmos:latest
docker push farmos/farmos:latest
2022-11-13 20:54:28 +01:00
echo "ANNOUNCE_RELEASE=1" >> $GITHUB_ENV
else
echo "ANNOUNCE_RELEASE=0" >> $GITHUB_ENV
2022-04-08 16:56:31 +02:00
fi
2022-11-13 20:54:28 +01:00
outputs :
announce : ${{ env.ANNOUNCE_RELEASE }}
announce :
name : Announce new release
if : needs.publish.outputs.announce
runs-on : ubuntu-latest
needs :
- build
- release
- publish
steps :
- name : Set FARMOS_VERSION from previous output.
run : echo "FARMOS_VERSION=${{ needs.build.outputs.farmos_version }}" >> $GITHUB_ENV
- name : Checkout the farmOS-microblog repository
uses : actions/checkout@v3
with :
repository : farmOS/farmOS-microblog
ssh-key : ${{ secrets.MICROBLOG_DEPLOY_KEY }}
- name : Configure Git.
run : |
git config --global user.name 'farmOS'
git config --global user.email 'noreply@farmOS.org'
- name : Commit/push to farmOS-microblog.
run : |
git commit --allow-empty --cleanup=whitespace -m '#farmOS ${{ env.FARMOS_VERSION }} has been released! https://github.com/farmOS/farmOS/releases/${{ env.FARMOS_VERSION }}'
git push origin main