Skip to content

Commit

Permalink
GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski committed Sep 4, 2022
1 parent dcc8297 commit 360ca7c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 91 deletions.
98 changes: 34 additions & 64 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Build
on:
workflow_dispatch:
push:
paths-ignore:
- 'README.md'

jobs:
build:
Expand All @@ -15,82 +13,54 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Parse Changelog Entry
id: changelog
uses: coditory/changelog-parser@v1
- name: Get last version
id: lasttag

- name: Get versions
id: versions
shell: bash
run: echo ::set-output name=version::$(git describe --abbrev=0 --tags --match 'v[0-9]*' | cut -c2-)
run: |
declare -r VERSION="$((git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null || echo "v0.0.0") \
| cut -c2-)"
declare -r MAJOR="$(echo "$VERSION" | cut -d. -f1)"
declare -r MINOR="$(echo "$VERSION" | cut -d. -f2)"
declare -r PATCH="$(echo "$VERSION" | cut -d. -f3)"
declare -r NEXT_VERSION="$MAJOR.$MINOR.$(( $PATCH + 1 ))"
echo ::set-output name=version::$VERSION
echo ::set-output name=next_version::$NEXT_VERSION
echo -e "VERSION: $VERSION\nNEXT_VERSION: $NEXT_VERSION"
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache Gradle

- name: Cache gradle
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build with Gradle

- name: Build with gradle
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: ./gradlew build jacocoTestReport coveralls --scan
- name: Publish Reports Artifact
uses: actions/upload-artifact@v2
if: always()

- name: Create github release
uses: ncipollo/release-action@v1
if: "github.ref == 'refs/heads/master'"
with:
name: Reports
path: build/reports
- name: Release
if: "github.ref == 'refs/heads/master' && steps.changelog.outputs.version != steps.lasttag.outputs.version"
env:
PREV_VERSION: ${{ steps.lasttag.outputs.version }}
NEXT_VERSION: ${{ steps.changelog.outputs.version }}
allowUpdates: true
draft: true
generateReleaseNotes: true
tag: v${{ steps.versions.outputs.next_version }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish snapshot to maven central
if: "github.ref == 'refs/heads/master'"
shell: bash
run: |
git config user.name "Coditory CI"
git config user.email "Coditory CI <[email protected]>"
if [ -n "$PREV_VERSION" ]; then
declare -r ESC_PREV_VERSION="${PREV_VERSION//./\\.}"
sed -i "s|^ *version *= *${ESC_PREV_VERSION} *$|version=${NEXT_VERSION}|" gradle.properties
sed -i "s|${ESC_PREV_VERSION}|${NEXT_VERSION}|" README.md
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -a -m "Release v${NEXT_VERSION}" -m "[ci-skip]"
git push origin master
fi
fi
git tag -f "v${NEXT_VERSION}"
git push origin --tags
- name: Publish Snapshot
if: "github.ref != 'refs/heads/master'"
env:
PREV_VERSION: ${{ steps.lasttag.outputs.version }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew publishToSonatype -Pversion="${PREV_VERSION}-${GITHUB_REF#refs/heads/}-SNAPSHOT" -Ppublish
- name: Publish Release
if: "github.ref == 'refs/heads/master' && steps.changelog.outputs.version != steps.lasttag.outputs.version"
env:
NEXT_VERSION: ${{ steps.changelog.outputs.version }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Pversion=$NEXT_VERSION -Ppublish
- name: Publish GitHub Release
if: "github.ref == 'refs/heads/master' && steps.changelog.outputs.version != steps.lasttag.outputs.version"
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: ${{ steps.changelog.outputs.description }}
tag_name: v${{ steps.changelog.outputs.version }}
release_name: Release v${{ steps.changelog.outputs.version }}
run: echo ">>> Publish Snapshot ${{ steps.versions.outputs.next_version }}-SNAPSHOT"
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/')
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin

- name: Publish release
if: startsWith(github.ref, 'refs/tags/v')
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: |
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Pversion=${GITHUB_REF#refs/tags/v} -Ppublish
echo "Published release: ${GITHUB_REF#refs/tags/v}"
- name: Publish snapshot
if: startsWith(github.ref, 'refs/heads/')
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: |
declare -r VERSION="$(git describe --abbrev=0 --tags --match 'v[0-9]*' 2>/dev/null || echo "v0.0.0" | cut -c2-)"
declare -r MAJOR="$(echo "$VERSION" | cut -d. -f1)"
declare -r MINOR="$(echo "$VERSION" | cut -d. -f2)"
declare -r PATCH="$(echo "$VERSION" | cut -d. -f3)"
declare -r NEXT_VERSION="$MAJOR.$MINOR.$(( $PATCH + 1 ))"
./gradlew publishToSonatype -Pversion="${NEXT_VERSION}-${GITHUB_REF#refs/heads/}-SNAPSHOT" -Ppublish
echo "Published snapshot: ${NEXT_VERSION}-${GITHUB_REF#refs/heads/}-SNAPSHOT"
25 changes: 0 additions & 25 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Add to your `build.gradle`:

```gradle
dependencies {
implementation "com.coditory.quark:quark-config:0.1.2"
implementation "com.coditory.quark:quark-config:<VERSION>"
}
```

Expand Down
1 change: 0 additions & 1 deletion gradle.properties

This file was deleted.

0 comments on commit 360ca7c

Please sign in to comment.