Skip to content

Commit

Permalink
Add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogesaku committed Dec 29, 2023
1 parent 557c070 commit 9c38dd3
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 190 deletions.
75 changes: 54 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
name: Build

on: [pull_request, push, workflow_dispatch]
on: [ pull_request, push, workflow_dispatch ]

jobs:
deduplicate:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip.outputs.should_skip }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Skip duplicates and docs
id: skip
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
paths_ignore: '["**/README.md", "LICENSE", ".gitignore", ".editorconfig", ".idea/**"]'

build:
runs-on: ubuntu-latest
needs: deduplicate
if: "needs.pre_job.outputs.should_skip != 'true'"
timeout-minutes: 15
steps:
- name: Checkout
Expand All @@ -37,7 +20,57 @@ jobs:
cache: gradle
distribution: temurin

- name: Build with gradle
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
- name: Build
run: ./gradlew build

- name: Publish Test Report
if: success() || failure() # run this step even if previous step failed
uses: dorny/test-reporter@v1
with:
name: Kotest report
path: ./**/build/test-results/test/*.xml
reporter: java-junit

- name: Publish Coverage Report
uses: codecov/codecov-action@v3
if: github.repository == 'coditory/klog' && github.ref == 'refs/heads/main'
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
override_commit: ${{ github.event.workflow_run.head_sha }}
override_branch: ${{ github.event.workflow_run.head_branch }}
override_build: ${{ github.event.workflow_run.id }}
files: 'build/reports/kover/report.xml'

- name: Publish Snapshot
run: ./gradlew publishJvmPublicationToSnapshotsRepository
if: github.repository == 'coditory/klog' && github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')

- name: Publish Release
id: publish-release
run: ./gradlew publishJvmPublicationToReleasesRepository
if: github.repository == 'coditory/klog' && startsWith(github.ref, 'refs/tags/v') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')

- name: Generate Release Notes
id: generate-release-notes
if: steps.publish-release.conclusion == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
declare -r NOTES="$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/releases/generate-notes \
-f target_commitish='main' \
| jq -r '.body')"
declare -r ESCAPED="${NOTES//$'\n'/'%0A'}"
echo "notes=$ESCAPED" >> $GITHUB_OUTPUT
- name: Create github release (main only)
if: steps.generate-release-notes.conclusion == 'success'
uses: ncipollo/release-action@v1
with:
allowUpdates: true
body: ${{ steps.notes.outputs.notes }}
tag: v${{ steps.versions.outputs.next_version }}
token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Dependabot

on: [ pull_request_target ]

jobs:
dependabot:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]'
permissions:
pull-requests: write
contents: write
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/[email protected]

- name: Enable auto-merge for dependabot PRs
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Approve patch and minor updates
if: steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' || steps.dependabot-metadata.outputs.package-ecosystem == 'github-actions'
run: gh pr review $PR_URL --approve -b "Pull request **approved** because **it includes a patch or minor update**"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103 changes: 2 additions & 101 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,11 @@ on:
- SNAPSHOT
required: true
default: AUTO
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Validate build succeeded
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
declare -r BUILD_SUCCESS="$(gh api \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/actions/runs?status=success\&head_sha=${{ github.sha }} \
| jq 'limit(1; .workflow_runs[] | select(.name == "Build" and .conclusion == "success"))')"
if [ -z "$BUILD_SUCCESS" ]; then
echo "Commit did not pass Build!"
exit 1
fi
- name: Checkout
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -81,93 +66,9 @@ jobs:
git_committer_name: Coditory Bot
git_committer_email: [email protected]

- name: Update version in README (main only)
- name: Create Release Tag
if: steps.gpg.conclusion == 'success'
env:
PREV_VERSION: ${{ steps.versions.outputs.version }}
NEXT_VERSION: ${{ steps.versions.outputs.next_version }}
run: |
declare -r ESC_PREV_VERSION="${PREV_VERSION//./\\.}"
echo "Changing: $PREV_VERSION -> $NEXT_VERSION"
sed -i "s|${ESC_PREV_VERSION}|${NEXT_VERSION}|" README.md
sed -i "s|${ESC_PREV_VERSION}|${NEXT_VERSION}|" mkdocs.yml
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -a -m "Update version in docs $PREV_VERSION -> $NEXT_VERSION" -m "[ci skip]"
git push origin main
else
echo "Nothing changed. Skipping commit."
fi
- name: Setup JDK
if: inputs.publish != 'SKIP'
uses: actions/setup-java@v4
with:
java-version: 21
cache: gradle
distribution: temurin

- name: Publish release
if: |
github.event_name == 'release'
|| inputs.publish == 'RELEASE'
|| (inputs.publish == 'AUTO' && github.ref == 'refs/heads/main')
env:
NEXT_VERSION: ${{ steps.versions.outputs.next_version }}
SIGNING_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: |
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Pversion=$NEXT_VERSION -Ppublish --info
echo "Published release: $NEXT_VERSION"
- name: Generate release notes
id: notes
if: |
github.event_name != 'release'
&& github.ref == 'refs/heads/main'
&& inputs.publish != 'SNAPSHOT'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PREV_VERSION: ${{ steps.versions.outputs.version }}
NEXT_VERSION: ${{ steps.versions.outputs.next_version }}
run: |
declare -r NOTES="$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v$NEXT_VERSION" \
-f target_commitish='main' \
-f previous_tag_name="v$PREV_VERSION" \
| jq -r '.body')"
declare -r ESCAPED="${NOTES//$'\n'/'%0A'}"
echo "notes=$ESCAPED" >> $GITHUB_OUTPUT
- name: Create github release (main only)
if: steps.notes.conclusion == 'success'
uses: ncipollo/release-action@v1
with:
allowUpdates: true
body: ${{ steps.notes.outputs.notes }}
draft: ${{ inputs.publish == 'SKIP' }}
tag: v${{ steps.versions.outputs.next_version }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish snapshot
if: |
github.event_name == 'workflow_dispatch'
&& (
inputs.publish == 'SNAPSHOT'
|| inputs.publish == 'AUTO' && github.ref != 'refs/heads/main'
)
env:
NEXT_VERSION: ${{ steps.versions.outputs.next_version }}
SIGNING_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: |
declare -r MIDDLE="$([ "$GITHUB_REF" == "refs/heads/main" ] && echo "" || echo "-${GITHUB_REF#refs/heads/}")"
./gradlew publishToSonatype -Pversion="${NEXT_VERSION}${MIDDLE}-SNAPSHOT" -Ppublish
echo "Published snapshot: ${NEXT_VERSION}${MIDDLE}-SNAPSHOT"
git push origin master "v$NEXT_VERSION"
6 changes: 5 additions & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ repositories {
}

dependencies {
implementation(libs.gradle.kotlin.plugin)
implementation(libs.gradle.kotlin)
implementation(libs.gradle.ktlint)
implementation(libs.gradle.dokka)
implementation(libs.gradle.kover)
implementation(libs.gradle.testLogger)

compileOnly(files(libs::class.java.protectionDomain.codeSource.location))
}
36 changes: 0 additions & 36 deletions build-logic/src/main/kotlin/build.coverage.gradle.kts

This file was deleted.

1 change: 1 addition & 0 deletions build-logic/src/main/kotlin/build.kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("build.java")
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.dokka")
}

val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class)
Expand Down
2 changes: 0 additions & 2 deletions build-logic/src/main/kotlin/build.publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gradle.kotlin.dsl.accessors._65a529fd93476750f091a5ac34bc1965.javadoc

plugins {
`java-library`
`maven-publish`
Expand Down
2 changes: 2 additions & 0 deletions build-logic/src/main/kotlin/build.test.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
kotlin("jvm")
id("com.adarshr.test-logger")
id("org.jetbrains.kotlinx.kover")
}

val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class)
Expand Down
Loading

0 comments on commit 9c38dd3

Please sign in to comment.