From cdbc62a019d9ab3a50b85fae6ae1ff6fd59e9933 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 23 Oct 2025 20:23:12 +0400 Subject: [PATCH 1/4] feat: another attempt at building tags and changelogs --- .github/workflows/prepare-release.yml | 146 ++++++++++++++++++++++++++ cliff.toml | 100 ++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 .github/workflows/prepare-release.yml create mode 100644 cliff.toml diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 00000000..0c6a6533 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,146 @@ +name: Prepare Release + +on: + workflow_dispatch: + inputs: + crate: + description: 'Crate to release' + required: true + type: choice + options: + - sentinel + - contributor-rewards + - doublezero-solana + - solana-validator-debt + version: + description: 'Version (e.g., 0.2.1 or 0.2.0-rc1)' + required: true + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + prepare-release: + runs-on: ubuntu-latest + steps: + - name: Validate version format + run: | + if ! echo "${{ github.event.inputs.version }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$'; then + echo "[ERROR] Invalid version format. Expected: X.Y.Z or X.Y.Z-rcN" + exit 1 + fi + + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install git-cliff + uses: taiki-e/install-action@git-cliff + + - name: Set up crate metadata + id: crate_meta + run: | + case "${{ github.event.inputs.crate }}" in + sentinel) + echo "crate_path=crates/sentinel" >> $GITHUB_OUTPUT + echo "tag_prefix=sentinel" >> $GITHUB_OUTPUT + echo "crate_name=sentinel" >> $GITHUB_OUTPUT + ;; + contributor-rewards) + echo "crate_path=crates/contributor-rewards" >> $GITHUB_OUTPUT + echo "tag_prefix=contributor-rewards" >> $GITHUB_OUTPUT + echo "crate_name=contributor-rewards" >> $GITHUB_OUTPUT + ;; + doublezero-solana) + echo "crate_path=crates/solana-cli" >> $GITHUB_OUTPUT + echo "tag_prefix=doublezero-solana" >> $GITHUB_OUTPUT + echo "crate_name=doublezero-solana" >> $GITHUB_OUTPUT + ;; + solana-validator-debt) + echo "crate_path=crates/validator-debt" >> $GITHUB_OUTPUT + echo "tag_prefix=solana-validator-debt" >> $GITHUB_OUTPUT + echo "crate_name=solana-validator-debt" >> $GITHUB_OUTPUT + ;; + *) + echo "[ERROR] Unknown crate: ${{ github.event.inputs.crate }}" + exit 1 + ;; + esac + + - name: Find previous tag + id: prev_tag + run: | + TAG_PREFIX="${{ steps.crate_meta.outputs.tag_prefix }}" + PREV_TAG=$(git tag --list "${TAG_PREFIX}/v*" --sort=-v:refname | head -n 1) + + if [ -z "$PREV_TAG" ]; then + echo "[WARN] No previous tag found for ${TAG_PREFIX}, using first commit" + PREV_TAG=$(git rev-list --max-parents=0 HEAD) + fi + + echo "prev_tag=${PREV_TAG}" >> $GITHUB_OUTPUT + echo "[OK] Previous tag: ${PREV_TAG}" + + - name: Generate changelog + run: | + TAG_PREFIX="${{ steps.crate_meta.outputs.tag_prefix }}" + VERSION="${{ github.event.inputs.version }}" + PREV_TAG="${{ steps.prev_tag.outputs.prev_tag }}" + CHANGELOG_PATH="${{ steps.crate_meta.outputs.crate_path }}/CHANGELOG.md" + + echo "[OK] Generating changelog for ${TAG_PREFIX}/v${VERSION}" + echo "[OK] Range: ${PREV_TAG}..HEAD" + + # Generate new changelog entry + git cliff \ + --config cliff.toml \ + --tag-pattern "${TAG_PREFIX}/v[0-9]*" \ + --tag "${TAG_PREFIX}/v${VERSION}" \ + --unreleased \ + --prepend "${CHANGELOG_PATH}" \ + "${PREV_TAG}..HEAD" + + echo "[OK] Changelog updated at ${CHANGELOG_PATH}" + + # Show diff for verification + git diff "${CHANGELOG_PATH}" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: | + chore(${{ steps.crate_meta.outputs.crate_name }}): prepare v${{ github.event.inputs.version }} release + + Update CHANGELOG.md for ${{ steps.crate_meta.outputs.crate_name }} v${{ github.event.inputs.version }} + branch: release/${{ steps.crate_meta.outputs.crate_name }}-v${{ github.event.inputs.version }} + delete-branch: true + title: "chore(${{ steps.crate_meta.outputs.crate_name }}): prepare v${{ github.event.inputs.version }} release" + body: | + ## Release Preparation for ${{ steps.crate_meta.outputs.crate_name }} v${{ github.event.inputs.version }} + + This PR updates the CHANGELOG.md for the upcoming release. + + ### Next Steps + 1. Review the changelog updates + 2. Merge this PR to main + 3. Create and push the release tag: + ```bash + git tag ${{ steps.crate_meta.outputs.tag_prefix }}/v${{ github.event.inputs.version }} + git push origin ${{ steps.crate_meta.outputs.tag_prefix }}/v${{ github.event.inputs.version }} + ``` + 4. The existing goreleaser workflow will automatically build and publish the release + + ### Changes + - Updated `${{ steps.crate_meta.outputs.crate_path }}/CHANGELOG.md` + + --- + *This PR was automatically generated by the [Prepare Release workflow](.github/workflows/prepare-release.yml)* + labels: | + release + changelog + assignees: ${{ github.actor }} diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000..3e99140d --- /dev/null +++ b/cliff.toml @@ -0,0 +1,100 @@ +[changelog] +# Changelog header +header = """ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +""" + +# Template for the changelog body +body = """ +{% if version %}\ +## [{{ version | trim_start_matches(pat="v") }}](https://github.com/doublezerofoundation/doublezero-offchain/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ +## [Unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} +### {{ group | upper_first }} +{% for commit in commits %} +- {{ commit.message | split(pat="\n") | first | trim }} +{% endfor %} +{% endfor %} + +""" + +# Template for the changelog footer (remove previous unreleased section) +footer = "" + +# Remove previous unreleased section when generating new release +trim = true + +[git] +# Parse commits based on conventional format, but include all commits +conventional_commits = true +filter_unconventional = false +split_commits = false + +# Protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false + +# Filter commits by matching regex +filter_commits = false + +# Tag pattern for matching tags (will be overridden in workflow for specific crates) +tag_pattern = "v[0-9]*" + +# Skip tags matching this pattern +skip_tags = "" + +# Ignore tags that don't follow semver +ignore_tags = "" + +# Date order for sorting tags +topo_order = false +sort_commits = "oldest" + +# Limit number of commits included in changelog +limit_commits = 0 + +# Commit preprocessors (regex-based modifications before parsing) +commit_preprocessors = [ + # Remove issue numbers from commit messages (currently disabled) + # { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, +] + +# Commit parsers to categorize commits +commit_parsers = [ + # Conventional commit parsers + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Fixed" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactoring" }, + # Skip maintenance and non-user-facing commits + { message = "^version [0-9]", skip = true }, + { message = "^style", skip = true }, + { message = "^test", skip = true }, + { message = "^chore\\(release\\)", skip = true }, + { message = "^chore\\(changelog\\)", skip = true }, + { message = "^chore\\(deps\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore", skip = true }, + { message = "^ci", skip = true }, + { message = "^docs", skip = true }, + { message = "^build", skip = true }, + # Catch-all for everything else + { message = ".*", group = "Other" }, +] + +# Link parsers to extract references +link_parsers = [ + # Parse GitHub issue/PR references + { pattern = "#(\\d+)", href = "https://github.com/doublezerofoundation/doublezero-offchain/pull/$1" }, +] + +[remote.github] +owner = "doublezerofoundation" +repo = "doublezero-offchain" From fe1c01e19e2997d3cd1467ffe1b58404e97b7145 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 23 Oct 2025 21:05:13 +0400 Subject: [PATCH 2/4] fix: address copilot cmt --- cliff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cliff.toml b/cliff.toml index 3e99140d..ce5c42a7 100644 --- a/cliff.toml +++ b/cliff.toml @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Template for the changelog body body = """ {% if version %}\ -## [{{ version | trim_start_matches(pat="v") }}](https://github.com/doublezerofoundation/doublezero-offchain/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} +## [{{ version | split(pat="/") | last | trim_start_matches(pat="v") }}](https://github.com/doublezerofoundation/doublezero-offchain/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} {% else %}\ ## [Unreleased] {% endif %}\ From 48f2833d46e304795be2cebf32a0a391f3caac9e Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 23 Oct 2025 21:18:37 +0400 Subject: [PATCH 3/4] fix: address another copilot cmt --- .github/workflows/prepare-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 0c6a6533..3dfac8ef 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -28,7 +28,7 @@ jobs: - name: Validate version format run: | if ! echo "${{ github.event.inputs.version }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$'; then - echo "[ERROR] Invalid version format. Expected: X.Y.Z or X.Y.Z-rcN" + echo "[ERROR] Invalid version format. Expected: X.Y.Z or X.Y.Z-rcN (where N is a number)" exit 1 fi From 6de9e671d930253d1870c1117ad5d3133bd863b4 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 23 Oct 2025 22:08:41 +0400 Subject: [PATCH 4/4] fix: one more copilot cmt --- cliff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cliff.toml b/cliff.toml index ce5c42a7..cc5daef4 100644 --- a/cliff.toml +++ b/cliff.toml @@ -43,7 +43,7 @@ protect_breaking_commits = false # Filter commits by matching regex filter_commits = false -# Tag pattern for matching tags (will be overridden in workflow for specific crates) +# Tag pattern for matching tags tag_pattern = "v[0-9]*" # Skip tags matching this pattern