diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..cb246f938 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,140 @@ +name: Release PG_CLI + +on: + workflow_dispatch: + +permissions: + contents: write + +env: + # Ultimately, we shouldn't ignore warnings. + # We need to pass it as an ENV because inlining doesn't work on Windows. + RUSTFLAGS: -A dead_code + # Need these guys for cross-compilation + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc + +jobs: + build_and_test: + name: Build & Test for ${{ matrix.config.target }} + strategy: + matrix: + config: + - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu } + - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu } + - { os: macos-latest, target: x86_64-apple-darwin } + - { os: macos-latest, target: aarch64-apple-darwin } + - { os: windows-latest, target: x86_64-pc-windows-msvc } + - { os: windows-latest, target: aarch64-pc-windows-msvc } + + runs-on: ${{ matrix.config.os }} + + outputs: + artifact_url: ${{ steps.upload-artifacts.outputs.artifact-url }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: ${{ matrix.config.target }} + + - uses: Swatinem/rust-cache@v2 + id: rust-cache + + # The Aarch64 Linux is a special snowflake, we need to install its toolchain + - name: Install arm64 toolchain + if: matrix.config.target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu + + # running containers via `services` only works on linux + # https://github.com/actions/runner/issues/1866 + - name: ๐Ÿ˜ Setup postgres + uses: ikalnytskyi/action-setup-postgres@v7 + + - name: ๐Ÿงช Run Tests + run: cargo test --release + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres + + - name: ๐Ÿ› ๏ธ Run Build + run: cargo build -p pg_cli --release --target ${{ matrix.config.target }} + + # windows is a special snowflake to, it saves binaries as .exe + - name: ๐Ÿ‘ฆ Name the Binary + if: matrix.config.os == 'windows-latest' + run: | + mkdir dist + cp target/${{ matrix.config.target }}/release/pg_cli.exe ./dist/pgcli_${{ matrix.config.target }} + - name: ๐Ÿ‘ฆ Name the Binary + if: matrix.config.os != 'windows-latest' + run: | + mkdir dist + cp target/${{ matrix.config.target }}/release/pg_cli ./dist/pgcli_${{ matrix.config.target }} + + # It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other. + # A common workaround is to upload and download the resulting artifacts. + - name: ๐Ÿ‘† Upload Artifacts + id: upload-artifacts + uses: actions/upload-artifact@v4 + with: + name: pgcli_${{ matrix.config.target }} + path: ./dist/pgcli_* + # The default compression level is 6; this took the binary down from 350 to 330MB. + # It is recommended to use a lower level for binaries, since the compressed result is not much smaller, + # and the higher levels of compression take much longer. + compression-level: 2 + if-no-files-found: error + + create_changelog_and_release: + runs-on: ubuntu-latest + needs: build_and_test # make sure that tests & build work correctly + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + # we need all commits to create a changelog + fetch-depth: 0 + + - name: ๐Ÿ“ Create Changelog + uses: orhun/git-cliff-action@v3 + id: create_changelog + with: + config: cliff.toml + args: --bump --latest + env: + GITHUB_REPO: ${{ github.repository }} + + - name: ๐Ÿ‘‡ Download Artifacts + uses: actions/download-artifact@v4 + id: download + with: + merge-multiple: true + pattern: pgcli_* + + - name: ๐Ÿ“‚ Create Release + uses: softprops/action-gh-release@v2 + id: create-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ steps.create_changelog.outputs.content }} + tag_name: ${{ steps.create_changelog.outputs.version }} + files: pgcli_* + fail_on_unmatched_files: true + draft: true + + - name: โœ… Output Link to Worflow Summary + run: | + { + echo "# ๐Ÿš€ Release completed!" + echo "" + echo "Here is the URL to the Release Draft:" + echo "" + echo "[Link](${{ steps.create-release.outputs.url }})" + echo "" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..8656d82b2 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,84 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[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") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing s +trim = true +# postprocessors +postprocessors = [ + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL +] +# render body even when there are no releases to process +# render_always = true +# output file path +# output = "test.md" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # Replace issue numbers + #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, + # Check spelling of the commit with https://github.com/crate-ci/typos + # If the spelling is incorrect, it will be automatically fixed. + #{ pattern = '.*', replace_command = 'typos --write-changes -' }, +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "๐Ÿš€ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^doc", group = "๐Ÿ“š Documentation" }, + { message = "^perf", group = "โšก Performance" }, + { message = "^refactor", group = "๐Ÿšœ Refactor" }, + { message = "^style", group = "๐ŸŽจ Styling" }, + { message = "^test", group = "๐Ÿงช Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "โš™๏ธ Miscellaneous Tasks" }, + { body = ".*security", group = "๐Ÿ›ก๏ธ Security" }, + { message = "^revert", group = "โ—€๏ธ Revert" }, + { message = ".*", group = "๐Ÿ’ผ Other" }, +] +# filter out the commits that are not matched by commit parsers +filter_commits = false +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest"