Release #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: Release version, for example 0.1.0 | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_version: ${{ steps.version.outputs.value }} | |
| released_sha: ${{ steps.release-sha.outputs.value }} | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyPassword }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| cache: gradle | |
| - name: Set up Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Resolve release version | |
| id: version | |
| shell: bash | |
| run: | | |
| if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | |
| version="${GITHUB_REF_NAME#v}" | |
| else | |
| version="${{ inputs.release_version }}" | |
| fi | |
| if [[ -z "${version}" ]]; then | |
| echo "release version is required" >&2 | |
| exit 1 | |
| fi | |
| echo "value=${version}" >> "${GITHUB_OUTPUT}" | |
| - name: Capture released commit SHA | |
| id: release-sha | |
| shell: bash | |
| run: | | |
| echo "value=${GITHUB_SHA}" >> "${GITHUB_OUTPUT}" | |
| - name: Normalize signing key | |
| shell: bash | |
| run: | | |
| if [[ -z "${ORG_GRADLE_PROJECT_signingInMemoryKey:-}" ]]; then | |
| echo "signing key is not set" >&2 | |
| exit 1 | |
| fi | |
| { | |
| echo "ORG_GRADLE_PROJECT_signingInMemoryKey<<EOF" | |
| printf '%b\n' "${ORG_GRADLE_PROJECT_signingInMemoryKey}" | |
| echo "EOF" | |
| } >> "${GITHUB_ENV}" | |
| - name: Publish to Maven Central | |
| run: > | |
| ./gradlew --no-daemon --console=plain | |
| -PreleaseVersion=${{ steps.version.outputs.value }} | |
| :lightrag-core:publishAndReleaseToMavenCentral | |
| :lightrag-spring-boot-starter:publishAndReleaseToMavenCentral | |
| - name: Create or update GitHub Release | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_VERSION: ${{ steps.version.outputs.value }} | |
| RELEASED_SHA: ${{ steps.release-sha.outputs.value }} | |
| run: | | |
| tag="v${RELEASE_VERSION}" | |
| if gh release view "${tag}" >/dev/null 2>&1; then | |
| gh release edit "${tag}" \ | |
| --title "${tag}" \ | |
| --latest | |
| else | |
| gh release create "${tag}" \ | |
| --target "${RELEASED_SHA}" \ | |
| --title "${tag}" \ | |
| --generate-notes \ | |
| --latest | |
| fi | |
| bump-next-snapshot: | |
| needs: publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout default branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.repository.default_branch }} | |
| - name: Check whether released commit is the default branch head | |
| id: bump-guard | |
| shell: bash | |
| env: | |
| RELEASED_SHA: ${{ needs.publish.outputs.released_sha }} | |
| run: | | |
| default_branch_head_sha="$(git rev-parse HEAD)" | |
| echo "default_branch_head_sha=${default_branch_head_sha}" | |
| echo "released_sha=${RELEASED_SHA}" | |
| if [[ "${default_branch_head_sha}" == "${RELEASED_SHA}" ]]; then | |
| echo "should_bump=true" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "should_bump=false" >> "${GITHUB_OUTPUT}" | |
| fi | |
| - name: Compute next minor snapshot | |
| id: next-version | |
| if: steps.bump-guard.outputs.should_bump == 'true' | |
| shell: bash | |
| env: | |
| RELEASE_VERSION: ${{ needs.publish.outputs.release_version }} | |
| run: | | |
| if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
| echo "release version must match X.Y.Z, got: ${RELEASE_VERSION}" >&2 | |
| exit 1 | |
| fi | |
| major="${BASH_REMATCH[1]}" | |
| minor="${BASH_REMATCH[2]}" | |
| next_minor=$((minor + 1)) | |
| next_version="${major}.${next_minor}.0-SNAPSHOT" | |
| echo "value=${next_version}" >> "${GITHUB_OUTPUT}" | |
| - name: Update default project version | |
| if: steps.bump-guard.outputs.should_bump == 'true' | |
| shell: bash | |
| env: | |
| NEXT_VERSION: ${{ steps.next-version.outputs.value }} | |
| run: | | |
| python3 - <<'PY' | |
| from pathlib import Path | |
| import os | |
| path = Path("gradle.properties") | |
| next_version = os.environ["NEXT_VERSION"] | |
| lines = path.read_text().splitlines() | |
| updated = [] | |
| replaced = False | |
| for line in lines: | |
| if line.startswith("projectVersion="): | |
| updated.append(f"projectVersion={next_version}") | |
| replaced = True | |
| else: | |
| updated.append(line) | |
| if not replaced: | |
| updated.insert(0, f"projectVersion={next_version}") | |
| path.write_text("\n".join(updated) + "\n") | |
| PY | |
| - name: Commit next snapshot version | |
| if: steps.bump-guard.outputs.should_bump == 'true' | |
| shell: bash | |
| env: | |
| NEXT_VERSION: ${{ steps.next-version.outputs.value }} | |
| run: | | |
| if git diff --quiet -- gradle.properties; then | |
| echo "projectVersion already set to ${NEXT_VERSION}" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add gradle.properties | |
| git commit -m "chore: bump version to ${NEXT_VERSION}" | |
| git push origin HEAD:${{ github.event.repository.default_branch }} | |
| - name: Skip bump for non-default-branch release | |
| if: steps.bump-guard.outputs.should_bump != 'true' | |
| shell: bash | |
| run: | | |
| echo "released commit is not the default branch head; skipping main version bump" |