From 6d2c2fe194da7e42d0e1f676ac992ef20d36b40a Mon Sep 17 00:00:00 2001 From: trdelnk Date: Tue, 18 Jun 2024 23:04:16 +0300 Subject: [PATCH] add publish to maven workflow --- .github/sh/validate_publishing_branch.sh | 4 +- .github/workflows/publish-to-maven.yml | 48 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-to-maven.yml diff --git a/.github/sh/validate_publishing_branch.sh b/.github/sh/validate_publishing_branch.sh index abc045f3..57e7242e 100755 --- a/.github/sh/validate_publishing_branch.sh +++ b/.github/sh/validate_publishing_branch.sh @@ -3,10 +3,10 @@ if [[ ${GITHUB_REF##*/} == main ]]; then # Safe to publish from main branch exit 0 -elif [[ ${GITHUB_REF##*/} == publish* ]]; then +elif [[ ${GITHUB_REF##*/} == release* ]]; then # Safe to publish from branches that have manually enabled publishing exit 0 else - echo "::error ::Can only release from main branch or branches that start with 'publish'" + echo "::error ::Can only release from main branch or branches that start with 'release'" exit 1 fi diff --git a/.github/workflows/publish-to-maven.yml b/.github/workflows/publish-to-maven.yml new file mode 100644 index 00000000..d5c34b44 --- /dev/null +++ b/.github/workflows/publish-to-maven.yml @@ -0,0 +1,48 @@ +name: Publish to Maven Central + +on: workflow_dispatch + +env: + NEW_VERSION: ${{ github.event.inputs.version }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEYID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEYPASSWORD }} + +jobs: + validate: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Ensure main branch + run: ./.github/sh/validate_publishing_branch.sh + + - name: Validate publishing + run: | + ./gradlew \ + -xtest \ + -xlint \ + publishToMavenLocal + + - name: Publishing + run: ./gradlew publishToMavenCentral \ No newline at end of file