|
| 1 | +# Secrets |
| 2 | + |
| 3 | +To publish to [Sonatype/Maven Central](https://central.sonatype.org/) you must obtain and install the following secrets on your repository: |
| 4 | + |
| 5 | +- `SONATYPE_USERNAME` and `SONATYPE_PASSWORD` |
| 6 | +- `PGP_SECRET` |
| 7 | + |
| 8 | +Note that `PGP_PASSPHRASE` is not required for publishing with **sbt-typelevel**, although it is supported if you already have a passphrase-protected key. |
| 9 | + |
| 10 | +The instructions provided here are adapted from [sbt/sbt-ci-release](https://github.com/sbt/sbt-ci-release/blob/9625d103cfe9fc0f727ee7903957acdf3ef85fcf/readme.md#sonatype) and [@SystemFw/base.g8 |
| 11 | +](https://github.com/SystemFw/base.g8/blob/6319421465450cd6033a92f9ade5c6fe1feafdb6/src/main/g8/dev-flow.md#ci-setup). |
| 12 | + |
| 13 | +## Sonatype Credentials |
| 14 | + |
| 15 | +If this is your first time publishing, first follow the [Initial Setup](https://central.sonatype.org/publish/publish-guide/#initial-setup) directions in Sonatype's [Publishing Guide](https://central.sonatype.org/publish/publish-guide/) to create an account and request publishing rights for your domain name. If you do not have a domain, you may use `io.github.your_gh_handle` as your **Group Id**. |
| 16 | + |
| 17 | +After you've been granted publishing rights for your domain, log in to either: |
| 18 | + |
| 19 | +- https://s01.oss.sonatype.org (all newly-registered domains) |
| 20 | +- https://oss.sonatype.org (domains registered before February 2021) |
| 21 | + |
| 22 | +Then: |
| 23 | + |
| 24 | +1. Click your username in the top right, then click **Profile** |
| 25 | +2. In the drop-down menu in the top left, select **User Token** |
| 26 | +3. Click the **Access User Token** button to obtain your Sonatype credentials |
| 27 | +4. Set these as the `SONATYPE_USERNAME` and `SONATYPE_PASSWORD` secrets on your repository |
| 28 | + |
| 29 | +## PGP Key |
| 30 | + |
| 31 | +[Sonatype requires](https://central.sonatype.org/publish/requirements/#sign-files-with-gpgpgp) that all artifacts published to Central are cryptographically signed. **sbt-typelevel** automatically signs your artifacts in CI during publishing but you must provide a secret key. |
| 32 | + |
| 33 | +### Option 1: Generate a key pair in your browser |
| 34 | + |
| 35 | +You can use the following form to easily generate a key pair locally in your browser with [OpenPGP.js](https://github.com/openpgpjs/openpgpjs). |
| 36 | + |
| 37 | +<div> |
| 38 | + < script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/openpgp.min.js"></ script> |
| 39 | + <script type="text/javascript"> |
| 40 | + async function tlGenerateKey() { |
| 41 | + const project = document.getElementById('project').value |
| 42 | + const email = document.getElementById('email').value |
| 43 | + const { publicKey, privateKey } = await openpgp.generateKey({ |
| 44 | + userIDs: [{ name: `${project} bot`, email }] |
| 45 | + }); |
| 46 | + document.getElementById('publicKey').value = publicKey; |
| 47 | + document.getElementById('privateKey').value = btoa(privateKey); |
| 48 | + } |
| 49 | + </script> |
| 50 | + |
| 51 | + <label for="project"><b>Your project name:</b></label><br/> |
| 52 | + <input type="text" id="project" name="project" size="64"/><br/> |
| 53 | + <label for="email"><b>Your email:</b></label><br/> |
| 54 | + <input type="text" id="email" name="email" size="64"/><br/> |
| 55 | + <button onClick="tlGenerateKey()">Generate Key</button> |
| 56 | + |
| 57 | +</div> |
| 58 | + |
| 59 | +#### Public key |
| 60 | + |
| 61 | +Copy-paste and submit your public key to the [Ubuntu key server](https://keyserver.ubuntu.com/). |
| 62 | + |
| 63 | +<textarea id="publicKey" readonly rows="16" cols="64" style="resize: none;"></textarea> |
| 64 | + |
| 65 | +#### Private key |
| 66 | + |
| 67 | +Copy-paste and set your private key as the `PGP_SECRET` in your repository secrets. |
| 68 | + |
| 69 | +<textarea id="privateKey" readonly rows="16" cols="64" style="resize: none;"></textarea> |
| 70 | + |
| 71 | +That's it! |
| 72 | + |
| 73 | +### Option 2: Generate a key pair using GPG |
| 74 | + |
| 75 | +First, follow the directions provided by [Sonatype](https://central.sonatype.org/publish/requirements/gpg/) to generate a key pair and submit the public key to a key server. |
| 76 | + |
| 77 | +Then, export your secret key with the following command and set it as the `PGP_SECRET` repository secret. |
| 78 | +``` |
| 79 | +gpg --armor --export-secret-keys $LONG_ID | base64 |
| 80 | +``` |
| 81 | +If your key is passphrase-protected, you should also set the `PGP_PASSPHRASE` secret. |
0 commit comments