Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial playwright integration #120

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Note: this is a dummy env file for CI, do not modify or use it until you know what you're doing
PORT=8000
MW_SITE_SERVER=http://localhost:8000
MW_SITE_NAME=MyWiki
MW_SITE_LANG=en
MW_ENABLE_UPLOADS=1
MW_USE_INSTANT_COMMONS=0
MW_AUTOUPDATE=true
MW_MAIN_CACHE_TYPE=CACHE_NONE
MW_LOAD_SKINS=Vector
MW_DEFAULT_SKIN=vector
MW_LOAD_EXTENSIONS=ParserFunctions
MW_USE_CACHE_DIRECTORY=
MW_SHOW_EXCEPTION_DETAILS=true
MW_USE_IMAGE_MAGIC=
MW_MEMCACHED_SERVERS=
MW_PROXY_SERVERS=
MW_FLOW_NAMESPACES=
MW_ENABLE_SITEMAP_GENERATOR=


MW_ADMIN_USER=admin
MW_ADMIN_PASS=rand0mmysqlpassw0rd1!

MW_DB_INSTALLDB_PASS=mediawiki
MW_DB_TYPE=mysql

MW_DB_NAME=mediawiki
MW_DB_PASS=mediawiki
MW_SECRET_KEY=jf843y8973098waujda9odu89seyf9s4fy98sof49gyh47e3w9yhf9os

MW_ENABLE_EMAIL=false
MW_ENABLE_USER_EMAIL=false
MW_EMERGENCY_CONTACT=apache@invalid
MW_PASSWORD_SENDER=apache@invalid
180 changes: 160 additions & 20 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,37 @@ env:
IMAGE_NAME: taqasta

jobs:
# Test the image Dockerfile syntax using https://github.com/replicatedhq/dockerfilelint
test:
# Lint the image Dockerfile syntax using https://github.com/replicatedhq/dockerfilelint
lint:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
-
name: Run linter (hadolint)
uses: vedmaka/hadolint-action@master
with:
dockerfile: "Dockerfile"
config: "hadolint.yaml"

# Push image to GitHub Packages.
# Generate image tags
# The image tag pattern is:
# for pull-requests: <MW_CORE_VERSION>-<DATE>-<PR_NUMBER>, eg: 1.35.2-20210125-25
# for tags: <TAG>
# for `master` branch: latest + <MW_VERSION>-latest + <MW_CORE_VERSION>-<DATE>-<SHA>
# <MW_CORE_VERSION> being parsed from the Dockerfile
push:
needs: [test]
tags:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
outputs:
REGISTRY_TAGS: ${{ steps.generate.outputs.REGISTRY_TAGS }}
REGISTRY_TAGS_VERSION: ${{ steps.generate.outputs.REGISTRY_TAGS_VERSION }}
REGISTRY_TAGS_PR_NUMBER: ${{ steps.generate.outputs.REGISTRY_TAGS_PR_NUMBER }}
SHA_SHORT: ${{ steps.generate.outputs.SHA_SHORT }}
steps:
- name: Checkout
uses: actions/checkout@v3
-
name: Generate tags
uses: actions/checkout@v4
- name: Generate tags
id: generate
run: |

Expand All @@ -67,7 +70,7 @@ jobs:

# Strip git ref prefix from version and use it as suffix for version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# Get the Taqasta version from the "VERSION" file
TAQASTA_VERSION=$(cat VERSION)

Expand All @@ -93,26 +96,139 @@ jobs:

SHA_SHORT=${{ github.sha }}
[ "${{ github.event_name }}" == "pull_request" ] && SHA_SHORT=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo REGISTRY_TAGS=$REGISTRY_TAGS
echo SHA_SHORT=$SHA_SHORT
echo EventName=${{ github.event_name }}

echo headref=${{ github.head_ref }}
echo "Final image tag to be pushed:"
echo $REGISTRY_TAGS
echo "REGISTRY_TAGS=$REGISTRY_TAGS" >> $GITHUB_OUTPUT
echo "REGISTRY_TAGS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "REGISTRY_TAGS_PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "SHA_SHORT=$SHA_SHORT" >> $GITHUB_OUTPUT

