- From
- Joe Hahn
- Date
- Read
- 12 min
I published my first module to drupal.org this week. The code had been ready for days; the publishing took a day on its own, almost entirely on things nobody tells you and that are obvious in hindsight.
This is the path written down in order, with the traps marked. It assumes you have a working module and a DDEV setup, and want it installable by other people via Composer.
Step 0: read the GitLab templates documentation
Before you write a line of CI config, before you create the project, before anything: go and read project.pages.drupalcode.org/gitlab_templates. Bookmark it. It is thirty minutes that will save you a day.
I did not, and everything else in this post is downstream of that. drupal.org's CI for contributed projects is driven by a shared, versioned, thoroughly documented set of GitLab templates, and the site has:
- a page for every job — Composer, PHPCS, PHPStan, PHPUnit, ESLint, Stylelint, CSpell, Nightwatch — saying what it runs and how to make it pass
- a customisations page listing every variable you are allowed to set, and which are deprecated
- a "Test locally" page describing how to run the whole pipeline on your own machine
I hand-wrote my .gitlab-ci.yml instead, inferring what the variables probably did. One of my guesses
was a deprecated variable that silently installed the wrong Drupal core, which produced thirty-eight
errors across two jobs that looked like bugs in my own code. Every minute spent debugging that was a
minute the customisations page would have given back.
There is a special sting to it: when the CSpell job failed, its log printed a link to those very docs. I read past it three times.
So: read the docs first. The rest of this post is the path I took the hard way, with the traps marked.
Step 1: set up local CI
drupal.org runs eight CI jobs against your project, and all eight can run on your machine before you push. The tool the documentation recommends is ddev-drupal-contrib, which assembles a whole Drupal site around your module so the same checks can run against it.
Your module must be at the repository root for this — not nested in web/modules/custom. If you
have been developing inside a full site, the module needs its own repo. Then:
$ ddev config --project-type=drupal11 --docroot=web
$ ddev add-on get ddev/ddev-drupal-contrib
$ ddev start
$ ddev poser # installs core as a dev dependency
$ ddev symlink-project # links your module into the assembled site
$ ddev exec "cd web/core && yarn install"
That last line is not optional and not in the quickstart. Core's frontend tooling needs Yarn.
Running npm ci in web/core exits 0 and installs nothing, leaving node_modules/.bin empty and
ESLint and Stylelint silently unavailable — an exit code of zero that means "I did nothing".
Now you have:
$ ddev phpcs $ ddev phpstan $ ddev phpunit
$ ddev eslint $ ddev stylelint
Two operational notes. Re-run ddev symlink-project whenever you add a file to the module root, or
the assembled site never sees it. And everything the add-on generates — web/, recipes/, vendor/,
.ddev/, .prettierrc.json, phpcs.xml.dist, phpstan-baseline.neon — must be gitignored.
phpstan-baseline.neon especially: committing a baseline suppresses exactly the errors the pipeline
exists to report.
The harness paid for itself on its first run for me. It caught a test loading a file by a hardcoded path:
require_once $this->root . '/modules/custom/petrichor/modules/petrichor_wiki/petrichor_wiki.install';
That passes on exactly one layout — drupal.org's CI, where the project folder happens to be named after the module. The local harness symlinks it under a different name, so four tests failed instantly. Resolve module paths through the extension list instead:
$path = $this->container->get('extension.list.module')->getPath('petrichor_wiki');
require_once $this->root . '/' . $path . '/petrichor_wiki.install';
Step 2: pick your core version honestly
core_version_requirement in your .info.yml is a promise, and it is easy to make a wrong one.
If you declare entity types with PHP attributes rather than the old annotations — which you should, since annotations are removed in Drupal 13 — then:
#[ContentEntityType(
id: 'petrichor_task',
label: new TranslatableMarkup('Task'),
// ...
)]
class Task extends PetrichorEntityBase {}
Drupal\Core\Entity\Attribute\ContentEntityType does not exist before Drupal 11.1.0. I said ^11,
which was false, and only found out because a CI misconfiguration installed 11.0.0 and every entity type
in the suite silently failed to register.
You can check any core API against core's own tags rather than trusting memory:
$ for ref in 11.0.0 11.1.0; do
printf '%s ' $ref
curl -s -o /dev/null -w '%{http_code}\n' \
"https://git.drupalcode.org/api/v4/projects/project%2Fdrupal/repository/files/core%2Flib%2FDrupal%2FCore%2FEntity%2FAttribute%2FContentEntityType.php?ref=$ref"
done
11.0.0 404
11.1.0 200
Step 3: the packaging files
Six files at the module root. None are large; several are easy to get subtly wrong.
composer.json — this is how a consumer gets your dependencies. Mine declares
league/commonmark, and the constraint had previously lived only in my site's root
composer.json — a file nobody installing the module ever sees. composer require drupal/petrichor
would have installed no CommonMark and fataled on enable.
{
"name": "drupal/petrichor",
"description": "...",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=8.3",
"league/commonmark": "^2.6"
},
"suggest": {
"drupal/key_auth": "Per-agent API keys for the MCP endpoint."
}
}
Do not require drupal/core here; core_version_requirement in .info.yml handles that.
.gitlab-ci.yml — include the shared templates and set as little as possible:
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
variables:
_TARGET_PHP: "8.3"
Do not set _TARGET_CORE. It is deprecated, and "11" is not read as "the 11 branch" — it is read
as core 11.0.0. That single line cost me nine PHPStan errors and twenty-nine PHPUnit errors that
looked like two unrelated regressions in my own code. Left unset, DRUPAL_CORE defaults to
$CORE_STABLE, which is what you want.
phpstan.neon — ship one so the level you are held to lives in your repo, reviewable, rather than
being whatever the runner defaults to:
parameters:
level: 1
paths:
- .
excludePaths:
analyseAndScan:
- vendor (?)
- node_modules (?)
The (?) suffix is not optional. Those directories do not exist in a clean checkout, and PHPStan
treats excluding a non-existent path as a config error — it exits 1 before analysing a single line,
which in a CI summary reads as "PHPStan found problems".
.cspell.json — the spell-check job will flag your domain vocabulary and, if you write British
English, half your comments:
{
"version": "0.2",
"language": "en,en-GB",
"words": ["petrichor", "commonmark", "worklog", "backlinks"],
"ignoreRegExpList": ["/[A-Za-z0-9_+/-]{24,}={0,2}/"]
}
That regex matters more than the word list: it ignores base64-ish tokens, so the UUID hashes inside your exported config YAML stop tripping the job — that one and every future one.
.prettierignore containing *.yml. CI creates this itself when absent, so committing it changes
nothing there. It matters locally: ddev-drupal-contrib writes its copy at the repo root then runs
ESLint from inside the module directory, where Prettier cannot see it — so without this the local run
flags every config YAML and disagrees with a CI run that is passing. A harness that disagrees with CI
is worse than no harness.
.gitignore for /vendor/ and everything the add-on generates.
And two files not to commit: no LICENSE (drupal.org adds GPL-2.0-or-later at packaging time)
and no version, project or datestamp keys in any .info.yml (the packaging system supplies
them; committing them is an error).
Step 4: git access, and the two hostnames
Agree to the Git terms on your drupal.org profile, then add an SSH key — in the GitLab UI, at
git.drupalcode.org → Preferences → SSH Keys. The field that used to be on your drupal.org profile is
gone, with nothing where it was to say so.
Then the part that will waste your afternoon if you let it:
$ ssh -T git@git.drupalcode.org
ssh: connect to host git.drupalcode.org port 22: Connection timed out
git.drupalcode.org sits behind Fastly, which serves HTTP and does not carry SSH. SSH terminates
on git.drupal.org. Web and HTTPS are on git.drupalcode.org. Two hostnames, one word apart in the
part your eye skips over.
Rather than trust me, ask GitLab what it advertises for any project:
$ curl -s "https://git.drupalcode.org/api/v4/projects/project%2Ftoken" \
| jq '{ssh: .ssh_url_to_repo, http: .http_url_to_repo}'
{
"ssh": "git@git.drupal.org:project/token.git",
"http": "https://git.drupalcode.org/project/token.git"
}
ssh_url_to_repo comes from the same config that serves the connection, which is a stronger guarantee
than documentation.
Step 5: create the project
On drupal.org, add a Module project. Two fields are effectively permanent and the rest you can edit forever:
- Short name — becomes both
drupal.org/project/<name>and the git path. Choose carefully. - Project type — a second dropdown that appears after you have already chosen "Module project", which reads like a redundant confirmation and is not. It decides whether your project can ever cut a real release. Take Full project, not Sandbox.
The rest — maintenance status, categories, components, resources — is all editable later. Leave the Resources tab empty until the repo exists; a link that 404s reads as abandoned rather than new.
The description field has a WYSIWYG-looking toolbar but is BUEditor: a plain textarea whose buttons insert literal HTML tags. Paste HTML, use Preview to confirm. It shows raw markup in the box while working correctly, so "fine" and "broken" look identical until you preview.
Step 6: push
Creating the project provisions the repo.
$ git remote add origin git@git.drupal.org:project/<name>.git
$ git push -u origin main
A note on history. If, like me, you extracted the module from a full site repo, start a fresh
history rather than replaying the site's commits. Two reasons beyond tidiness: commits authored with a
GitHub noreply address will not associate with your drupal.org account, so most of your history shows
as an unknown author; and any commit carrying your real email puts it in a permanently public log. Set
the identity locally — not globally, or you retarget your GitHub commits too:
$ git config user.email '<uid>-<name>@users.noreply.drupalcode.org'
That anonymised address still credits your contribution record. drupal.org shows it to you under DrupalCode access.
Then create the release branch. Releases are cut from a branch named for the version, not from main:
$ git checkout -b 1.0.x && git push -u origin 1.0.x
GitLab will offer to open a merge request. Ignore it — you are the maintainer pushing directly, and
main and 1.0.x are identical.
Step 7: cut the release
This part is on drupal.org, not GitLab: project page → Add new release → pick 1.0.x.
Take 1.0.x-dev for a first release. It tracks the branch tip, so you are not making a version
commitment before anyone has used the thing, and you can tag alphas later. Tick "show in the download
table" or it will not appear on your project page.
Development releases get no security advisory coverage — that is a rule, not an oversight, and opting in requires a stable release plus a separate application. Say so in the release notes; someone finding out after deploying is a worse outcome than someone deciding not to.
Then verify rather than assume, because packaging takes a few minutes:
$ ddev composer require "drupal/<name>:1.0.x-dev" --dry-run
- Locking drupal/<name> (dev-1.0.x b1508c8)
When CI fails and you cannot see why
One last thing that cost me three rounds. GitLab's API returns 401 for job traces even on public projects:
$ curl -s -o /dev/null -w '%{http_code}\n' ".../api/v4/projects/project%2F<name>/jobs/<id>/trace"
401
The web route is open:
$ curl -sL -o /dev/null -w '%{http_code}\n' "https://git.drupalcode.org/project/<name>/-/jobs/<id>/raw"
200
Same job, same permissions, different route. Get the log before you reason about the config. Every CI problem I had was explained in one line of a log I had convinced myself I could not read — and the CSpell job log even prints a link to the very documentation that would have prevented the whole exercise.
The short version
- Read https://project.pages.drupalcode.org/gitlab_templates/ first. Every job, every variable, and how to run the lot locally.
- Set up
ddev-drupal-contriband run all eight checks before you push. yarn installinweb/core, not npm.- Ship
composer.json,.gitlab-ci.yml,phpstan.neon(with(?)),.cspell.json,.prettierignore,.gitignore. No LICENSE, noversionkey. - Never set
_TARGET_CORE. - SSH is
git.drupal.org; the web UI isgit.drupalcode.org. - Short name and project type are permanent; everything else is editable.
- Fresh git history, anonymised email, local git config only.
1.0.x-devfirst, and verify it resolves withcomposer require --dry-run.- Read the job log at
/-/jobs/<id>/raw.
The module: Petrichor —
composer require drupal/petrichor:1.0.x-dev. What it is and why I built it is
a separate post.