Publish to Maven Central #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to Maven Central | |
| on: | |
| workflow_dispatch: # 手动触发 | |
| release: | |
| types: [created] # 在创建新的release时触发 | |
| jobs: | |
| publish: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Setup Xcode | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: latest-stable | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v2 | |
| - name: Setup Gradle | |
| uses: gradle/gradle-build-action@v2 | |
| - name: Import GPG key | |
| run: | | |
| # 创建 GPG 目录 | |
| mkdir -p ~/.gnupg/ | |
| chmod 700 ~/.gnupg/ | |
| # 在 macOS 上设置 GPG | |
| echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf | |
| echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf | |
| # 导入密钥 | |
| echo "${{ secrets.GPG_KEY_CONTENTS }}" | base64 --decode | gpg --batch --import | |
| gpg --list-secret-keys --keyid-format LONG | |
| env: | |
| GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }} | |
| - name: Publish to Maven Central | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} | |
| ORG_GRADLE_PROJECT_sonatypeStagingProfileId: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} | |
| run: | | |
| if [[ ${{ github.event_name }} == 'release' ]]; then | |
| ./gradlew publishAllPublicationsToMavenCentral --no-daemon --no-parallel | |
| else | |
| ./gradlew publishAllPublicationsToMavenCentral --no-daemon --no-parallel | |
| fi |