# Pre-build the image, deploy via compose and run e2e
deploy-e2e:
needs: [tags]
timeout-minutes: 60
outputs:
pages_url: ${{ steps.deployment_pages.outputs.page_url }}
# services:
# registry:
# image: registry:2
# ports:
# - 5000:5000
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

# We could perform the build in a separate job, but why for? let's save some bandwidth on caches
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
secrets: |
COMPOSER_TOKEN=${{ secrets.GITHUB_TOKEN }}
push: false
tags: ${{ needs.tags.outputs.REGISTRY_TAGS }}
cache-from: type=gha
cache-to: type=gha,mode=max
load: true

- name: Setup Docker Compose
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_BUILDKIT: 1
shell: bash
run: DOCKER_BUILDKIT=1 docker compose up -d

- name: Give containers a moment to init
shell: bash
run: sleep 30s

- name: Wait for init
shell: bash
run: while ! docker compose logs web --tail 10 | grep -q '>>>>> run-maintenance-script.sh <<<<<'; do sleep 2; done

- name: Wait for apache
shell: bash
run: curl --head -X GET --retry 10 --retry-connrefused --retry-delay 10 http://localhost:8000

# todo, migrate to docker image? https://playwright.dev/docs/docker
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
working-directory: ./e2e
run: npm ci
- name: Install Playwright Browsers
working-directory: ./e2e
run: npx playwright install chromium --with-deps
- name: Run Playwright tests
working-directory: ./e2e
run: npx playwright test
# - uses: actions/upload-artifact@v3
# if: failure()
# with:
# name: playwright-report
# path: e2e/playwright-report/
# retention-days: 7

- name: Upload screenshots as a github-pages artifact
uses: actions/upload-pages-artifact@v2
if: failure()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 7
if-no-files-found: error

- name: Stop containers
if: always()
shell: bash
run: docker-compose down --volumes --timeout 60

# Builds from cache & push the image to GitHub registry this time
push:
needs: [tags,deploy-e2e]
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.docker_build.outputs.digest }}
imageid: ${{ steps.docker_build.outputs.imageid }}
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
install: true
-
Expand All @@ -133,32 +249,56 @@ jobs:
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64, linux/arm64
secrets: |
COMPOSER_TOKEN=${{ secrets.GITHUB_TOKEN }}
push: true
tags: ${{ steps.generate.outputs.REGISTRY_TAGS }}
tags: ${{ needs.tags.outputs.REGISTRY_TAGS }}
cache-from: type=gha
cache-to: type=gha,mode=max
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Image tags debug
run: echo ${{ steps.generate.outputs.REGISTRY_TAGS }}
run: echo ${{ needs.tags.outputs.REGISTRY_TAGS }}

# Send a message to the PR thread
notify:
needs: [tags,push]
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
-
name: Notify about image tag
if: github.event_name == 'pull_request' && steps.docker_build.outputs.digest != ''
uses: hasura/comment-progress@v2.2.0
if: github.event_name == 'pull_request' && needs.push.outputs.digest != ''
uses: hasura/comment-progress@v2.3.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: comment
message: ":whale: The image based on [${{ steps.generate.outputs.SHA_SHORT }}](https://github.com/WikiTeq/Taqasta/pull/${{ steps.generate.outputs.REGISTRY_TAGS_PR_NUMBER }}/commits/${{ github.event.pull_request.head.sha }}) commit has been built with `${{ steps.generate.outputs.REGISTRY_TAGS_VERSION }}` tag as [${{ steps.generate.outputs.REGISTRY_TAGS }}](https://github.com/${{ github.repository }}/pkgs/container/${{ env.IMAGE_NAME }}/${{ steps.docker_build.outputs.imageid }}?tag=${{ steps.generate.outputs.REGISTRY_TAGS_VERSION }})"
message: ":whale: The image based on [${{ needs.tags.outputs.SHA_SHORT }}](https://github.com/WikiTeq/Taqasta/pull/${{ needs.tags.outputs.REGISTRY_TAGS_PR_NUMBER }}/commits/${{ github.event.pull_request.head.sha }}) commit has been built with `${{ needs.tags.outputs.REGISTRY_TAGS_VERSION }}` tag as [${{ needs.tags.outputs.REGISTRY_TAGS }}](https://github.com/${{ github.repository }}/pkgs/container/${{ env.IMAGE_NAME }}/${{ needs.push.outputs.imageid }}?tag=${{ needs.tags.outputs.REGISTRY_TAGS_VERSION }})"
recreate: true
fail: false

