Skip to content

Commit

Permalink
VIDEO-7662: Publish snapshots to MavenCentral (#104)
Browse files Browse the repository at this point in the history
Gradle changes:
- remove references to artifactory
- publish snapshots to maven central snapshots repository
- remove obsolete `jcenter` from repositories

Circle CI changes:
- refactor Circle CI config file to use commands and executors
- add parameter for pre-release publishing to maven central
- add parameter for disabling default CI workflow 
- add parameter and workflow for publishing a snapshot from any branch
- add comments and do other minor refactoring in CI config

Other changes:
- restore patch version number to 3, since that is the next version to be published
- update README with info on how to reference maven central snapshots
- add CHANGELOG entry
- add contributor
  • Loading branch information
Magnus Martikainen authored Nov 5, 2021
1 parent 0a4d17a commit b994780
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 141 deletions.
223 changes: 134 additions & 89 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
version: 2.1

parameters:
# this flag allows you to disable the default workflow, e.g. when running the standalone publish-snapshot workflow
enable-default-workflow:
description: "enables the main workflow that builds and tests on all branches and publishes a snapshot on master"
type: boolean
default: true

# this flag allows you to publish a snapshot from any branch, using a standalone workflow
enable-publish-snapshot-workflow:
description: "enables the standalone workflow to build and publish a snapshot from any branch"
type: boolean
default: false

aliases:
- &workspace
~/audioswitch

- &gradle-cache-key
key: jars-{{ checksum "build.gradle" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- &restore_cache-gradle
<<: *gradle-cache-key
name: Restore Gradle Cache
- &save_cache-gradle
<<: *gradle-cache-key
name: Save Gradle Cache
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper

- &configure-git-user
name: Configure git user
command: |
git config --global user.email $GIT_USER_EMAIL
git config --global user.name $GIT_USER_NAME
- &build-defaults
working_directory: *workspace
docker:
- image: circleci/android:api-28-node
environment:
- _JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport"

- &integration-test-defaults
working_directory: *workspace
docker:
- image: google/cloud-sdk:latest
environment:
resource_class: medium+

- &gcloud-auth
name: Google Cloud Auth
command: >
echo $GCP_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
- &signing-key
name: Install signing key
command: >
echo $SIGNING_KEY | base64 -d >> $SIGNING_SECRET_KEY_RING_FILE
jars-{{ checksum "build.gradle" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}

- &release-filter
filters:
Expand All @@ -54,133 +28,200 @@ aliases:
branches:
ignore: /.*/

- &snapshot-filter
filters:
branches:
only:
- master

commands:
restore_gradle_cache:
steps:
- restore_cache:
key: *gradle-cache-key
name: Restore Gradle Cache

save_gradle_cache:
steps:
- save_cache:
key: *gradle-cache-key
name: Save Gradle Cache
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper

setup_git_user:
description: Configure git user
steps:
- run:
name: Configure git user name and email
command: |
git config --global user.email $GIT_USER_EMAIL
git config --global user.name $GIT_USER_NAME
setup_gcloud:
description: Authenticate with Google Cloud
steps:
- run:
name: Setup GCloud Auth
command: |
echo $GCP_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
install_signing_key:
steps:
- run:
name: Install signing key
command: |
echo $SIGNING_KEY | base64 -d >> $SIGNING_SECRET_KEY_RING_FILE
publish_to_sonatype:
description: Publish to Sonatype Repository
parameters:
pre-release:
description: If true, publish a pre-release, otherwise publish a release
type: boolean
steps:
- run:
name: Publish AudioSwitch <<# parameters.pre-release >> snapshot <</ parameters.pre-release >><<^ parameters.pre-release >> release <</ parameters.pre-release >>
command: |
./gradlew -q sonatypeAudioSwitchReleaseUpload \
-PpreRelease=<< parameters.pre-release >>
executors:
build-executor:
working_directory: *workspace
docker:
- image: circleci/android:api-30
resource_class: large
environment:
_JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport"

integration-test-executor:
working_directory: *workspace
docker:
- image: google/cloud-sdk:latest
resource_class: medium+

jobs:
lint:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- restore_cache: *restore_cache-gradle
- restore_gradle_cache
- run:
name: Lint
command: ./gradlew -q lint
- store_artifacts:
path: audioswitch/build/reports/lint-results.html
prefix: audioswitch
- save_cache: *save_cache-gradle
destination: audioswitch
- save_gradle_cache

check-format:
<<: *build-defaults
executor: build-executor
resource_class: medium+
steps:
- checkout
- restore_cache: *restore_cache-gradle
- restore_gradle_cache
- run:
name: Spotless Check
command: ./gradlew -q spotlessCheck
- save_cache: *save_cache-gradle
- save_gradle_cache

build-audioswitch:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- restore_gradle_cache
- run:
name: Build AudioSwitch and Tests
command: ./gradlew -q audioswitch:assemble audioswitch:assembleAndroidTest
- persist_to_workspace:
root: .
paths:
- audioswitch/build
- save_cache: *save_cache-gradle
- save_gradle_cache

unit-tests:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- restore_gradle_cache
- run:
name: Unit Tests
command: ./gradlew audioswitch:testDebugUnitTest
- save_cache: *save_cache-gradle
- save_gradle_cache

integration-tests:
<<: *integration-test-defaults
executor: integration-test-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- run: *gcloud-auth
- setup_gcloud
- run:
name: Integration Tests
name: Run Integration Tests
command: >
gcloud firebase test android run --use-orchestrator --environment-variables clearPackageData=true --no-record-video --project video-app-79418
ui-test-args.yaml:integration-tests
publish-pre-release:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *signing-key
- run:
name: Publish AudioSwitch pre release
command: ./gradlew -q jfrogOssSnapshotsAudioSwitchUpload
- save_cache: *save_cache-gradle
- restore_gradle_cache
- install_signing_key
- publish_to_sonatype:
pre-release: true
- save_gradle_cache

publish-release:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *signing-key
- run:
name: Publish AudioSwitch release
command: ./gradlew -q sonatypeAudioSwitchReleaseUpload
- save_cache: *save_cache-gradle
- restore_gradle_cache
- install_signing_key
- publish_to_sonatype:
pre-release: false
- save_gradle_cache

bump-version:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *configure-git-user
- restore_gradle_cache
- setup_git_user
- run:
name: Bump Version
command: ./gradlew incrementVersion
- save_cache: *save_cache-gradle
- save_gradle_cache

publish-docs:
<<: *build-defaults
resource_class: large
executor: build-executor
steps:
- checkout
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *configure-git-user
- restore_gradle_cache
- setup_git_user
- run:
name: Publish Docs
command: ./gradlew publishDocs
- save_cache: *save_cache-gradle
- save_gradle_cache

workflows:
# Default workflow. Triggered by all commits. Runs checks and tests on all branches. For master, also publishes a snapshot.
build-test-publish:
when: << pipeline.parameters.enable-default-workflow >>
jobs:
- lint
- check-format
Expand All @@ -196,14 +237,12 @@ workflows:
- lint
- check-format
- publish-pre-release:
filters:
branches:
only:
- "master"
<<: *snapshot-filter
requires:
- unit-tests
- integration-tests

# Workflow to publish a release. Triggered by new git tags that match a version number, e.g. '1.2.3'.
release:
jobs:
- publish-release:
Expand All @@ -216,3 +255,9 @@ workflows:
<<: *release-filter
requires:
- publish-docs

# Workflow to explicitly build and publish a snapshot. Triggered manually by setting the parameter to true.
publish-snapshot:
when: << pipeline.parameters.enable-publish-snapshot-workflow >>
jobs:
- publish-pre-release
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog

### 1.1.3

Enhancements
Expand All @@ -7,6 +8,7 @@ Enhancements
- Updated internal dependencies related to Android 12 support
- Updated compile and target sdk to Android 12 (31)
- Updated gradle to version 4.2.1
- Snapshots are now published to the Maven Central snapshots repository

### 1.1.2

Expand Down Expand Up @@ -65,7 +67,7 @@ audioSwitch.start { _, _ -> }
```kotlin
val audioSwitch = AudioSwitch(context, audioFocusChangeListener = OnAudioFocusChangeListener { focusChange ->
// Do something with audio focus change
))}
})

audioSwitch.start { _, _ -> }
// Audio focus changes are received after activating
Expand Down Expand Up @@ -170,7 +172,7 @@ Ensure that you have `mavenCentral` listed in your project's buildscript reposit
buildscript {
repositories {
mavenCentral()
...
// ...
}
}
```
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Thank you to all our contributors!
* [Tejas Nandanikar](https://github.com/tejas-n)
* [Ryan C. Payne](https://github.com/paynerc)
* [Ardavon Falls](https://github.com/afalls-twilio)
* [Magnus Martikainen](https://github.com/mmartikainen)
Loading

0 comments on commit b994780

Please sign in to comment.