Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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"
84 changes: 84 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -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 = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing s
trim = true
# postprocessors
postprocessors = [
# { pattern = '<REPO>', 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}](<REPO>/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 = "<!-- 0 -->🚀 Features" },
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
{ message = "^test", group = "<!-- 6 -->🧪 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 = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
{ message = ".*", group = "<!-- 10 -->💼 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"