diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..57e0f10 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,89 @@ +--- +name: Release + +on: + push: + tags: + - "v*.*.*" + +permissions: + contents: write + issues: read + pull-requests: read + +jobs: + ci: + uses: ./.github/workflows/ci.yaml + 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: + - 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"