Skip to content

Commit

Permalink
build: Added github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lilmayu committed May 15, 2024
1 parent 563d66b commit 365f742
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: 'Build & Test'

on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
commit:
description: If the commit you want to test isn't the head of a branch, provide its SHA here
required: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Build
run: ./gradlew shadowJar
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Test
run: ./gradlew test
- name: Create badges dir if necessary
run: mkdir -p .github/badges
- name: Generate JaCoCo Badge
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
coverage-badge-filename: jacoco.svg
- name: Log coverage percentage
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Check if there are any changes
id: verify_diff
run: |
git diff --quiet .github/badges/jacoco.svg || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit badge
if: steps.verify_diff.outputs.changed == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .github/badges/jacoco.svg
git commit -m "Add/Update Jacoco badge"
- name: Push badge commit
if: steps.verify_diff.outputs.changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.extract_branch.outputs.branch }}
42 changes: 42 additions & 0 deletions .github/workflows/publish-github-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'Publish to GitHub Releases'

on:
push:
tags:
- '**'
workflow_dispatch:

permissions:
contents: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Test
run: ./gradlew test
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Build
run: ./gradlew shadowJar
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
build/libs/java-discord-oauth2-api-*.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/publish-mavencentral.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Publish to MavenCentral'

on:
push:
tags:
- '**'

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Test
run: ./gradlew test
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Publish, Close, and Release to MavenCentral
env:
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRHUSERNAME }}
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRHPASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SECRET }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew publishCloseAndRelease

0 comments on commit 365f742

Please sign in to comment.