From 28b72e975ee3d57af66ccc88f163be95dbd2756a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Sant=C3=A9?= <76043368+guilhem-sante@users.noreply.github.com> Date: Thu, 29 May 2025 13:48:34 +0200 Subject: [PATCH 1/2] ci(release): add github workflow to automatically update changelog and publish release --- .github/workflows/changelog.yaml | 51 ++++++++++++++++ .github/workflows/release.yaml | 96 +++++++++++++++++++++++++++++++ CHANGELOG.md | 0 cliff.toml | 99 ++++++++++++++++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 .github/workflows/changelog.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 CHANGELOG.md create mode 100644 cliff.toml diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 0000000..c151c05 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,51 @@ +--- +name: Update Changelog + +on: + workflow_call: + push: + branches: + - main + paths-ignore: + - CHANGELOG.md + +permissions: + contents: write + issues: read + pull-requests: read + +jobs: + update-changelog: + name: Update CHANGELOG.md + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate a changelog + uses: orhun/git-cliff-action@v4 + id: git-cliff + with: + config: cliff.toml + args: -vv + env: + OUTPUT: CHANGELOG.md + GITHUB_REPO: ${{ github.repository }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Commit & push changelog + run: | + if git diff --quiet; then + echo "No changes to CHANGELOG.md" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add CHANGELOG.md + git commit -m "docs(changelog): CHANGELOG.md automated update after push on main" + git push origin main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..09abce5 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,96 @@ +--- +name: Release + +on: + push: + tags: + - "v*.*.*" + +permissions: + contents: write + issues: read + pull-requests: read + +jobs: + ci: + uses: ./.github/workflows/ci.yaml + secrets: inherit + + update-changelog: + uses: ./.github/workflows/changelog.yaml + needs: + - ci + secrets: inherit + + generate-changelog: + name: Generate a changelog + runs-on: ubuntu-latest + needs: + - ci + outputs: + release_body: ${{ steps.git-cliff.outputs.content }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Generate a changelog + uses: orhun/git-cliff-action@v4 + id: git-cliff + with: + config: cliff.toml + args: -vv --latest --strip header + env: + OUTPUT: CHANGES.md + GITHUB_REPO: ${{ github.repository }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + build-publish: + name: Build and Publish release + needs: + - update-changelog + - generate-changelog + runs-on: ${{ matrix.build.os }} + strategy: + fail-fast: false + matrix: + build: + - name: linux-x64-glibc + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + steps: + - uses: actions/checkout@v4 + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ matrix.build.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Build binary + run: cargo build --release --locked --target ${{ matrix.build.target }} + - name: Set the release version + shell: bash + run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV + - name: Prepare release assets + run: | + mkdir -p release/ + cp {LICENSE,README.md,CHANGELOG.md} release/ + cp "target/${{ matrix.build.target }}/release/leetcode-cli" release/ + mv release/ leetcode-cli-${{ env.RELEASE_VERSION }}/ + - name: Create + shell: bash + run: | + tar -czvf leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz \ + leetcode-cli-${{ env.RELEASE_VERSION }}/ + shasum -a 512 leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz \ + > leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}.tar.gz.sha512 + - name: Upload the binary releases + id: upload-release + uses: softprops/action-gh-release@v2 + with: + files: | + leetcode-cli-${{ env.RELEASE_VERSION }}-${{ matrix.build.target }}* + body: ${{ needs.generate-changelog.outputs.release_body }} + draft: false + prerelease: false diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..713743d --- /dev/null +++ b/cliff.toml @@ -0,0 +1,99 @@ +[remote.github] +owner = "coding-kelps" +repo = "leetcode-cli" + +[changelog] +header = """ +# Changelog + +All notable changes to this project will be documented in this file. + +""" +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% macro print_commit(commit) -%} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }} - \ + ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\ +{% endmacro -%} + +{% if version %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}]\ + ({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ +{% else %}\ + ## [unreleased] +{% endif %}\ + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits + | filter(attribute="scope") + | sort(attribute="scope") %} + {{ self::print_commit(commit=commit) }} + {%- endfor %} + {% for commit in commits %} + {%- if not commit.scope -%} + {{ self::print_commit(commit=commit) }} + {% endif -%} + {% endfor -%} +{% endfor -%} +{%- if github -%} +{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} + ## New Contributors โค๏ธ +{% endif %}\ +{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %} + * @{{ contributor.username }} made their first contribution + {%- if contributor.pr_number %} in \ + [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \ + {%- endif %} +{%- endfor -%} +{%- endif %} + + +""" + +footer = """ + +""" +trim = true + +[contributors] +# drop any contributor whose username matches one of these literals or regexes +ignore = [ + "github-actions\\[bot\\]" +] + +[git] +conventional_commits = true +filter_unconventional = true +split_commits = false + +commit_parsers = [ + { field = "author.email", pattern = "github-actions\\[bot\\]@users.noreply.github.com", skip = true}, + { message = "^feat", group = "โ›ฐ๏ธ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^doc", group = "๐Ÿ“š Documentation" }, + { message = "^perf", group = "โšก Performance" }, + { message = "^refactor\\(clippy\\)", skip = true }, + { message = "^refactor", group = "๐Ÿšœ Refactor" }, + { message = "^style", group = "๐ŸŽจ Styling" }, + { message = "^test", group = "๐Ÿงช Testing" }, + { message = "^build", group = "๐Ÿ”จ Build" }, + { message = "^ci", group = "โš™๏ธ Miscellaneous Tasks" }, + { message = "^revert", group = "โ—€๏ธ Revert" }, +] +protect_breaking_commits = false +filter_commits = false +tag_pattern = "v[0-9].*" +skip_tags = "beta|alpha" +ignore_tags = "rc" +topo_order = false +sort_commits = "newest" From ba2eb642d9bae6b7d76c5de403aed529460be4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Sant=C3=A9?= <76043368+guilhem-sante@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:34:05 +0200 Subject: [PATCH 2/2] revert(changelog): remove changelog auto-update through GitHub Action --- .github/workflows/changelog.yaml | 51 -------------------------------- .github/workflows/release.yaml | 7 ----- 2 files changed, 58 deletions(-) delete mode 100644 .github/workflows/changelog.yaml diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml deleted file mode 100644 index c151c05..0000000 --- a/.github/workflows/changelog.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -name: Update Changelog - -on: - workflow_call: - push: - branches: - - main - paths-ignore: - - CHANGELOG.md - -permissions: - contents: write - issues: read - pull-requests: read - -jobs: - update-changelog: - name: Update CHANGELOG.md - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Generate a changelog - uses: orhun/git-cliff-action@v4 - id: git-cliff - with: - config: cliff.toml - args: -vv - env: - OUTPUT: CHANGELOG.md - GITHUB_REPO: ${{ github.repository }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Commit & push changelog - run: | - if git diff --quiet; then - echo "No changes to CHANGELOG.md" - exit 0 - fi - - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add CHANGELOG.md - git commit -m "docs(changelog): CHANGELOG.md automated update after push on main" - git push origin main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 09abce5..57e0f10 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,12 +16,6 @@ jobs: uses: ./.github/workflows/ci.yaml secrets: inherit - update-changelog: - uses: ./.github/workflows/changelog.yaml - needs: - - ci - secrets: inherit - generate-changelog: name: Generate a changelog runs-on: ubuntu-latest @@ -47,7 +41,6 @@ jobs: build-publish: name: Build and Publish release needs: - - update-changelog - generate-changelog runs-on: ${{ matrix.build.os }} strategy: