diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cb99408 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 "action@github.com" + 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 }} \ No newline at end of file diff --git a/.github/workflows/publish-github-releases.yml b/.github/workflows/publish-github-releases.yml new file mode 100644 index 0000000..b3a7734 --- /dev/null +++ b/.github/workflows/publish-github-releases.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/publish-mavencentral.yml b/.github/workflows/publish-mavencentral.yml new file mode 100644 index 0000000..6a8d98d --- /dev/null +++ b/.github/workflows/publish-mavencentral.yml @@ -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 \ No newline at end of file