|
| 1 | +--- |
| 2 | +name: deploy-to-maven-central |
| 3 | +description: Deploys the library to OSSRH staging and creates a pre-release, but publishing must be done manually via the Sonatype web UI. |
| 4 | +disable-model-invocation: true |
| 5 | +allowed-tools: Bash(*) |
| 6 | +--- |
| 7 | + |
| 8 | +# Deploy to Maven Central (OSSRH Staging) |
| 9 | + |
| 10 | +Deploy both `auth` and `store` flavours of the Android auth library to the OSSRH staging repository, then upload the staged deployment for publishing. |
| 11 | + |
| 12 | +## Steps |
| 13 | + |
| 14 | +### 1. Validate `local.properties` |
| 15 | + |
| 16 | +Check that the file `local.properties` in the project root exists and contains all of the following keys: |
| 17 | + |
| 18 | +- `signing.keyId` |
| 19 | +- `signing.password` |
| 20 | +- `signing.secretKeyRingFile` |
| 21 | +- `ossrhUsername` |
| 22 | +- `ossrhPassword` |
| 23 | + |
| 24 | +If the file is missing or any key is absent, stop and tell the user: |
| 25 | + |
| 26 | +> `local.properties` must contain the following properties: |
| 27 | +> |
| 28 | +> ``` |
| 29 | +> signing.keyId=<gpg signing key> |
| 30 | +> signing.password=<gpg signing password> |
| 31 | +> signing.secretKeyRingFile=<gpg keyring> |
| 32 | +> ossrhUsername=<ossrhUsername> |
| 33 | +> ossrhPassword=<ossrhPassword> |
| 34 | +> ``` |
| 35 | +
|
| 36 | +Extract the values of `ossrhUsername` and `ossrhPassword` from `local.properties` for use in later steps. Store them in shell variables `OSSRH_USER` and `OSSRH_PASS`. |
| 37 | +
|
| 38 | +### 2. Publish the `auth` flavour |
| 39 | +
|
| 40 | +Run Gradle to assemble and publish the **auth** (regular) flavour: |
| 41 | +
|
| 42 | +```bash |
| 43 | +./gradlew :auth-lib:assembleRelease :auth-lib:publishAuthReleasePublicationToOssrh-staging-apiRepository |
| 44 | +``` |
| 45 | +
|
| 46 | +Wait for this to succeed before continuing. |
| 47 | + |
| 48 | +### 3. Publish the `store` flavour |
| 49 | + |
| 50 | +Run Gradle to assemble and publish the **store** flavour: |
| 51 | + |
| 52 | +```bash |
| 53 | +./gradlew :auth-lib:assembleRelease :auth-lib:publishStoreReleasePublicationToOssrh-staging-apiRepository |
| 54 | +``` |
| 55 | + |
| 56 | +Wait for this to succeed before continuing. |
| 57 | + |
| 58 | +### 4. Generate a base64 auth token |
| 59 | + |
| 60 | +Compute a base64-encoded token from the credentials for the OSSRH staging API: |
| 61 | + |
| 62 | +```bash |
| 63 | +TOKEN=$(printf "$OSSRH_USER:$OSSRH_PASS" | base64) |
| 64 | +``` |
| 65 | + |
| 66 | +### 5. Fetch the staging repository list |
| 67 | + |
| 68 | +Call the OSSRH staging API to get the list of repositories: |
| 69 | + |
| 70 | +```bash |
| 71 | +curl -s --fail \ |
| 72 | + -H "Authorization: Bearer $TOKEN" \ |
| 73 | + https://ossrh-staging-api.central.sonatype.com/manual/search/repositories |
| 74 | +``` |
| 75 | + |
| 76 | +### 6. Extract the repository key |
| 77 | + |
| 78 | +Parse the JSON response to extract the repository key. It is the `key` field of the first (or only) entry in the `repositories` array. Save this as `REPO_KEY`. |
| 79 | + |
| 80 | +### 7. Upload the repository |
| 81 | + |
| 82 | +POST to the upload endpoint to promote the staged repository: |
| 83 | + |
| 84 | +```bash |
| 85 | +curl -s --fail -X POST \ |
| 86 | + -H "Authorization: Bearer $TOKEN" \ |
| 87 | + "https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$REPO_KEY" |
| 88 | +``` |
| 89 | + |
| 90 | +### 8. Report result |
| 91 | + |
| 92 | +If all steps succeeded, tell the user: |
| 93 | + |
| 94 | +> Deployment uploaded successfully. To complete publishing, log in to the [Sonatype OSSRH portal](https://central.sonatype.com) and manually release the staged repository. |
| 95 | +
|
| 96 | +If any step failed, report the error and stop. |
0 commit comments