Skip to content
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
104 changes: 104 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: e2e

on:
pull_request:
paths-ignore:
- "**.md"
- "docs/**"
schedule:
# Mondays at 06:00 UTC
- cron: "0 6 * * 1"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: e2e-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
playwright:
name: Playwright against GitLab CE
runs-on: ubuntu-latest
# GitLab's first boot alone takes several minutes.
timeout-minutes: 60
defaults:
run:
shell: bash
env:
E2E_DIR: e2e/playwright
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: |
webapp/package-lock.json
e2e/playwright/package-lock.json

# The browser and the containers share these names.
- name: Map E2E hostnames
run: echo "127.0.0.1 mattermost gitlab.test" | sudo tee -a /etc/hosts

# Runs in the background so GitLab's boot overlaps with the plugin build.
- name: Start Mattermost, GitLab, and the runner
run: |
(make e2e-env-up > "$RUNNER_TEMP/server-up.log" 2>&1; echo $? > "$RUNNER_TEMP/server-up.exit") &

- name: Build the plugin bundle
run: make dist

- name: Install E2E dependencies
run: |
cd "$E2E_DIR"
npm ci
npx playwright install --with-deps chromium

- name: Type-check the suite
run: |
cd "$E2E_DIR"
npm run tsc

- name: Wait for the servers to be healthy
timeout-minutes: 20
run: |
while [ ! -f "$RUNNER_TEMP/server-up.exit" ]; do sleep 5; done
cat "$RUNNER_TEMP/server-up.log"
exit "$(cat "$RUNNER_TEMP/server-up.exit")"

- name: Run the suite
run: |
cd "$E2E_DIR"
npm test

- name: Collect container logs
if: failure()
run: |
cd "$E2E_DIR"
mkdir -p results
docker compose ps -a > results/containers.txt
docker compose logs --no-color > results/containers.log

- name: Upload results
if: failure() || cancelled()
uses: actions/upload-artifact@v4
with:
name: e2e-results-${{ github.run_id }}-${{ github.run_attempt }}
path: e2e/playwright/results
retention-days: 14

- name: Stop the servers
if: always()
run: make e2e-env-down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Team members can stay up-to-date with how many reviews, todos, assigned issues,
## Development

