diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a2edaa0 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: xemantic diff --git a/.github/scripts/update-readme-version.sh b/.github/scripts/update-readme-version.sh new file mode 100755 index 0000000..fcfdc8b --- /dev/null +++ b/.github/scripts/update-readme-version.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# +# Copyright 2024 Kazimierz Pogoda / Xemantic +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Ensure VERSION environment variable is set +if [ -z "$VERSION" ]; then + echo "Error: VERSION environment variable is not set" + exit 1 +fi + +# Check if settings.gradle.kts exists +if [ ! -f "settings.gradle.kts" ]; then + echo "Error: settings.gradle.kts not found" + exit 1 +fi + +# Extract groupId and name from settings.gradle.kts +GROUP_ID=$(grep "val groupId = " settings.gradle.kts | sed -n 's/.*groupId = "\(.*\)".*/\1/p') +ARTIFACT_ID=$(grep "val name = " settings.gradle.kts | sed -n 's/.*name = "\(.*\)".*/\1/p') + +if [ -z "$GROUP_ID" ] || [ -z "$ARTIFACT_ID" ]; then + echo "Error: Could not extract groupId or name from settings.gradle.kts" + exit 1 +fi + +# Check if README.md exists +if [ ! -f "README.md" ]; then + echo "Error: README.md not found" + exit 1 +fi + +# Escape special characters in the group ID for sed +ESCAPED_GROUP_ID=$(echo "$GROUP_ID" | sed 's/\./\\./g') + +# Create the pattern to match +PATTERN="\"$ESCAPED_GROUP_ID:$ARTIFACT_ID:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" + +# Create the replacement string +REPLACEMENT="\"$GROUP_ID:$ARTIFACT_ID:$VERSION\"" + +# Check if the pattern exists in the file +if ! grep -q "$GROUP_ID:$ARTIFACT_ID:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" README.md; then + echo "Error: Dependency pattern not found in README.md" + exit 1 +fi + +# Perform the replacement and save to a temporary file +sed "s|$PATTERN|$REPLACEMENT|g" README.md > README.md.tmp + +# Check if sed made any changes +if cmp -s README.md README.md.tmp; then + echo "No version updates were needed" + rm README.md.tmp + exit 0 +fi + +# Move the temporary file back to the original +mv README.md.tmp README.md + +echo "Successfully updated version to $VERSION in README.md" diff --git a/.github/workflows/build-branch.yml b/.github/workflows/build-branch.yml new file mode 100644 index 0000000..41408dc --- /dev/null +++ b/.github/workflows/build-branch.yml @@ -0,0 +1,27 @@ +name: Build branch +on: + push: + branches-ignore: + - main + pull_request: + branches-ignore: + - main + +jobs: + build_branch: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4.2.2 + + - name: Setup Java + uses: actions/setup-java@v4.5.0 + with: + distribution: 'temurin' + java-version: 23 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4.2.1 + + - name: Build + run: ./gradlew build diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml new file mode 100644 index 0000000..f36cfce --- /dev/null +++ b/.github/workflows/build-main.yml @@ -0,0 +1,26 @@ +name: Build main +on: + push: + branches: + - main +jobs: + build_main: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4.2.2 + + - name: Setup Java + uses: actions/setup-java@v4.5.0 + with: + distribution: 'temurin' + java-version: 23 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4.2.1 + + - name: Build + run: ./gradlew build sourcesJar dokkaGeneratePublicationHtml publish + env: + ORG_GRADLE_PROJECT_githubActor: ${{ secrets.GITHUBACTOR }} + ORG_GRADLE_PROJECT_githubToken: ${{ secrets.GITHUBTOKEN }} diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..f5b8528 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,57 @@ +name: Build release +on: + release: + types: [published] +jobs: + build_release: + runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + steps: + - name: Write release version + run: | + VERSION=${GITHUB_REF_NAME#v} + echo Version: $VERSION + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Checkout sources + uses: actions/checkout@v4.2.2 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4.5.0 + with: + distribution: 'temurin' + java-version: 23 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4.2.1 + + - name: Build + env: + ORG_GRADLE_PROJECT_githubActor: ${{ secrets.GITHUBACTOR }} + ORG_GRADLE_PROJECT_githubToken: ${{ secrets.GITHUBTOKEN }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_sonatypeUser: ${{ secrets.SONATYPE_USER }} + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} + run: ./gradlew -Pversion=$VERSION build sourcesJar dokkaGeneratePublicationHtml publishToSonatype closeAndReleaseSonatypeStagingRepository + + - name: Checkout main branch + uses: actions/checkout@v4.2.2 + with: + ref: main + fetch-depth: 0 + + - name: Update README + run: sh .github/scripts/update-readme-version.sh + + - name: Commit README + uses: stefanzweifel/git-auto-commit-action@v5.0.1 + with: + commit_message: Dependency version in README.md updated to ${{ env.VERSION }} + file_pattern: 'README.md' diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml new file mode 100644 index 0000000..2e19eca --- /dev/null +++ b/.github/workflows/updater.yml @@ -0,0 +1,24 @@ +name: GitHub Actions Version Updater + +# Controls when the action will run. +on: + schedule: + # Automatically run on every Sunday + - cron: '0 0 * * 0' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Git checkout + uses: actions/checkout@v4.2.2 + with: + # [Required] Access token with `workflow` scope. + token: ${{ secrets.WORKFLOW_SECRET }} + + - name: Run GitHub Actions Version Updater + uses: saadmk11/github-actions-version-updater@v0.8.1 + with: + # [Required] Access token with `workflow` scope. + token: ${{ secrets.WORKFLOW_SECRET }}