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 f36fd67
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 284 deletions.
115 changes: 92 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
name: Build

on: [pull_request, push, workflow_dispatch]
on:
pull_request:
push:
workflow_dispatch:
release:
types: [published]

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
uses: actions/checkout@v3

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Setup JDK
uses: actions/setup-java@v4
Expand All @@ -37,7 +25,88 @@ 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: Import GPG Key
id: gpg
uses: crazy-max/ghaction-import-gpg@v5
if: |
github.repository == 'coditory/klog' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_committer_name: Coditory Bot
git_committer_email: [email protected]

- name: Publish Snapshot
if: github.repository == 'coditory/klog' && github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
env:
SIGNING_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: ./gradlew publishJvmPublicationToSnapshotRepository

- name: Publish Release
id: publish-release
if: github.repository == 'coditory/klog' && startsWith(github.ref, 'refs/tags/v') && (github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch')
env:
SIGNING_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
run: |
declare -r RELEASE_VERSION="$([[ "$RELEASE_TAG_NAME" =~ v.* ]] \
&& (echo "$TAG_NAME" | cut -c2-) \
|| echo "$TAG_NAME")"
declare -r VERSION_ARG="$([ -n "$RELEASE_VERSION" ] \
&& echo "-Pversion=$RELEASE_VERSION" \
|| echo "")"
./gradlew publishJvmPublicationToReleaseRepository $VERSION_ARG
- 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 }}
173 changes: 0 additions & 173 deletions .github/workflows/release.yml

This file was deleted.

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
Loading

0 comments on commit f36fd67

Please sign in to comment.