This plugin contains both a server and web app portion. Read our documentation about the [Developer Workflow](https://developers.mattermost.com/integrate/plugins/developer-workflow/) and [Developer Setup](https://developers.mattermost.com/integrate/plugins/developer-setup/) for more information about developing and extending plugins.

### Playwright e2e tests

Setup and commands are documented in [e2e/playwright/README.md](e2e/playwright/README.md). From the repo root, `make e2e-env-up` starts Mattermost and GitLab, and `make e2e` runs the suite.

## Help wanted!

Expand Down
22 changes: 22 additions & 0 deletions build/custom.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Include custom targets and environment variables here

E2E_DIR = e2e/playwright

$(E2E_DIR)/node_modules: $(E2E_DIR)/package.json $(E2E_DIR)/package-lock.json
cd $(E2E_DIR) && npm ci && npx playwright install chromium
touch $@

## Starts the disposable Mattermost and GitLab servers used by the E2E suite.
.PHONY: e2e-env-up
e2e-env-up:
$(E2E_DIR)/scripts/ensure-hosts.sh
cd $(E2E_DIR) && docker compose up -d --wait

## Stops the E2E servers and wipes their data.
.PHONY: e2e-env-down
e2e-env-down:
cd $(E2E_DIR) && docker compose down -v

## Builds the plugin and runs the Playwright E2E suite against PW_BASE_URL (default http://mattermost:8065).
.PHONY: e2e
e2e: dist $(E2E_DIR)/node_modules
cd $(E2E_DIR) && npm run tsc && npm test

## Generates mock golang interfaces for testing
.PHONY: mock
mock:
Expand Down
5 changes: 5 additions & 0 deletions e2e/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
results
.env
storage_state
.gitlab-credentials.json
94 changes: 94 additions & 0 deletions e2e/playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# GitLab plugin E2E tests

Playwright suite that drives the plugin against a disposable Mattermost server and a GitLab Community Edition container. GitLab users, the trusted OAuth application, and webhook settings are created with `gitlab-rails runner`. Groups, projects, issues, and merge requests are created by the specs through the GitLab API.

Built on [`@mattermost/playwright-lib`](https://www.npmjs.com/package/@mattermost/playwright-lib) (fixtures, page objects, and admin bootstrap), so no `mattermost` monorepo checkout is needed.

## Host names

The browser and both containers share two hostnames. Add this line to `/etc/hosts` once:

```text
127.0.0.1 mattermost gitlab.test
```

`scripts/ensure-hosts.sh` checks that both names resolve and prints the line when they do not. It does not edit `/etc/hosts`.

The suite needs Node.js 20 or newer. GitLab needs about 4 GB of RAM. The first boot takes several minutes.

## Running

From the repo root:

```sh
make e2e-env-up # Mattermost 11.11, Postgres, GitLab CE, and a GitLab runner
make e2e # build the plugin bundle, install deps, run the suite
make e2e-env-down # stop and wipe both servers
```

Or from this directory, after `make dist` and `make e2e-env-up`:

```sh
npm ci && npx playwright install chromium
npm test # headless
npm run test:headed # watch the browser
npm run test:ui # Playwright UI mode
npm run show-report # open the last HTML report
```

`global_setup.ts` creates the sysadmin, a single `gitlab-e2e` team (a second team would move the GitLab buttons out of the channel header), and a regular member, `gitlab-e2e-user`, that the specs act as. Only the install wizard and the `/gitlab instance` checks use the sysadmin. Setup then bootstraps GitLab, uploads the newest `dist/*.tar.gz`, and writes the GitLab URL and OAuth credentials into the plugin config. It then runs `/gitlab instance install` and completes the wizard in the GitLab bot DM with the same OAuth application, so `gitlab-e2e` becomes the default instance. The suite is safe to rerun against the same server: the bootstrap recreates the OAuth application and the runner registration, and setup disconnects both Mattermost users and uninstalls the old instance before installing it again. It also closes any issues and merge requests still assigned to or awaiting review from `gitlab-e2e`, and clears its to-dos, so an interrupted run does not skew the sidebar counts. The first test then reconnects through the OAuth popup.

Setup deletes every other team the sysadmin belongs to. It only does so on `http://mattermost:8065` unless `PW_DELETE_OTHER_TEAMS=true` is set.

The bootstrap also creates a personal access token for `gitlab-e2e`. Specs use it to act as the connected user, for example to approve merge requests or clear to-dos. Root performs most GitLab actions so that the connected user receives the DMs.

GitLab Community Edition has no group webhooks, so the group-subscription test adds its webhook on the project inside the group.

### Coverage

| Spec | Covers |
| --- | --- |
| `connect` | OAuth connect and disconnect, and the `disconnect` command |
| `commands` | `help`, `about`, `me`, `instance list`, `connect`, `settings`, `todo`, and usage errors |
| `subscriptions` | Add, list, delete, `unsubscribe`, custom features, validation, permissions, `webhook list` |
| `channel_events` | Issue, merge request, comment, push, tag, and release posts |
| `feature_filters` | Label filters, feature exclusion, confidential issues |
| `dm_notifications` | Assignment, comment, mention, review, approval, merge DMs, and muting with `settings` |
| `notifications` | Project and group subscriptions, plus the assigned issue and merge request lists |
| `sidebar` | Review and to-do lists and counts |
| `post_actions` | Create GitLab issue (incl. label, assignee, and milestone) and attach to issue from the post menu, and `/gitlab issue create` |
| `webapp_integrations` | Link tooltips and the profile popover attribute |
| `pipelines` | `/gitlab pipelines run`, plus pipeline, job, and deployment posts on the runner |
| `permalinks` | Blob permalink code previews (`fixme`, see below) |

`pipelines` includes a `fixme` test for the failed-pipeline DM. The plugin does not deliver that DM to the pipeline author today ([MM-71329](https://mattermost.atlassian.net/browse/MM-71329)).

`permalinks` is a `fixme`: the code-preview feature only recognizes `gitlab.com` permalinks (`gitlabPermalinkRegex` in `server/plugin.go` is anchored to that host) and `EnableCodePreview` defaults to `public`, which skips the suite's private projects. That host restriction is a product bug (code previews never work for self-hosted GitLab) and will be tracked in a separate ticket. Exercising it against the self-hosted `gitlab.test` stack needs the regex to accept the configured host.

### Writing tests

Specs follow the [Mattermost Playwright guidelines](https://github.com/mattermost/mattermost/blob/master/e2e-tests/playwright/CLAUDE.OPTIONAL.md):

- Every test has a JSDoc block with `@objective` (and `@precondition` when the setup is not the default), the `@gitlab_plugin` tag, and `// #` action and `// *` verification comments.
- Specs hold no selectors. Mattermost UI goes through `@mattermost/playwright-lib` page objects, and the plugin's UI through the components in `support/components/` (`GitlabRhs`, `GitlabSidebar`, `CreateIssueModal`, `AttachCommentModal`, `GitlabLinkTooltip`, `GitlabProfileAttribute`).
- Components locate elements by role, label, or text. Test ids are kept only for elements without an accessible name: the header counts, sidebar items, the connected username, subscription rows, and the link tooltip.

### CI

`.github/workflows/e2e.yml` runs the suite on every pull request except those that only change Markdown files or files under `docs/`, weekly on Mondays at 06:00 UTC, and on demand from the Actions tab. It boots the stack on the runner while the plugin builds, then runs the full suite. When a run fails, the Playwright report, traces, and container logs are uploaded as the `e2e-results-*` artifact.

### Environment

| Variable | Default |
| --- | --- |
| `PW_BASE_URL` | `http://mattermost:8065` |
| `PW_ADMIN_USERNAME` / `PW_ADMIN_PASSWORD` | `sysadmin` / `Sys@dmin-sample1` |
| `PW_HEADLESS` | `true` |
| `PW_REGULAR_USER_PASSWORD` | `gitlab-e2e-user`'s password. Required unless `PW_BASE_URL` is `http://mattermost:8065` |
| `PW_DELETE_OTHER_TEAMS` | unset (only deletes other teams on `http://mattermost:8065`) |
| `MM_IMAGE` (docker compose) | `mattermost/mattermost-enterprise-edition:11.11` (release-1.x plugins bundle React 18 or older, so they cannot run on Mattermost 12) |
| `GITLAB_IMAGE` (docker compose) | `gitlab/gitlab-ce:18.11.12-ce.0` |
| `GITLAB_RUNNER_IMAGE` (docker compose) | `gitlab/gitlab-runner:alpine-v18.11.4` |
| `GITLAB_ROOT_PASSWORD` | `Kv7-Qm4n-Wx2p-L9` |

GitLab rejects passwords that contain a predictable word or part of the account name, username, or email. The defaults above avoid that check. The GitLab user the suite connects is `gitlab-e2e`. Its password is printed into `.gitlab-credentials.json` by the bootstrap and is not a secret outside this local stack.
114 changes: 114 additions & 0 deletions e2e/playwright/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Disposable Mattermost and GitLab Community Edition for the plugin E2E suite.
# npm run server:up # start and wait until healthy
# npm run server:down # stop and wipe all data
#
# The host must resolve mattermost and gitlab.test to 127.0.0.1 so the browser
# and the containers share one pair of URLs. scripts/ensure-hosts.sh checks this.
name: gitlab-plugin-e2e

services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: mmuser
POSTGRES_PASSWORD: mostest
POSTGRES_DB: mattermost_test
healthcheck:
test: ["CMD-SHELL", "pg_isready -U mmuser -d mattermost_test"]
interval: 5s
timeout: 5s
retries: 20
networks:
- e2e

mattermost:
# Must satisfy plugin.json's min_server_version. Only amd64 images are
# published; on Apple silicon Docker Desktop runs them under emulation.
image: ${MM_IMAGE:-mattermost/mattermost-enterprise-edition:11.11}
platform: linux/amd64
hostname: mattermost
depends_on:
postgres:
condition: service_healthy
ports:
- "127.0.0.1:8065:8065"
environment:
MM_SQLSETTINGS_DRIVERNAME: postgres
MM_SQLSETTINGS_DATASOURCE: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10
# GitLab delivers webhooks to this name over the Compose network.
MM_SERVICESETTINGS_SITEURL: http://mattermost:8065
MM_SERVICESETTINGS_ENABLEONBOARDINGFLOW: "false"
MM_SERVICESETTINGS_ENABLETUTORIAL: "false"
MM_SERVICESETTINGS_ENABLESECURITYFIXALERT: "false"
MM_PLUGINSETTINGS_ENABLE: "true"
MM_PLUGINSETTINGS_ENABLEUPLOADS: "true"
MM_PLUGINSETTINGS_AUTOMATICPREPACKAGEDPLUGINS: "false"
MM_RATELIMITSETTINGS_ENABLE: "false"
MM_ANNOUNCEMENTSETTINGS_ADMINNOTICESENABLED: "false"
MM_ANNOUNCEMENTSETTINGS_USERNOTICESENABLED: "false"
MM_LOGSETTINGS_CONSOLELEVEL: INFO
# The image is distroless (no shell/curl), so the healthcheck pings the
# server through mmctl over the local-mode socket.
MM_SERVICESETTINGS_ENABLELOCALMODE: "true"
healthcheck:
test: ["CMD", "/mattermost/bin/mmctl", "--local", "system", "status"]
interval: 5s
timeout: 10s
retries: 60
start_period: 20s
networks:
e2e:
aliases:
- mattermost

gitlab:
image: ${GITLAB_IMAGE:-gitlab/gitlab-ce:18.11.12-ce.0}
hostname: gitlab.test
shm_size: "256m"
depends_on:
mattermost:
condition: service_healthy
ports:
- "127.0.0.1:8929:8929"
environment:
# GitLab rejects weak passwords: no predictable words, and nothing from the
# root user's name, username, or email (root, admin, example).
GITLAB_ROOT_PASSWORD: ${GITLAB_ROOT_PASSWORD:-Kv7-Qm4n-Wx2p-L9}
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.test:8929'
nginx['listen_https'] = false
letsencrypt['enable'] = false
prometheus_monitoring['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
gitlab_exporter['enable'] = false
puma['worker_processes'] = 0
sidekiq['max_concurrency'] = 5
gitlab_kas['enable'] = false
registry['enable'] = false
gitlab_pages['enable'] = false
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:8929/-/readiness"]
interval: 20s
timeout: 10s
retries: 30
start_period: 300s
networks:
e2e:
aliases:
- gitlab.test

# Runs CI jobs for the pipeline, job, and deployment specs. Global setup
# registers it against GitLab with a shell executor.
gitlab-runner:
image: ${GITLAB_RUNNER_IMAGE:-gitlab/gitlab-runner:alpine-v18.11.4}
depends_on:
gitlab:
condition: service_healthy
networks:
- e2e

networks:
e2e: {}
13 changes: 13 additions & 0 deletions e2e/playwright/global_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import './support/env';

import {baseGlobalSetup} from '@mattermost/playwright-lib';

import {prepareServer} from './support/plugin';

export default async function globalSetup() {
await baseGlobalSetup();
await prepareServer();
}
Loading
Loading