Skip to content

Commit 0f0ab8e

Browse files
author
John Qualls
authored
AHOYAPPS-618: Publish Docs CI Integration (#76)
* Add dokka gradle plugin * Add property KDoc tags * Add generated Github Pages * Revert "Add generated Github Pages" This reverts commit d11c568. * Test Jekyll doc format * Revert "Test Jekyll doc format" This reverts commit bf312b0. * Change constructor documentation to match KDoc spec * Additional documenation changes to match KDoc specs * Add dokka docs * Add config.yml to use proper markdown * Revert "Add config.yml to use proper markdown" This reverts commit b32c29b. * Fixing parameter formatting * Set theme jekyll-theme-minimal * Set theme jekyll-theme-slate * Add documentation link to README * Exclude docs dir from spotless check * Change dokka config to output html to docs folder * Fix KDoc formatting * Going to store docs in another branch * Remove docs dokka output dir config * Update docs link * Add publishDocs gradle task * Fix mv command syntax * Move index.html redirect to gh-pages branch * Add publish-docs CI job * Update changelog * Move docs index.html to audioswitch modue * Reference index.html from mainline in gh-pages
1 parent 638bc91 commit 0f0ab8e

File tree

8 files changed

+161
-50
lines changed

8 files changed

+161
-50
lines changed

.circleci/config.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ jobs:
158158
command: ./gradlew incrementVersion
159159
- save_cache: *save_cache-gradle
160160

161+
publish-docs:
162+
<<: *build-defaults
163+
resource_class: large
164+
steps:
165+
- checkout
166+
- attach_workspace:
167+
at: *workspace
168+
- restore_cache: *restore_cache-gradle
169+
- run: *configure-git-user
170+
- run:
171+
name: Publish Docs
172+
command: ./gradlew publishDocs
173+
- save_cache: *save_cache-gradle
174+
161175
workflows:
162176
build-test-publish:
163177
jobs:
@@ -187,7 +201,11 @@ workflows:
187201
jobs:
188202
- publish-release:
189203
<<: *release-filter
190-
- bump-version:
204+
- publish-docs:
191205
<<: *release-filter
192206
requires:
193207
- publish-release
208+
- bump-version:
209+
<<: *release-filter
210+
requires:
211+
- publish-docs

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
### 1.1.1
4+
5+
Enhancements
6+
7+
- Added public KDoc documentation for each release. The latest documentation release can be found at https://twilio.github.io/audioswitch/latest
8+
39
### 1.1.0
410

511
Enhancements

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Android Studio Version | Android API Version Min
2020
------------ | -------------
2121
3.6+ | 16
2222

23+
## Documentation
24+
25+
The KDoc for this library can be found [here](https://twilio.github.io/audioswitch/latest).
26+
2327
## Getting Started
2428

2529
To get started using this library, follow the steps below.

audioswitch/build.gradle

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'maven'
33
apply plugin: 'maven-publish'
44
apply plugin: "com.jfrog.artifactory"
55
apply plugin: 'kotlin-android'
6+
apply plugin: "org.jetbrains.dokka"
67

78
android {
89
compileSdkVersion 30
@@ -37,6 +38,16 @@ android {
3738
}
3839
}
3940

41+
dokkaHtml.configure {
42+
dokkaSourceSets {
43+
named("main") {
44+
noAndroidSdkLink.set(false)
45+
includeNonPublic = false
46+
reportUndocumented = true
47+
skipEmptyPackages = true
48+
}
49+
}
50+
}
4051
}
4152

4253
dependencies {

audioswitch/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<script>
10+
window.location.replace(document.location.href + "audioswitch/index.html");
11+
</script>
12+
</body>
13+
</html>

audioswitch/src/main/java/com/twilio/audioswitch/AudioDeviceChangeListener.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.twilio.audioswitch
22

3-
/** A listener that receives the most recently available [AudioDevice]s.
3+
/**
44
* Receives a list of the most recently available [AudioDevice]s. Also provides the
55
* currently selected [AudioDevice] from [AudioSwitch].
6-
*
7-
* @param audioDevices the list of [AudioDevice]s or an empty list if none are available.
8-
* @param selectedAudioDevice the currently selected device or null if no device has been selected.
6+
* - audioDevices - The list of [AudioDevice]s or an empty list if none are available.
7+
* - selectedAudioDevice - The currently selected device or null if no device has been selected.
98
*/
109
typealias AudioDeviceChangeListener = (
1110
audioDevices: List<AudioDevice>,

audioswitch/src/main/java/com/twilio/audioswitch/AudioSwitch.kt

+19-45
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ private const val TAG = "AudioSwitch"
2626
* should be routed to. It is strongly recommended that instances of this class are created and
2727
* accessed from a single application thread. Accessing an instance from multiple threads may cause
2828
* synchronization problems.
29-
*/
29+
*
30+
* @property loggingEnabled A property to configure AudioSwitch logging behavior. AudioSwitch logging is disabled by
31+
* default.
32+
* @property selectedAudioDevice Retrieves the selected [AudioDevice] from [AudioSwitch.selectDevice].
33+
* @property availableAudioDevices Retrieves the current list of available [AudioDevice]s.
34+
**/
3035
class AudioSwitch {
3136

3237
private var logger: Logger = ProductionLogger()
@@ -67,58 +72,30 @@ class AudioSwitch {
6772
}
6873
}
6974

70-
/**
71-
* A property to configure AudioSwitch logging behavior. AudioSwitch logging is disabled by
72-
* default.
73-
*/
7475
var loggingEnabled: Boolean
75-
/**
76-
* Returns `true` if logging is enabled. Returns `false` by default.
77-
*/
7876
get() = logger.loggingEnabled
7977

80-
/**
81-
* Toggle whether logging is enabled.
82-
*/
8378
set(value) {
8479
logger.loggingEnabled = value
8580
}
86-
87-
/**
88-
* Retrieves the selected [AudioDevice] from [AudioSwitch.selectDevice].
89-
*
90-
* @return the selected [AudioDevice]
91-
*/
9281
val selectedAudioDevice: AudioDevice? get() = selectedDevice
93-
94-
/**
95-
* Retrieves the current list of available [AudioDevice]s.
96-
*
97-
* @return the current list of [AudioDevice]s
98-
*/
9982
val availableAudioDevices: List<AudioDevice> = mutableAudioDevices
10083

10184
/**
10285
* Constructs a new AudioSwitch instance.
103-
*
104-
* @param context An Android Context.
105-
* @param loggingEnabled Toggle whether logging is enabled. This argument is false by default.
106-
* @param audioFocusChangeListener A listener that is invoked when the system audio focus is updated.
86+
* - [context] - An Android Context.
87+
* - [loggingEnabled] - Toggle whether logging is enabled. This argument is false by default.
88+
* - [audioFocusChangeListener] - A listener that is invoked when the system audio focus is updated.
10789
* Note that updates are only sent to the listener after [activate] has been called.
108-
* @param preferredDeviceList The order in which [AudioSwitch] automatically selects and activates
90+
* - [preferredDeviceList] - The order in which [AudioSwitch] automatically selects and activates
10991
* an [AudioDevice]. This parameter is ignored if the [selectedAudioDevice] is not `null`.
110-
*
11192
* The default preferred [AudioDevice] order is the following:
112-
*
11393
* [BluetoothHeadset], [WiredHeadset], [Earpiece], [Speakerphone]
114-
*
115-
* [preferredDeviceList] is added to the front of the default list. For example, if [preferredDeviceList]
94+
* . The [preferredDeviceList] is added to the front of the default list. For example, if [preferredDeviceList]
11695
* is [Speakerphone] and [BluetoothHeadset], then the new preferred audio
11796
* device list will be:
118-
*
11997
* [Speakerphone], [BluetoothHeadset], [WiredHeadset], [Earpiece].
120-
*
121-
* @throws IllegalArgumentException if the [preferredDeviceList] contains duplicate [AudioDevice] elements.
98+
* An [IllegalArgumentException] is thrown if the [preferredDeviceList] contains duplicate [AudioDevice] elements.
12299
*/
123100
@JvmOverloads
124101
constructor(
@@ -171,11 +148,9 @@ class AudioSwitch {
171148
}
172149

173150
/**
174-
* Starts listening for audio device changes. **Note:** When audio device listening is no
175-
* longer needed, [AudioSwitch.stop] should be called in order to prevent a
176-
* memory leak.
177-
*
178-
* @param listener receives audio device change events
151+
* Starts listening for audio device changes and calls the [listener] upon each change.
152+
* **Note:** When audio device listening is no longer needed, [AudioSwitch.stop] should be
153+
* called in order to prevent a memory leak.
179154
*/
180155
fun start(listener: AudioDeviceChangeListener) {
181156
audioDeviceChangeListener = listener
@@ -253,11 +228,10 @@ class AudioSwitch {
253228
}
254229

255230
/**
256-
* Selects the desired [AudioDevice]. If the provided [AudioDevice] is not
257-
* available, no changes are made. If the provided [AudioDevice] is null, an [AudioDevice] is
258-
* chosen based on the following preference: Bluetooth, Wired Headset, Earpiece, Speakerphone.
259-
*
260-
* @param audioDevice The [AudioDevice] to use
231+
* Selects the desired [audioDevice]. If the provided [AudioDevice] is not
232+
* available, no changes are made. If the provided device is null, one is chosen based on the
233+
* specified preferred device list or the following default list:
234+
* [BluetoothHeadset], [WiredHeadset], [Earpiece], [Speakerphone].
261235
*/
262236
fun selectDevice(audioDevice: AudioDevice?) {
263237
if (selectedDevice != audioDevice) {

build.gradle

+86
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
buildscript {
22
ext.kotlin_version = '1.4.0'
3+
ext.dokka_version = '1.4.10'
34

45
/**
56
* Properties and environment variables needed to publish to Bintray.
@@ -74,17 +75,20 @@ buildscript {
7475
dependencies {
7576
classpath 'com.android.tools.build:gradle:4.0.0'
7677
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
78+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
7779
}
7880
}
7981

8082
plugins {
8183
id "com.diffplug.spotless" version "5.6.1"
8284
id "com.jfrog.artifactory" version "4.15.2"
85+
id "org.jetbrains.dokka" version "1.4.10"
8386
}
8487
apply plugin: "com.diffplug.spotless"
8588
spotless {
8689
format 'misc', {
8790
target '**/*.gradle', '**/*.md', '**/.gitignore'
91+
targetExclude 'docs/**'
8892

8993
trimTrailingWhitespace()
9094
indentWithSpaces()
@@ -238,3 +242,85 @@ task bintrayAudioSwitchReleaseUpload(type: RootGradleBuild) {
238242
'maven.password': "${getPropertyValue("AUDIOSWITCH_BINTRAY_PASSWORD")}"
239243
]
240244
}
245+
246+
task publishDocs {
247+
description = 'Publish AudioSwitch KDocs to gh-pages branch'
248+
group = 'Publishing'
249+
dependsOn 'audioswitch:dokkaHtml'
250+
dependsOn validateReleaseTag
251+
def releaseVersion = System.getenv("CIRCLE_TAG") == null ?
252+
("") :
253+
(System.getenv("CIRCLE_TAG"))
254+
def pinLatestDocsCommand = ["ln", "-sfn", "${releaseVersion}", "docs/latest"]
255+
def githubToken = System.getenv("GITHUB_TOKEN")
256+
def repoSlug = "${System.env.CIRCLE_PROJECT_USERNAME}/${System.env.CIRCLE_PROJECT_REPONAME}"
257+
def gitRef = "https://${githubToken}@github.com/${repoSlug}.git"
258+
def remote = "upstream"
259+
def pushNullFile = new FileOutputStream("/dev/null")
260+
261+
doLast {
262+
exec {
263+
workingDir "${rootDir}"
264+
commandLine "cp", "audioswitch/index.html", "audioswitch/build"
265+
}
266+
267+
exec {
268+
workingDir "${rootDir}"
269+
commandLine "git", "remote", "add", "${remote}", "${gitRef}"
270+
// Ignore exit value because remote may have been added in previous task
271+
ignoreExitValue true
272+
}
273+
274+
exec {
275+
workingDir "${rootDir}"
276+
commandLine "git", "fetch", "${remote}"
277+
}
278+
279+
exec {
280+
workingDir "${rootDir}"
281+
commandLine "git", "checkout", "-b", "gh-pages", "remotes/${remote}/gh-pages"
282+
}
283+
284+
exec {
285+
workingDir "${rootDir}"
286+
commandLine "mkdir", "docs"
287+
ignoreExitValue true
288+
}
289+
290+
exec {
291+
workingDir "${rootDir}"
292+
commandLine "cp", "-r", "audioswitch/build/dokka/html/.", "docs/${releaseVersion}"
293+
}
294+
295+
exec {
296+
workingDir "${rootDir}"
297+
commandLine "cp", "audioswitch/build/index.html", "docs/${releaseVersion}"
298+
}
299+
300+
exec {
301+
workingDir "${rootDir}"
302+
commandLine pinLatestDocsCommand
303+
}
304+
305+
exec {
306+
workingDir "${rootDir}"
307+
commandLine "git", "add", "docs/${releaseVersion}", "docs/latest"
308+
}
309+
310+
exec {
311+
workingDir "${rootDir}"
312+
commandLine "git", "commit", "-m", "\"${releaseVersion} release docs [skip ci]\""
313+
}
314+
315+
exec {
316+
workingDir "${rootDir}"
317+
commandLine "git", "push", "--quiet", "${remote}", "gh-pages"
318+
standardOutput pushNullFile
319+
}
320+
321+
exec {
322+
workingDir "${rootDir}"
323+
commandLine "git", "checkout", "${releaseVersion}"
324+
}
325+
}
326+
}

0 commit comments

Comments
 (0)