Skip to content

Commit 6358a34

Browse files
authored
Extract generic release workflow (#4)
1 parent 0cd9ab8 commit 6358a34

File tree

3 files changed

+213
-27
lines changed

3 files changed

+213
-27
lines changed

.github/workflows/README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Release Workflow
2+
3+
A reusable GitHub Actions workflow for automating releases of Gradle-based projects with semantic
4+
versioning, Maven publishing, and branch management.
5+
6+
## Overview
7+
8+
The release workflow (`release.yml`) provides:
9+
10+
- **Semantic versioning** - Automatic version bumping (major, minor, patch)
11+
- **Maven publishing** - Build and publish to Maven Central
12+
- **Branch management** - Automatic syncing of main, develop, and ci-release branches
13+
- **GitHub releases** - Automatic release creation with generated notes
14+
- **Snapshot support** - Optional snapshot releases without branch updates
15+
- **Signing** - Automatic artifact signing with GPG
16+
17+
## Usage
18+
19+
### In Your Project
20+
21+
Create a workflow file (e.g., `.github/workflows/publish-new-version.yml`) in your project:
22+
23+
```yaml
24+
name: Publish New Version
25+
26+
on:
27+
workflow_dispatch:
28+
inputs:
29+
bump:
30+
description: 'Version bump type (major, minor, patch)'
31+
required: true
32+
type: choice
33+
options:
34+
- patch
35+
- minor
36+
- major
37+
snapshot:
38+
description: 'Snapshot release'
39+
required: false
40+
type: boolean
41+
default: false
42+
43+
concurrency:
44+
group: release
45+
cancel-in-progress: false
46+
47+
jobs:
48+
release:
49+
uses: GetStream/stream-build-conventions-android/.github/workflows/release.yml@develop
50+
with:
51+
bump: ${{ inputs.bump }}
52+
snapshot: ${{ inputs.snapshot }}
53+
secrets:
54+
github-token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
55+
maven-central-username: ${{ secrets.MAVEN_USERNAME }}
56+
maven-central-password: ${{ secrets.MAVEN_PASSWORD }}
57+
signing-key: ${{ secrets.SIGNING_KEY }}
58+
signing-key-id: ${{ secrets.SIGNING_KEY_ID }}
59+
signing-key-password: ${{ secrets.SIGNING_PASSWORD }}
60+
```
61+
62+
### Requirements
63+
64+
Your project must have:
65+
66+
1. **Branch structure**:
67+
- `develop` - Development branch (default branch to release from)
68+
- `main` - Production branch
69+
- `ci-release` - Created automatically during release
70+
71+
2. **Version file**: A properties file with semantic version (defaults to `gradle.properties`, but
72+
can be customized via the `version-properties-file` input):
73+
```properties
74+
version=1.2.3
75+
```
76+
77+
3. **Gradle project**: A Gradle project with a `publish` task configured
78+
79+
## Inputs
80+
81+
| Input | Required | Default | Description |
82+
|---------------------------|----------|---------------------|-------------------------------------------------|
83+
| `bump` | Yes | - | Version bump type: `major`, `minor`, or `patch` |
84+
| `snapshot` | No | `false` | Whether this is a snapshot release |
85+
| `version-properties-file` | No | `gradle.properties` | Path to file containing version |
86+
87+
## Secrets
88+
89+
| Secret | Required | Description |
90+
|--------------------------|----------|-------------------------------------------------------------------------------------|
91+
| `github-token` | Yes | GitHub token with repo with write permissions (i.e. able to push to main & develop) |
92+
| `maven-central-username` | Yes | Maven Central username for publishing |
93+
| `maven-central-password` | Yes | Maven Central password for publishing |
94+
| `signing-key` | Yes | GPG signing key for artifact signing |
95+
| `signing-key-id` | Yes | GPG signing key ID |
96+
| `signing-key-password` | Yes | GPG signing key password |
97+
98+
## Snapshot vs Production Releases
99+
100+
Both release types bump the version and run `./gradlew publish`. The key differences:
101+
102+
| Feature | Production (`snapshot: false`) | Snapshot (`snapshot: true`) |
103+
|--------------------|--------------------------------|-----------------------------|
104+
| Version commit | Pushed to ci-release | Local only |
105+
| Branch updates | main and develop synced | No branches updated |
106+
| GitHub release | Created with tag | Not created |
107+
| `SNAPSHOT` env var | `"false"` | `"true"` |
108+
109+
## Environment Variables
110+
111+
The workflow sets these environment variables during the publish step:
112+
113+
| Variable | Description |
114+
|-------------------------------------------------|----------------------------------------------------------------|
115+
| `SNAPSHOT` | `"true"` or `"false"` - Access via `System.getenv("SNAPSHOT")` |
116+
| `ORG_GRADLE_PROJECT_RELEASE_SIGNING_ENABLED` | Always `"true"` |
117+
| `ORG_GRADLE_PROJECT_mavenCentralUsername` | From secrets |
118+
| `ORG_GRADLE_PROJECT_mavenCentralPassword` | From secrets |
119+
| `ORG_GRADLE_PROJECT_signingInMemoryKey` | From secrets |
120+
| `ORG_GRADLE_PROJECT_signingInMemoryKeyId` | From secrets |
121+
| `ORG_GRADLE_PROJECT_signingInMemoryKeyPassword` | From secrets |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
default: minor
15+
version-properties-file:
16+
description: 'Path to properties file containing version'
17+
required: false
18+
type: string
19+
default: 'gradle.properties'
20+
snapshot:
21+
description: 'Snapshot release'
22+
required: false
23+
type: boolean
24+
default: false
25+
26+
concurrency:
27+
group: release
28+
cancel-in-progress: false
29+
30+
jobs:
31+
release:
32+
permissions:
33+
contents: write
34+
uses: ./.github/workflows/release.yml
35+
with:
36+
bump: ${{ inputs.bump }}
37+
version-properties-file: ${{ inputs.version-properties-file }}
38+
snapshot: ${{ inputs.snapshot }}
39+
secrets:
40+
github-token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
41+
maven-central-username: ${{ secrets.OSSRH_USERNAME }}
42+
maven-central-password: ${{ secrets.OSSRH_PASSWORD }}
43+
signing-key: ${{ secrets.SIGNING_KEY }}
44+
signing-key-id: ${{ secrets.SIGNING_KEY_ID }}
45+
signing-key-password: ${{ secrets.SIGNING_PASSWORD }}

.github/workflows/release.yml

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
1-
name: Release
1+
name: Release Workflow
22

33
on:
4-
workflow_dispatch:
4+
workflow_call:
55
inputs:
66
bump:
7-
description: 'Version bump type'
7+
description: 'Version bump type (major, minor, patch)'
88
required: true
9-
type: choice
10-
options:
11-
- patch
12-
- minor
13-
- major
14-
default: 'minor'
9+
type: string
1510
version-properties-file:
1611
description: 'Path to properties file containing version'
1712
required: false
1813
type: string
1914
default: 'gradle.properties'
20-
21-
concurrency:
22-
group: release
23-
cancel-in-progress: false
15+
snapshot:
16+
description: 'Whether this is a snapshot release'
17+
required: false
18+
type: boolean
19+
default: false
20+
secrets:
21+
github-token:
22+
description: 'GitHub token with repo write permissions'
23+
required: true
24+
maven-central-username:
25+
description: 'Maven Central username'
26+
required: true
27+
maven-central-password:
28+
description: 'Maven Central password'
29+
required: true
30+
signing-key:
31+
description: 'GPG signing key'
32+
required: true
33+
signing-key-id:
34+
description: 'GPG signing key ID'
35+
required: true
36+
signing-key-password:
37+
description: 'GPG signing key password'
38+
required: true
2439

2540
jobs:
2641
publish:
@@ -30,7 +45,7 @@ jobs:
3045
- name: Checkout
3146
uses: actions/checkout@v4
3247
with:
33-
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
48+
token: ${{ secrets.github-token }}
3449
ref: develop
3550
fetch-depth: 0
3651

@@ -56,47 +71,52 @@ jobs:
5671
5772
- name: Bump version
5873
id: bump
59-
uses: ./.github/actions/bump-version
74+
uses: GetStream/stream-build-conventions-android/.github/actions/bump-version@develop
6075
with:
61-
bump: ${{ github.event.inputs.bump }}
62-
file: ${{ github.event.inputs.version-properties-file }}
76+
bump: ${{ inputs.bump }}
77+
file: ${{ inputs.version-properties-file }}
6378

6479
- name: Commit version file
6580
uses: EndBug/[email protected]
6681
with:
67-
add: ${{ github.event.inputs.version-properties-file }}
82+
add: ${{ inputs.version-properties-file }}
6883
message: "AUTOMATION: Version Bump"
6984
default_author: github_actions
7085
push: false
7186

7287
- name: Push changes to ci-release branch
88+
if: ${{ !inputs.snapshot }}
7389
run: git push origin HEAD:ci-release --force-with-lease
7490

7591
- name: Setup Gradle
76-
uses: ./.github/actions/setup-gradle
92+
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@develop
7793
with:
7894
cache-read-only: false
7995

8096
- name: Build and publish
81-
run: ./gradlew build publish --no-configuration-cache
97+
run: ./gradlew publish --no-configuration-cache
8298
env:
83-
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
84-
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
85-
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
86-
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
87-
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
99+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.maven-central-username }}
100+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.maven-central-password }}
101+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signing-key }}
102+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signing-key-id }}
103+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signing-key-password }}
88104
ORG_GRADLE_PROJECT_RELEASE_SIGNING_ENABLED: true
105+
# todo Make it a gradle property instead?
106+
SNAPSHOT: ${{ inputs.snapshot }}
89107

90108
- name: Create Github Release
109+
if: ${{ !inputs.snapshot }}
91110
uses: ncipollo/[email protected]
92111
with:
93112
generateReleaseNotes: true
94-
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
113+
token: ${{ secrets.github-token }}
95114
tag: v${{ steps.bump.outputs.new-version }}
96115
commit: ci-release
97116
makeLatest: true
98117

99118
sync_branches:
119+
if: ${{ !inputs.snapshot }}
100120
needs: publish
101121
name: Sync main and develop with release
102122
runs-on: ubuntu-latest
@@ -106,7 +126,7 @@ jobs:
106126
with:
107127
ref: main
108128
fetch-depth: 0
109-
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
129+
token: ${{ secrets.github-token }}
110130

111131
- name: Configure git
112132
run: |

0 commit comments

Comments
 (0)