diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9ffa0a9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,133 @@ +name: Build +'on': + pull_request: + branches: + - main + - develop + push: + branches: + - main + - develop + - release/** +permissions: + contents: write +jobs: + version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.gitversion.outputs.semVer }} + versionCode: ${{ steps.run_number.outputs.versionCode }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.9.6 + with: + versionSpec: 5.x + - id: gitversion + name: Use GitVersion + uses: gittools/actions/gitversion/execute@v0.9.6 + with: + useConfigFile: true + configFilePath: ./gitversion.yml + - name: Display SemVer + run: 'echo "SemVer: ${{ steps.gitversion.outputs.semVer }}"' + build: + needs: + - version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: temurin + - name: Build with Gradle + env: + ORG_GRADLE_PROJECT_version: ${{ needs.version.outputs.version }} + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build + - name: Rename AAR + run: mv ./build/libs/jlemmy-${{ needs.version.outputs.version }}.jar ./jlemmy.jar + - uses: actions/upload-artifact@master + with: + name: jlemmy-jar + path: ./jlemmy.jar + release: + permissions: + contents: write + needs: + - version + if: github.event_name != 'pull_request' + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - id: create_release + name: Create Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: v${{ needs.version.outputs.version }} + name: Release ${{ needs.version.outputs.version }} + draft: false + prerelease: ${{ github.ref != 'refs/heads/main' }} + publish-release: + needs: + - version + - release + - build + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@master + with: + name: jlemmy-jar + path: ./ + - name: Upload Artifact to Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ needs.release.outputs.upload_url }} + asset_path: ./jlemmy.jar + asset_name: jlemmy-v${{ needs.version.outputs.version }}.jar + asset_content_type: application/zip + publish-sonatype: + permissions: + contents: read + needs: + - version + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: temurin + - name: Build with Gradle + env: + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} + ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SECRET }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PGP_PASSPHRASE }} + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: |- + -Pversion=${{ needs.version.outputs.version }} + -Ppom.url="https://github.com/${{ github.repository }}" + -Ppom.scm.connection="scm:git:git://github.com/${{ github.repository }}" + -Ppom.scm.developerConnection="scm:git:ssh://github.com/${{ github.repository }}" + -Ppom.scm.url="https://github.com/${{ github.repository }}" + publishToCentralPortal --no-daemon diff --git a/.github/workflows/pkl b/.github/workflows/pkl new file mode 160000 index 0000000..34d9416 --- /dev/null +++ b/.github/workflows/pkl @@ -0,0 +1 @@ +Subproject commit 34d9416df0e00f320eb9fae5f0c7acefe26780ac diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f05e650 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test +'on': + pull_request: + branches: + - main + - develop + push: + branches: + - main + - develop + - release/** +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: temurin + - name: Test with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: test diff --git a/.github/workflows/update-types.pkl b/.github/workflows/update-types.pkl new file mode 100644 index 0000000..222e1ed --- /dev/null +++ b/.github/workflows/update-types.pkl @@ -0,0 +1,62 @@ +extends "pkl/src/base.pkl" +import "pkl/src/common.pkl" + +name = "Update" + +on = new On { + schedule = new Schedule { + cron = "* * * * Sun" + } + workflow_dispatch = new WorkflowDispatch {} +} + +permissions = new Mapping { + ["contents"] = "write" +} + +jobs = new Mapping { + ["update-types"] = new Job { + steps = new Listing { + common.checkout + new CommandStep { + name = "Update submodules" + run = """ + git pull --recurse-submodules + git submodule update --remote --recursive type-generator/lemmy-js-client + """ + } + new ActionStep { + name = "Setup python" + uses = "actions/setup-python@v3" + with = new Mapping { + ["python-version"] = "3.11" + } + } + new CommandStep { + name = "Install dependencies" + run = """ + pip install -r requirements.txt + """ + } + new CommandStep { + name = "Build new types" + run = """ + python type-generator/main.py + """ + } + new CommandStep { + id = "date" + name = "Get current date" + run = "echo \"::set-output name=date::$(date +'%Y%m%d-%s')\"" + } + new ActionStep { + name = "Create pull request" + uses = "peter-evans/create-pull-request@v6" + with = new Mapping { + ["branch"] = "update-types/feature/update-types-${{ steps.date.outputs.date }}" + ["name"] = "Update types from source" + } + } + } + } +}.toMap().filter((k,v) -> v != null).toMapping() \ No newline at end of file diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..b4da0b6 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,34 @@ +name: Update +'on': + schedule: + - cron: '* * * * Sun' + workflow_dispatch: {} +permissions: + contents: write +jobs: + update-types: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Update submodules + run: |- + git pull --recurse-submodules + git submodule update --remote --recursive type-generator/lemmy-js-client + - name: Setup python + uses: actions/setup-python@v3 + with: + python-version: '3.11' + - name: Install dependencies + run: pip install -r requirements.txt + - name: Build new types + run: python type-generator/main.py + - id: date + name: Get current date + run: echo "::set-output name=date::$(date +'%Y%m%d-%s')" + - name: Create pull request + uses: peter-evans/create-pull-request@v6 + with: + branch: update-types/feature/update-types-${{ steps.date.outputs.date }} + name: Update types from source diff --git a/.github/workflows/workflows.pkl b/.github/workflows/workflows.pkl new file mode 100644 index 0000000..0522eab --- /dev/null +++ b/.github/workflows/workflows.pkl @@ -0,0 +1,9 @@ +amends "pkl/render.pkl" + +workflows = new Listing { + (import("pkl/build.pkl")) { + projectName = "jlemmy" + } + import("pkl/test.pkl") + import("update-types.pkl") +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 84d8ca1..36b963d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ .mtj.tmp/ # Package Files # -*.jar *.war *.nar *.ear @@ -23,5 +22,6 @@ hs_err_pid* .idea/ -.gradle/ .DS_Store +build/ +.gradle/ diff --git a/.gitmodules b/.gitmodules index f7ec940..14f5bae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "type-generator/lemmy-js-client"] path = type-generator/lemmy-js-client url = https://github.com/LemmyNet/lemmy-js-client.git +[submodule ".github/workflows/pkl"] + path = .github/workflows/pkl + url = git@github.com:ComposeComponents/actions-java.git diff --git a/LICENSE.md b/LICENSE.md index 520d078..45930ce 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2024 Ben McLean +Copyright (c) 2024 Emily McLean Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e986eab..8cac106 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # jlemmy + +A Java client for Lemmy diff --git a/build-pkl.sh b/build-pkl.sh new file mode 100755 index 0000000..1a66774 --- /dev/null +++ b/build-pkl.sh @@ -0,0 +1,2 @@ +pkl eval -m .github/workflows .github/workflows/workflows.pkl +pkl eval -f yaml -o gitversion.yml gitversion.pkl \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4813459..1d82bac 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,10 @@ plugins { id 'java' + id 'net.thebugmc.gradle.sonatype-central-portal-publisher' version '1.2.3' } group = 'cl.emilym' -version = '1.0-SNAPSHOT' +description = "A Java Lemmy client" repositories { mavenCentral() @@ -19,4 +20,36 @@ dependencies { test { useJUnitPlatform() +} + +centralPortal { + username = findProperty("sonatypeUsername") + password = findProperty("sonatypePassword") + name = "jlemmy" + pom { + url = findProperty("pom.url") + licenses { + license { + name = findProperty("pom.license.name") + url = findProperty("pom.license.url") + } + } + developers { + developer { + name = findProperty("pom.developer.name") + email = findProperty("pom.developer.email") + } + } + scm { + connection = findProperty("pom.scm.connection") + developerConnection = findProperty("pom.scm.developerConnection") + url = findProperty("pom.scm.url") + } + } +} + +signing { + def signingKey = findProperty("signingKey") + def signingPassword = findProperty("signingPassword") + useInMemoryPgpKeys(signingKey, signingPassword) } \ No newline at end of file diff --git a/gitversion.pkl b/gitversion.pkl new file mode 100644 index 0000000..cd436f1 --- /dev/null +++ b/gitversion.pkl @@ -0,0 +1 @@ +amends "package://github.com/BenMMcLean/pkl-gitversion/releases/download/v0.1.1/pkl-gitversion@0.1.1#/default.pkl" \ No newline at end of file diff --git a/gitversion.yml b/gitversion.yml new file mode 100644 index 0000000..5216f76 --- /dev/null +++ b/gitversion.yml @@ -0,0 +1,113 @@ +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +mode: ContinuousDelivery +continuous-delivery-fallback-tag: ci +tag-prefix: (pre/)?[vV] +commit-date-format: yyyy-MM-dd +update-build-number: true +branches: + develop: + regex: ^develop$ + mode: ContinuousDeployment + tag: alpha + increment: Minor + prevent-increment-of-merged-branch-version: false + track-merge-target: true + tracks-release-branches: true + is-release-branch: false + is-mainline: false + pre-release-weight: 0 + main: + regex: ^master$|^main$ + source-branches: + - develop + - release + mode: ContinuousDelivery + tag: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + tracks-release-branches: false + is-release-branch: false + is-mainline: true + pre-release-weight: 55000 + release: + regex: ^releases?[/-] + source-branches: + - develop + - main + - support + - release + mode: ContinuousDelivery + tag: beta + increment: None + prevent-increment-of-merged-branch-version: true + track-merge-target: false + tracks-release-branches: false + is-release-branch: true + is-mainline: false + pre-release-weight: 30000 + feature: + regex: ^.*[/-]features?[/-] + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + mode: ContinuousDelivery + tag: useBranchName + increment: Inherit + prevent-increment-of-merged-branch-version: false + track-merge-target: false + tracks-release-branches: false + is-release-branch: false + is-mainline: false + pre-release-weight: 30000 + pull-request: + regex: '[/-](?\d+)' + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + mode: ContinuousDelivery + tag: PullRequest + increment: Inherit + prevent-increment-of-merged-branch-version: false + track-merge-target: false + tracks-release-branches: false + is-release-branch: false + is-mainline: false + pre-release-weight: 30000 + hotfix: + regex: ^.*[/-]hotfix(es)?[/-] + source-branches: + - develop + - main + - support + mode: ContinuousDelivery + tag: beta + increment: Patch + prevent-increment-of-merged-branch-version: false + track-merge-target: false + tracks-release-branches: false + is-release-branch: false + is-mainline: false + pre-release-weight: 30000 + support: + regex: ^.*[/-]support[/-] + source-branches: + - main + mode: ContinuousDelivery + tag: '' + increment: Patch + prevent-increment-of-merged-branch-version: true + track-merge-target: false + tracks-release-branches: false + is-release-branch: false + is-mainline: true + pre-release-weight: 55000 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/type-generator/requirements.txt b/type-generator/requirements.txt new file mode 100644 index 0000000..0faadab --- /dev/null +++ b/type-generator/requirements.txt @@ -0,0 +1,3 @@ +-i https://pypi.org/simple +tree-sitter==0.21.3 +tree-sitter-typescript==0.21.1