Set up deployment
CI pushes to your extension's Drupal.org repository with an SSH key. Follow this page to create the key and the repository secrets that turn deployment on. Use a dedicated key for each project, so you can revoke 1 key and keep the others.
Before you start
Make sure you have the following:
- Administrator access to your extension's GitHub repository, to add secrets and variables.
- A Drupal.org account that can push to your extension's repository.
ssh-keygen, which comes with OpenSSH.
Add the SSH key and the secrets
-
Generate a new SSH key:
ssh-keygen -m PEM -t rsa -b 4096 -C "your_email+project_name@example.com"The
-Ccomment only labels the key, so any text you'll recognize works. -
When
ssh-keygenasks where to save the key, it suggestsid_rsain your.sshdirectory. To keep your existing keys, enter a new filename in that directory, such asid_rsa_myextension.ssh-keygenwrites the private key to that file and the public key to the same name with.pubadded. -
Press Enter at both passphrase prompts to leave the passphrase empty. CI can't type a passphrase.
-
Add the public key to the SSH keys of your Drupal.org account, which live on git.drupalcode.org, Drupal.org's GitLab.
-
Add the private key as the
DEPLOY_SSH_KEYsecret in your repository's Settings > Secrets and variables > Actions. Paste the whole file, from its-----BEGINline to its-----ENDline. -
Add these secrets in the same place:
DEPLOY_REMOTE- your extension's Drupal.org repository, such asgit@git.drupal.org:project/myextension.git. Until it's set, theDeployjob reports a notice and skips deployment.DEPLOY_USER_NAME- the git user name on the CI runner, such as your name on Drupal.org. The deployment fails without it. The deployment makes no commits of its own, so this name appears in no commit on Drupal.org.DEPLOY_USER_EMAIL- the git email address on the runner, such as your email address on Drupal.org. The deployment fails without it too.
-
Optional: To push every deployed branch to 1 branch of the
DEPLOY_REMOTErepository, add a repository variable namedDEPLOY_BRANCH, set to that branch's name, such as1.x. Add it under Settings > Secrets and variables > Actions > Variables, since it isn't a secret. Set it only when 1 branch deploys, because several branches would replace each other's code in that 1 destination branch. WithoutDEPLOY_BRANCH, each branch deploys to the branch of the same name. Tags deploy as tags either way.
Confirm that the Actions secrets of your repository list DEPLOY_SSH_KEY, DEPLOY_REMOTE, DEPLOY_USER_NAME and DEPLOY_USER_EMAIL. You add DEPLOY_PROCEED, the secret that turns the push on, after the test in the next section.
Confirm that it works
Until the DEPLOY_PROCEED secret is 1, the Deploy job runs but stops before the push, so you can test it first:
- Push a commit to a branch that deploys, such as
1.x. Watch theDeployworkflow that starts afterTestpasses. The job ends with "Skip deployment because DEPLOY_PROCEED is not set to 1." That message meansDEPLOY_REMOTE,DEPLOY_USER_NAMEandDEPLOY_USER_EMAILare set. The job connects toDEPLOY_REMOTEonly after the next step. - Add the
DEPLOY_PROCEEDsecret, set to1, in the same place as the other secrets. - Push another commit to the branch. After
Testpasses, theDeployjob pushes it, and the commit appears in your Drupal.org repository.
DEPLOY_REMOTE can name any git remote that accepts the key, such as a mirror on another git host.
Next steps
- Deployment - what deploys, and in what order.
- Branch protection - the CI jobs to require before a merge.