report-pages:
needs: [deploy-e2e]
runs-on: ubuntu-latest
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
environment:
name: github-pages
url: ${{ steps.deployment_pages.outputs.page_url }}
if: failure() && ( github.event_name == 'push' || github.event_name == 'pull_request' )
steps:
- name: Deploy to GitHub Pages
id: deployment_pages
uses: actions/deploy-pages@v2
with:
artifact_name: playwright-report
token: ${{ secrets.GITHUB_TOKEN }}
72 changes: 72 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# # Note: this is a dummy Compose file for CI, do not modify or use it until you know what you're doing
version: '3.1'
services:
db:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password --expire_logs_days=3
cap_add:
- SYS_NICE # CAP_SYS_NICE, fix error mbind: Operation not permitted
restart: unless-stopped
environment:
- MYSQL_ROOT_HOST=%
- MYSQL_ROOT_PASSWORD=${MW_DB_INSTALLDB_PASS:-mediawiki}
- MYSQL_DATABASE=${MW_DB_NAME:-mediawiki}
volumes:
- initdb:/docker-entrypoint-initdb.d
- mysql:/var/lib/mysql

web:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "${PORT:-127.0.0.1:8000}:80"
links:
- db
env_file:
- .env.ci
environment:
- MW_ADMIN_USER=${MW_ADMIN_USER:-admin}
- MW_ADMIN_PASS=${MW_ADMIN_PASS:-Passsw0rd!}
- MW_DB_NAME=${MW_DB_NAME:-mediawiki}
- MW_DB_INSTALLDB_USER=root
- MW_DB_INSTALLDB_PASS=${MW_DB_INSTALLDB_PASS:-mediawiki}
- MW_DB_USER=root
- MW_DB_PASS=${MW_DB_PASS:-mediawiki}
- MW_SECRET_KEY
- MW_SITE_SERVER
- MW_SITE_NAME
- MW_SITE_LANG
- MW_ENABLE_UPLOADS
- MW_USE_INSTANT_COMMONS
- MW_AUTOUPDATE
- MW_MAIN_CACHE_TYPE
- MW_LOAD_SKINS=${MW_LOAD_SKINS:-Vector,chameleon}
- MW_DEFAULT_SKIN=${MW_DEFAULT_SKIN:-chameleon}
- MW_LOAD_EXTENSIONS=${MW_LOAD_EXTENSIONS:-ParserFunctions,WikiEditor}
- MW_ENABLE_EMAIL
- MW_ENABLE_USER_EMAIL
- MW_EMERGENCY_CONTACT
- MW_PASSWORD_SENDER
- MW_DB_TYPE=${MW_DB_TYPE:-mysql}
- MW_USE_CACHE_DIRECTORY
- MW_SHOW_EXCEPTION_DETAILS
- MW_MEMCACHED_SERVERS
- MW_PROXY_SERVERS
- MW_FLOW_NAMESPACES
- MW_SEARCH_TYPE
- MW_ENABLE_SITEMAP_GENERATOR
- MW_CIRRUS_SEARCH_SERVERS
- PHP_UPLOAD_MAX_FILESIZE=500M
- PHP_POST_MAX_SIZE=500M
- MW_DEBUG_MODE
volumes:
- mediawiki:/mediawiki
- settings:/var/www/mediawiki/w/_settings

volumes:
mediawiki:
mysql:
initdb:
settings:
5 changes: 5 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Loading
Loading