blob: 450fb01c360bb9850d73e6eb437727c5036b9179 [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: publish_java_sdk
on:
push:
tags:
- "java-sdk-*"
env:
GITHUB_TOKEN: ${{ github.token }}
jobs:
validate:
if: startsWith(github.ref, 'refs/tags/java-sdk-')
runs-on: ubuntu-latest
steps:
- name: Extract tag name
id: extract
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Validate tag format
run: |
TAG=${TAG}
if [[ ! "$TAG" =~ ^java-sdk-([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]]; then
echo "Tag $TAG does not match strict semver format (java-sdk-X.Y.Z where 0 <= X,Y,Z <= 999)"
exit 1
fi
echo "Valid tag: $TAG"
tag:
needs: validate
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract tag name
id: extract_tag
run: |
tag=${GITHUB_REF#refs/tags/}
echo "tag_name=$tag" >> "$GITHUB_OUTPUT"
echo "::notice ::Tag that triggered the workflow: $tag"
- name: Extract java-sdk version from build.gradle.kts
id: extract_version
run: |
version=$(foreign/java/gradlew -p foreign/java/java-sdk properties -q | grep "version:" | cut -d: -f2 | tr -d ' ')
echo "java_sdk_version=$version" >> "$GITHUB_OUTPUT"
echo "::notice ::Version from gradle build file is $version"
- name: Check if version from build.gradle is the same as the tag
id: check_git_tag
run: |
if [[ "java-sdk-${{ steps.extract_version.outputs.java_sdk_version }}" == "${{ steps.extract_tag.outputs.tag_name }}" ]];
then
echo "::notice ::Tag ${{ steps.extract_tag.outputs.tag_name }} matches the version in build.gradle"
echo "tag_matches=true" >> "$GITHUB_OUTPUT"
else
echo "::warning ::Tag ${{ steps.extract_tag.outputs.tag_name }} does not matche the version from build.gradle"
echo "tag_matches=false" >> "$GITHUB_OUTPUT"
fi
outputs:
java_sdk_version: ${{ steps.extract_tag.outputs.tag_name }}
tag_created: ${{ steps.check_git_tag.outputs.tag_matches }}
publish:
name: Publish Java SDK to Maven Nexus
needs: tag
if: ${{ needs.tag.outputs.tag_created == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Build
run: foreign/java/dev-support/checks/build.sh build -x test -x checkstyleMain -x checkstyleTest
- name: Run tests
run: foreign/java/dev-support/checks/build.sh test
- name: Publish
# To publish we use NEXUS_USER and NEXUS_PASSWORD as credentials
env:
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PW }}
run: foreign/java/dev-support/checks/build.sh build -x test -x checkstyleMain -x checkstyleTest publish