Skip to content

Commit

Permalink
Migrate to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MiSikora committed Nov 9, 2020
1 parent 46405c9 commit 58b2bc3
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 17 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
37 changes: 37 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
84 changes: 84 additions & 0 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 0 additions & 12 deletions RELEASING.md

This file was deleted.

File renamed without changes.
48 changes: 48 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -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.
88 changes: 88 additions & 0 deletions prepare-release.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 58b2bc3

Please sign in to comment.