diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml new file mode 100644 index 00000000..d19f80ae --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -0,0 +1,18 @@ +name: Gradle Wrapper Validation +on: + push: + branches: + - master + pull_request: + +jobs: + validate-project-gradle-wrapper: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Validate + runs-on: ubuntu-latest + steps: + - name: Checkout latest code + uses: actions/checkout@v2 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 00000000..cd49506f --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,47 @@ +name: Release +on: + push: + tags: + - '*.*.*' + +jobs: + publish-release: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Publish Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Dirs + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: cache-gradle- + + - name: Deploy Release + env: + ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + ORG_GRADLE_PROJECT_SONATYPE_NEXUS_SIGNING_KEY: ${{ secrets.SONATYPE_NEXUS_SIGNING_KEY }} + run: ./gradlew uploadArchives --no-daemon --no-parallel --stacktrace + + - name: Stop Gradle + run: ./gradlew --stop + + - name: Extract Release Notes + id: release-notes + uses: ffurrer2/extract-release-notes@v1 + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + body: ${{ steps.release-notes.outputs.release_notes }} + files: | + ./library/*/build/outputs/aar/*.aar + ./library/*/build/libs/!(*-sources|*-javadoc).jar + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml new file mode 100644 index 00000000..cb60c0eb --- /dev/null +++ b/.github/workflows/publish-snapshot.yml @@ -0,0 +1,37 @@ +name: Snapshot +on: + push: + branches: + - master + +jobs: + publish-snapshot: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Publish Snapshot + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Dirs + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: cache-gradle- + + - name: Deploy Snapshot + env: + ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + run: ./gradlew uploadArchives --no-daemon --no-parallel --stacktrace + + - name: Stop Gradle + run: ./gradlew --stop diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml new file mode 100644 index 00000000..12cf69e0 --- /dev/null +++ b/.github/workflows/quality-check.yml @@ -0,0 +1,84 @@ +name: Quality Check +on: + push: + branches: + - master + paths-ignore: + - 'library/docs/**' + - '**.md' + - '.github/CODEOWNERS' + pull_request: + paths-ignore: + - 'library/docs/**' + - '**.md' + - '.github/CODEOWNERS' + +jobs: + tests: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Tests + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Dirs + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: cache-gradle- + + - name: Run Tests + run: ./gradlew test --stacktrace + + - name: Stop Gradle + run: ./gradlew --stop + + detekt: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Detekt + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Dirs + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: cache-gradle- + + - name: Run Detekt + run: ./gradlew detekt --stacktrace + + - name: Stop Gradle + run: ./gradlew --stop + + lint: + if: ${{ github.repository == 'MiSikora/Ruler' }} + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Dirs + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: cache-gradle- + + - name: Run Lint + run: ./gradlew lint --stacktrace + + - name: Stop Gradle + run: ./gradlew --stop diff --git a/README.md b/README.md index f2ca0ce6..ce86646f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,5 @@ # Ruler -[![Build Status](https://app.bitrise.io/app/07d245b19bfdcfe5/status.svg?token=eLa51er1EPU3_rvwpL99Kw)](https://app.bitrise.io/app/07d245b19bfdcfe5) - -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.mehow.ruler/ruler/badge.svg)](https://search.maven.org/search?q=g:io.mehow.ruler) -[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0) - Distance measurements library for Java and Android. ## Integration diff --git a/RELEASING.md b/RELEASING.md deleted file mode 100644 index bdb966ae..00000000 --- a/RELEASING.md +++ /dev/null @@ -1,12 +0,0 @@ -# Releasing - - 1. Change the version in [`gradle.properties`](gradle.properties) to a non-SNAPSHOT version. - 2. Update [the `CHANGELOG.md`](CHANGELOG.md) for the impending release. - 3. Update [the `README.md`](README.md) with the new version. - 4. `git commit -am "Prepare for release X.Y.Z."` (where `X.Y.Z` is the new version). - 5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where `X.Y.Z` is the new version). - 6. Update the [`gradle.properties`](gradle.properties) to the next SNAPSHOT version. - 7. `git commit -am "Prepare next development version."` - 8. `git push && git push --tags` - 9. Wait for [the CI server](https://app.bitrise.io/build/c3c2f15e87d8f268) to upload the artifact. - 10. Visit [Sonatype Nexus](https://oss.sonatype.org) and promote the artifact. diff --git a/CHANGELOG.md b/docs/changelog.md similarity index 100% rename from CHANGELOG.md rename to docs/changelog.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..ce86646f --- /dev/null +++ b/docs/index.md @@ -0,0 +1,48 @@ +# Ruler + +Distance measurements library for Java and Android. + +## Integration + +Ruler requires Java 8 bytecode. To enable Java 8 desugaring configure it in your Gradle script. + +```groovy +android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + // For Kotlin projects + kotlinOptions { + jvmTarget = "1.8" + } +} +``` + +To integrate it with your app you need to add a dependency to you project. + +```groovy +debugImplementation "io.mehow.ruler:ruler:0.5.3" +``` + +If you use Android you can use Android artifact. + +```groovy +debugImplementation "io.mehow.ruler:android:0.5.3" +``` + +## License + + Copyright 2020 MichaƂ Sikora + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. diff --git a/docs/releasing.md b/docs/releasing.md new file mode 100644 index 00000000..25571a89 --- /dev/null +++ b/docs/releasing.md @@ -0,0 +1,8 @@ +# Releasing + +## Versioning + +1. Run the [prepare release script](https://github.com/MiSikora/Laboratory/blob/master/prepare-release.sh) and bump the desirable version part. +2. If there are no errors `git push && git push --tags`. +3. Wait for [the CI server](https://github.com/MiSikora/Ruler/actions) to upload the artifacts. +4. Visit [Sonatype Nexus](https://oss.sonatype.org) and promote the artifacts. diff --git a/prepare-release.sh b/prepare-release.sh new file mode 100644 index 00000000..4ddfd746 --- /dev/null +++ b/prepare-release.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +set -e + +if [[ $(git rev-parse --abbrev-ref HEAD) != master ]]; then + echo Release version can be prepared automatically only from the master branch. + exit 0 +fi + +currentVersion=$(git describe --abbrev=0) +currentMajor=$(echo "$currentVersion" | cut -d. -f1) +currentMinor=$(echo "$currentVersion" | cut -d. -f2) +currentPatch=$(echo "$currentVersion" | cut -d. -f3) + +echo "Ruler $currentVersion:" + +PS3=$"What do you want to do? " +options=("Bump major" "Bump minor" "Bump patch" "Quit") +select option in "${options[@]}" +do + case $option in + "Bump major" ) + newVersion="$((currentMajor + 1)).0.0" + break ;; + "Bump minor" ) + newVersion="$currentMajor.$((currentMinor + 1)).0" + break ;; + "Bump patch" ) + newVersion="$currentMajor.$currentMinor.$((currentPatch + 1))" + break ;; + "Quit" ) + exit 0 ;; + * ) + echo "Invalid option '$REPLY'." + exit 0 ;; + esac +done + +function confirmBump { + read -rp "Bump version from $currentVersion to $newVersion? [Y/n] " choice + case "$choice" in + [nN][oO]|[n|N] ) echo 1 ;; + * ) echo 0 ;; + esac +} + +if [[ $(confirmBump) != 0 ]] ; then + echo "No" + exit 0 +else + echo "Yes" +fi + +# Replace current version in gradle.properties +propertiesFile="./gradle.properties" +versionNameKey="VERSION_NAME" +sed -i "" "s/.*$versionNameKey.*/$versionNameKey=$newVersion/g" $propertiesFile + +# Replace current version in changelog.md and update hyperlinks +changelogFile="./docs/changelog.md" +today=$(date +%F) +sed -i "" "s/## \[Unreleased\]/## \[Unreleased\]"$'\\\n\\\n'"## \[$newVersion\] - $today/g" $changelogFile +newVersionTag="[$newVersion]: https:\/\/github.com\/MiSikora\/Ruler\/releases\/tag\/$newVersion" +sed -i "" "s/$currentVersion...HEAD/$newVersion...HEAD"$'\\\n'"$newVersionTag""/g" $changelogFile + +# Replace current version in index.md +indexFile="./docs/index.md" +sed -i "" "s/$currentVersion/$newVersion/g" $indexFile + +# Replace current version in README.md +readmeFile="./README.md" +sed -i "" "s/$currentVersion/$newVersion/g" $readmeFile + +git reset &> /dev/null +git commit -am "Prepare for release $newVersion" &> /dev/null +git tag -a "$newVersion" -m "Version $newVersion" &> /dev/null + +# Update current version to a snapshot one +newMajor="$(cut -d"." -f1 <<<"$newVersion")" +newMinor="$(cut -d"." -f2 <<<"$newVersion")" +newPatch="$(cut -d"." -f3 <<<"$newVersion")" +newSnapshotVersion="$newMajor.$newMinor.$((newPatch + 1))-SNAPSHOT" +sed -i "" "s/.*$versionNameKey.*/$versionNameKey=$newSnapshotVersion/g" $propertiesFile + +git commit -am "Prepare next development version" &> /dev/null + +echo "\ +Version bumped successfully to $newVersion and commit is tagged. \ +Changes can be pushed to the origin."