Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/actions/bump-version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Bump Version Action

A reusable composite action that bumps semantic versions (semver) based on the specified bump type. It can automatically read from and write to properties files.

## Inputs

| Input | Description | Required | Default | Example |
|---------------|---------------------------------------------|----------|---------------------|------------------------------|
| `bump` | Version bump type | Yes | - | `major`, `minor`, or `patch` |
| `file` | Path to properties file containing version | No | `gradle.properties` | `gradle.properties` |
| `version-key` | Key name for version in the properties file | No | `version` | `version` |

## Outputs

| Output | Description | Example |
|---------------|-------------------------------|---------|
| `new-version` | The new version after bumping | `1.2.4` |

## Usage

### Basic Usage

The action reads the version from a file, bumps it, and writes it back:

```yaml
- name: Bump version
id: bump
uses: ./.github/actions/bump-version
with:
bump: patch
# file defaults to gradle.properties

- name: Use new version
run: echo "New version is ${{ steps.bump.outputs.new-version }}"
```

### Custom Properties File

For non-standard file paths or version keys:

```yaml
- name: Bump version
id: bump
uses: ./.github/actions/bump-version
with:
bump: minor
file: custom/path/version.properties
version-key: appVersion
```

## Examples

### Version Bumping

| Bump Type | Input | Output |
|-----------|---------|---------|
| Major | `1.2.3` | `2.0.0` |
| Minor | `1.2.3` | `1.3.0` |
| Patch | `1.2.3` | `1.2.4` |

### File Format

The action expects properties files in the format:
```properties
version=1.2.3
```

You can customize the key name using the `version-key` input if your file uses a different format (e.g., `appVersion=1.2.3`).

## Validation

The action validates:
- File exists at the specified path
- Version key exists in the file
- Version format matches semver pattern (`X.Y.Z`)
- Bump type is one of: `major`, `minor`, or `patch`

If validation fails, the action will exit with an error.
73 changes: 73 additions & 0 deletions .github/actions/bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 'Bump Version'
description: 'Bumps a semantic version based on the specified bump type'

inputs:
bump:
description: 'Version bump type (major, minor, or patch)'
required: true
file:
description: 'Path to properties file containing version (must have version=X.Y.Z format)'
required: false
default: 'gradle.properties'
version-key:
description: 'Key name for version in the properties file'
required: false
default: 'version'

outputs:
new-version:
description: 'The new version after bumping'
value: ${{ steps.calculate.outputs.new_version }}

runs:
using: 'composite'
steps:
- name: Calculate and update version
id: calculate
shell: bash
run: |
FILE="${{ inputs.file }}"
VERSION_KEY="${{ inputs.version-key }}"
BUMP="${{ inputs.bump }}"

# Read current version from file
if [[ ! -f "$FILE" ]]; then
echo "Error: File '$FILE' not found"
exit 1
fi

CURRENT=$(grep "^${VERSION_KEY}=" "$FILE" | cut -d'=' -f2)
if [[ -z "$CURRENT" ]]; then
echo "Error: Could not find '${VERSION_KEY}=' in $FILE"
exit 1
fi
echo "Read version from $FILE: $CURRENT"

# Validate current version format
if ! [[ $CURRENT =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format '$CURRENT'. Expected format: X.Y.Z"
exit 1
fi

# Validate bump type
if [[ ! "$BUMP" =~ ^(major|minor|patch)$ ]]; then
echo "Error: Invalid bump type '$BUMP'. Must be: major, minor, or patch"
exit 1
fi

# Parse version
IFS='.' read -r major minor patch <<< "$CURRENT"

# Calculate new version
case "$BUMP" in
major) NEW="$((major+1)).0.0" ;;
minor) NEW="$major.$((minor+1)).0" ;;
patch) NEW="$major.$minor.$((patch+1))" ;;
esac

# Update file with new version
sed -i "s/^${VERSION_KEY}=.*/${VERSION_KEY}=$NEW/" "$FILE"
echo "Updated $FILE: ${VERSION_KEY}=$CURRENT → ${VERSION_KEY}=$NEW"

echo "new_version=$NEW" >> $GITHUB_OUTPUT
echo "Bumped version from $CURRENT to $NEW (bump type: $BUMP)"
37 changes: 37 additions & 0 deletions .github/actions/setup-gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Setup Gradle Action

A reusable composite action that sets up Java and Gradle.

## Inputs

| Input | Description | Required | Default |
|-------------------|-----------------------------------|----------|---------|
| `cache-read-only` | Whether Gradle cache is read-only | No | `true` |

## Usage

### Basic Usage (read-only cache)

```yaml
- name: Checkout
uses: actions/checkout@v4

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
```

### CI Workflow (write cache for main/develop)
```yaml
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
```

### Release Workflow (write cache)
```yaml
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: false
```
22 changes: 22 additions & 0 deletions .github/actions/setup-gradle/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Setup Java and Gradle'
description: 'Sets up JDK 17 and Gradle with caching for faster builds'

inputs:
cache-read-only:
description: 'Whether Gradle cache is read-only'
required: false
default: 'true'

runs:
using: 'composite'
steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
cache-read-only: ${{ inputs.cache-read-only }}
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
pull_request:
push:
branches: [ develop ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
format:
name: Check formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}

- name: Check formatting
run: ./gradlew spotlessCheck

lint:
name: Run detekt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}

- name: Run detekt
run: ./gradlew detekt

build:
name: Build and validate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}

- name: Build and validate
run: ./gradlew build :plugin:validatePlugins
109 changes: 109 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Release

on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
version-properties-file:
description: 'Path to properties file containing version'
required: false
type: string
default: 'gradle.properties'

concurrency:
group: release
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
ref: develop

- name: Bump version
id: bump
uses: ./.github/actions/bump-version
with:
bump: ${{ github.event.inputs.bump }}
file: ${{ github.event.inputs.version-properties-file }}

- name: Commit version file
uses: EndBug/[email protected]
with:
add: ${{ github.event.inputs.version-properties-file }}
message: "AUTOMATION: Version Bump"
default_author: github_actions
push: false

- name: Push changes to ci-release branch
run: git push origin HEAD:ci-release --force-with-lease

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
cache-read-only: false

- name: Build and publish
run: ./gradlew build publish --no-configuration-cache
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}

- name: Create Github Release
uses: ncipollo/[email protected]
with:
generateReleaseNotes: true
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
tag: v${{ steps.bump.outputs.new-version }}
commit: ci-release
makeLatest: true

sync_branches:
needs: publish
name: Sync main and develop with release
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}

- name: Configure git
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"

- name: Sync main with ci-release
run: |
git fetch origin ci-release
git merge --ff-only origin/ci-release

- name: Sync develop with main
run: |
git fetch origin develop
git checkout develop
git merge --no-edit main

- name: Push both branches
run: |
git push origin main
git push origin develop
15 changes: 15 additions & 0 deletions LICENSE_HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2014-$YEAR Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-build-conventions-android/blob/main/LICENSE
*
* 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.
*/
Loading
Loading