From f016cf9aea4c63d2a315f74125591670fd64fd50 Mon Sep 17 00:00:00 2001 From: langua Date: Tue, 13 Aug 2024 14:14:18 +0200 Subject: [PATCH] (ci) add action workflow for autobuild and package publication --- .github/workflows/autobuild.yml | 31 +++++++++++++++++++ .github/workflows/package-pubilsh.yml | 43 +++++++++++++++++++++++++++ build.gradle.kts | 24 +++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 .github/workflows/autobuild.yml create mode 100644 .github/workflows/package-pubilsh.yml diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml new file mode 100644 index 0000000..8483729 --- /dev/null +++ b/.github/workflows/autobuild.yml @@ -0,0 +1,31 @@ +# ref: +# Writing Workflows: +# https://docs.github.com/en/actions/writing-workflows +# Setup Java JDK: +# https://github.com/marketplace/actions/setup-java-jdk +# And the github action env is clean by default so the project need to be pulled and checkout by job +# https://github.com/marketplace/actions/checkout +# otherwise there is nothing in the workspace folder (can also run git pull but this one make thing easy) +# @v4 seems like the latest version matches v4.x.x for a job +# +name: AutoBuilder +run-name: 'Auto build on ${{github.ref_type}} ${{github.ref_name}} #${{github.run_number}}' +on: [push] +jobs: + Build: + runs-on: ubuntu-latest + steps: + - name: setup jdk 21 + uses: actions/setup-java@v4 + with: + distribution: 'oracle' + java-version: '21' + - name: checkout repo + uses: actions/checkout@v4 + - name: build project with maven + run: mvn --batch-mode package + - name: upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{github.event.repository.name}}-autobuild-${{github.run_number}}-git-${{github.sha}}.zip + path: ./build/libs/*.jar diff --git a/.github/workflows/package-pubilsh.yml b/.github/workflows/package-pubilsh.yml new file mode 100644 index 0000000..9858d5c --- /dev/null +++ b/.github/workflows/package-pubilsh.yml @@ -0,0 +1,43 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path +# also ref: +# Publishing packages to GitHub Packages: +# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-github-packages +# +# Upgrade to Automatic token authentication, no need for personal access token anymore +# ref: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token +# + +name: Publish to GitHub Packages + +run-name: 'Package Publish #${{github.run_number}}' + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'oracle' + server-id: 'github-package' + + - name: Publish to GitHub Packages Apache Maven + run: ./gradle publish + env: + GITHUB_MAVEN_URL: https://maven.pkg.github.com/${{github.repository}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index c996806..de4ae26 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,8 @@ +import java.net.URI + plugins { id("java") + id("maven-publish") } group = "me.crafter.mc" @@ -24,4 +27,25 @@ dependencies { java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +publishing { + publications { + create("mavenJava") { + from(components["java"]) + groupId = project.group.toString() + artifactId = "lockettepro" + version = project.version.toString() + } + } + repositories { + maven { + name = "github-package" + url = URI(System.getenv("GITHUB_MAVEN_URL")) + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } } \ No newline at end of file