From 03070d7582a6303f03cee84154ccf1f06b560c2d Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Wed, 4 Jun 2025 16:25:03 +0100 Subject: [PATCH] feat: Create releases in CI (#2168) Fix: https://github.com/XRPLF/clio/issues/1779 --- .github/scripts/prepare-release-artifacts.sh | 24 +++++++ .github/workflows/nightly.yml | 10 ++- .github/workflows/nightly_notes.md | 7 -- .github/workflows/release.yml | 56 +++++++++++++++ .github/workflows/release_impl.yml | 71 +++++++++++++++----- cliff.toml | 17 +++-- 6 files changed, 157 insertions(+), 28 deletions(-) create mode 100755 .github/scripts/prepare-release-artifacts.sh delete mode 100644 .github/workflows/nightly_notes.md create mode 100644 .github/workflows/release.yml diff --git a/.github/scripts/prepare-release-artifacts.sh b/.github/scripts/prepare-release-artifacts.sh new file mode 100755 index 00000000..2267d8f9 --- /dev/null +++ b/.github/scripts/prepare-release-artifacts.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -ex -o pipefail + +BINARY_NAME="clio_server" + +ARTIFACTS_DIR="$1" +if [ -z "${ARTIFACTS_DIR}" ]; then + echo "Usage: $0 " + exit 1 +fi + +cd "${ARTIFACTS_DIR}" || exit 1 + +for artifact_name in $(ls); do + pushd "${artifact_name}" || exit 1 + zip -r "../${artifact_name}.zip" ./${BINARY_NAME} + popd || exit 1 + + rm "${artifact_name}/${BINARY_NAME}" + rm -r "${artifact_name}" + + sha256sum "./${artifact_name}.zip" > "./${artifact_name}.zip.sha256sum" +done diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e04ac807..66df39e0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -16,6 +16,7 @@ on: - ".github/actions/**" - "!.github/actions/code_coverage/**" + - .github/scripts/prepare-release-artifacts.sh concurrency: # Only cancel in-progress jobs or runs for the current workflow - matches against branch & tags @@ -96,7 +97,14 @@ jobs: overwrite_release: true title: "Clio development (nightly) build" version: nightly - notes_header_file: nightly_notes.md + header: > + # Release notes + + > **Note:** Please remember that this is a development release and it is not recommended for production use. + + Changelog (including previous releases): + generate_changelog: false + draft: false build_and_publish_docker_image: uses: ./.github/workflows/build_clio_docker_image.yml diff --git a/.github/workflows/nightly_notes.md b/.github/workflows/nightly_notes.md deleted file mode 100644 index 8f777788..00000000 --- a/.github/workflows/nightly_notes.md +++ /dev/null @@ -1,7 +0,0 @@ -# Release notes - -> **Note:** Please remember that this is a development release and it is not recommended for production use. - -Changelog (including previous releases): - -## SHA256 checksums diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2b351d70 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Create release + +on: + push: + tags: + - "*.*.*" + pull_request: + paths: + - .github/workflows/release.yml + +concurrency: + # Only cancel in-progress jobs or runs for the current workflow - matches against branch & tags + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-and-test: + name: Build and Test + + strategy: + fail-fast: false + matrix: + include: + - os: macos15 + conan_profile: default_apple_clang + build_type: Release + static: false + - os: heavy + conan_profile: gcc + build_type: Release + static: true + container: '{ "image": "ghcr.io/xrplf/clio-ci:latest" }' + + uses: ./.github/workflows/build_and_test.yml + with: + runs_on: ${{ matrix.os }} + container: ${{ matrix.container }} + conan_profile: ${{ matrix.conan_profile }} + build_type: ${{ matrix.build_type }} + static: ${{ matrix.static }} + run_unit_tests: true + run_integration_tests: true + upload_clio_server: true + disable_cache: true + + release: + needs: build-and-test + uses: ./.github/workflows/release_impl.yml + with: + overwrite_release: false + title: "${{ github.ref_name}}" + version: "${{ github.ref_name }}" + header: > + # Introducing Clio version ${{ github.ref_name }} + generate_changelog: true + draft: true diff --git a/.github/workflows/release_impl.yml b/.github/workflows/release_impl.yml index 08b8b666..2644b28f 100644 --- a/.github/workflows/release_impl.yml +++ b/.github/workflows/release_impl.yml @@ -18,14 +18,26 @@ on: required: true type: string - notes_header_file: - description: "Release notes header file" + header: + description: "Release notes header" required: true type: string + generate_changelog: + description: "Generate changelog" + required: false + type: boolean + + draft: + description: "Create a draft release" + required: false + type: boolean + jobs: release: - runs-on: ubuntu-latest + runs-on: heavy + container: + image: ghcr.io/xrplf/clio-ci:latest env: GH_REPO: ${{ github.repository }} GH_TOKEN: ${{ github.token }} @@ -35,29 +47,55 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Prepare runner + uses: ./.github/actions/prepare_runner + with: + disable_ccache: true - uses: actions/download-artifact@v4 with: path: release_artifacts pattern: clio_server_* - - name: Prepare files + - name: Create release notes + shell: bash + run: | + printf '%s\n' "${{ inputs.header }}" > "${RUNNER_TEMP}/release_notes.md" + + - name: Generate changelog + shell: bash + if: ${{ inputs.generate_changelog }} + run: | + LAST_TAG=$(gh release view --json tagName -q .tagName) + LAST_TAG_COMMIT=$(git rev-parse $LAST_TAG) + BASE_COMMIT=$(git merge-base HEAD $LAST_TAG_COMMIT) + git-cliff "${BASE_COMMIT}..HEAD" --ignore-tags "nightly|-b" + cat CHANGELOG.md >> "${RUNNER_TEMP}/release_notes.md" + + - name: Prepare release artifacts + shell: bash + run: .github/scripts/prepare-release-artifacts.sh release_artifacts + + - name: Append sha256 checksums shell: bash working-directory: release_artifacts run: | - cp ${{ github.workspace }}/.github/workflows/${{ inputs.notes_header_file }} "${RUNNER_TEMP}/release_notes.md" - echo '' >> "${RUNNER_TEMP}/release_notes.md" - echo '```' >> "${RUNNER_TEMP}/release_notes.md" + { + echo '## SHA256 checksums' + echo + echo '```' + cat *.sha256sum + echo '```' + } >> "${RUNNER_TEMP}/release_notes.md" - for d in $(ls); do - archive_name=$(ls $d) - mv ${d}/${archive_name} ./ - rm -r $d - sha256sum ./$archive_name > ./${archive_name}.sha256sum - cat ./$archive_name.sha256sum >> "${RUNNER_TEMP}/release_notes.md" - done - - echo '```' >> "${RUNNER_TEMP}/release_notes.md" + - name: Upload release notes + uses: actions/upload-artifact@v4 + with: + name: release_notes_${{ inputs.version }} + path: "${RUNNER_TEMP}/release_notes.md" - name: Remove current release and tag if: ${{ github.event_name != 'pull_request' && inputs.overwrite_release }} @@ -74,5 +112,6 @@ jobs: ${{ inputs.overwrite_release && '--prerelease' || '' }} \ --title "${{ inputs.title }}" \ --target $GITHUB_SHA \ + ${{ inputs.draft && '--draft' || '' }} \ --notes-file "${RUNNER_TEMP}/release_notes.md" \ ./release_artifacts/clio_server* diff --git a/cliff.toml b/cliff.toml index ef23ee83..755a5247 100644 --- a/cliff.toml +++ b/cliff.toml @@ -8,15 +8,24 @@ [changelog] # template for the changelog header header = """ -# Changelog\n -All notable changes to this project will be documented in this file.\n """ # template for the changelog body # https://keats.github.io/tera/docs/#introduction + body = """ {% if version %}\ - ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + Version {{ version | trim_start_matches(pat="v") }} of Clio, an XRP Ledger API server optimized for HTTP and WebSocket API calls, is now available. {% else %}\ + Clio, an XRP Ledger API server optimized for HTTP and WebSocket API calls, is under active development. +{% endif %}\ + + +This release adds new features and bug fixes. +This release adds bug fixes. +\ +{% if version %} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %} ## [unreleased] {% endif %}\ {% for group, commits in commits | filter(attribute="merge_commit", value=false) | group_by(attribute="group") %} @@ -24,7 +33,7 @@ body = """ {% for commit in commits %} - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ {% if commit.breaking %}[**breaking**] {% endif %}\ - {{ commit.message | upper_first }} {% if commit.remote.username %}by @{{ commit.remote.username }}{% endif %}\ + {{ commit.message | upper_first }}{% if commit.remote.username %} by @{{ commit.remote.username }}{% endif %}\ {% endfor %} {% endfor %}\n """