Skip to content

Commit

Permalink
ci: Use script to get module name from tag
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jul 31, 2024
1 parent 54b6857 commit 24f10c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name: CI
on:
push:
branches: [main]
# Release tag format is [module-name]-[namespace-name]-v[version]-[sub-version]
# For example: fragment-ktx-v1.3.5-0, compose-gears-v.1.1.1-1
tags:
- '*-ktx-v*-[0-9]+'
- '*-gears-v*-[0-9]+'
# Release tag format is [library-name]-v[version]
# Examples: fragment-ktx-v1.3.5-0, gears-compose-v1.1.1, resultflow-v0.1.0
tags: ['*-v*']
pull_request:
branches: [main]

Expand Down Expand Up @@ -36,7 +34,7 @@ jobs:
run: ./gradlew detektAll detektReleaseAll

publish:
name: Publish gears
name: Publish
needs: check
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
Expand All @@ -51,20 +49,18 @@ jobs:
distribution: 'temurin'
java-version: 17

- name: Get namespace and module name from tag
- name: Get module name from tag
id: parse-tag
run: |
tag=${GITHUB_REF#refs/tags/}
module=$(echo "${tag%-*-v*}")
namespace=$(echo "${tag/-v*}" | rev | cut -d '-' -f 1 | rev)
module=$(./scripts/get-module-name.sh "$tag")
echo "module=$module" >> "$GITHUB_OUTPUT"
echo "namespace=$namespace" >> "$GITHUB_OUTPUT"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Run Publish
run: ./gradlew :${{ steps.parse-tag.outputs.namespace }}:${{ steps.parse-tag.outputs.module }}:publish
run: ./gradlew ${{ steps.parse-tag.outputs.module }}:publish
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
Expand Down
23 changes: 23 additions & 0 deletions scripts/get-module-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
#
# Retrieves Gradle module name from the given version tag.
# Examples:
# gears-compose-v1.0.0 -> :gears:gears-compose
# core-ktx-v1.0.0-1 -> :ktx:core-ktx
# resultflow-v1.0.0 -> :resultflow
#

set -eu

tag=$1
library=${tag%-v*} # Remove version suffix

# Handle prefix for inner modules
prefix=":"
if [[ $library == *-ktx ]]; then
prefix=":ktx:"
elif [[ $library == gears-* ]]; then
prefix=":gears:"
fi

echo "$prefix$library"

0 comments on commit 24f10c8

Please sign in to comment.