Skip to content

Commit c7aea51

Browse files
feat: release pipeline (#186)
1 parent 9f2108d commit c7aea51

File tree

2 files changed

+224
-0
lines changed

2 files changed

+224
-0
lines changed

β€Ž.github/workflows/release.yml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Release PG_CLI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
9+
env:
10+
# Ultimately, we shouldn't ignore warnings.
11+
# We need to pass it as an ENV because inlining doesn't work on Windows.
12+
RUSTFLAGS: -A dead_code
13+
# Need these guys for cross-compilation
14+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
15+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
16+
17+
jobs:
18+
build_and_test:
19+
name: Build & Test for ${{ matrix.config.target }}
20+
strategy:
21+
matrix:
22+
config:
23+
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
24+
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu }
25+
- { os: macos-latest, target: x86_64-apple-darwin }
26+
- { os: macos-latest, target: aarch64-apple-darwin }
27+
- { os: windows-latest, target: x86_64-pc-windows-msvc }
28+
- { os: windows-latest, target: aarch64-pc-windows-msvc }
29+
30+
runs-on: ${{ matrix.config.os }}
31+
32+
outputs:
33+
artifact_url: ${{ steps.upload-artifacts.outputs.artifact-url }}
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
with:
38+
submodules: true
39+
- uses: actions-rust-lang/setup-rust-toolchain@v1
40+
with:
41+
target: ${{ matrix.config.target }}
42+
43+
- uses: Swatinem/rust-cache@v2
44+
id: rust-cache
45+
46+
# The Aarch64 Linux is a special snowflake, we need to install its toolchain
47+
- name: Install arm64 toolchain
48+
if: matrix.config.target == 'aarch64-unknown-linux-gnu'
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y gcc-aarch64-linux-gnu
52+
53+
# running containers via `services` only works on linux
54+
# https://github.com/actions/runner/issues/1866
55+
- name: 🐘 Setup postgres
56+
uses: ikalnytskyi/action-setup-postgres@v7
57+
58+
- name: πŸ§ͺ Run Tests
59+
run: cargo test --release
60+
env:
61+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
62+
63+
- name: πŸ› οΈ Run Build
64+
run: cargo build -p pg_cli --release --target ${{ matrix.config.target }}
65+
66+
# windows is a special snowflake to, it saves binaries as .exe
67+
- name: πŸ‘¦ Name the Binary
68+
if: matrix.config.os == 'windows-latest'
69+
run: |
70+
mkdir dist
71+
cp target/${{ matrix.config.target }}/release/pg_cli.exe ./dist/pgcli_${{ matrix.config.target }}
72+
- name: πŸ‘¦ Name the Binary
73+
if: matrix.config.os != 'windows-latest'
74+
run: |
75+
mkdir dist
76+
cp target/${{ matrix.config.target }}/release/pg_cli ./dist/pgcli_${{ matrix.config.target }}
77+
78+
# It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other.
79+
# A common workaround is to upload and download the resulting artifacts.
80+
- name: πŸ‘† Upload Artifacts
81+
id: upload-artifacts
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: pgcli_${{ matrix.config.target }}
85+
path: ./dist/pgcli_*
86+
# The default compression level is 6; this took the binary down from 350 to 330MB.
87+
# It is recommended to use a lower level for binaries, since the compressed result is not much smaller,
88+
# and the higher levels of compression take much longer.
89+
compression-level: 2
90+
if-no-files-found: error
91+
92+
create_changelog_and_release:
93+
runs-on: ubuntu-latest
94+
needs: build_and_test # make sure that tests & build work correctly
95+
steps:
96+
- name: Checkout Repo
97+
uses: actions/checkout@v4
98+
with:
99+
# we need all commits to create a changelog
100+
fetch-depth: 0
101+
102+
- name: πŸ“ Create Changelog
103+
uses: orhun/git-cliff-action@v3
104+
id: create_changelog
105+
with:
106+
config: cliff.toml
107+
args: --bump --latest
108+
env:
109+
GITHUB_REPO: ${{ github.repository }}
110+
111+
- name: πŸ‘‡ Download Artifacts
112+
uses: actions/download-artifact@v4
113+
id: download
114+
with:
115+
merge-multiple: true
116+
pattern: pgcli_*
117+
118+
- name: πŸ“‚ Create Release
119+
uses: softprops/action-gh-release@v2
120+
id: create-release
121+
env:
122+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
with:
124+
token: ${{ secrets.GITHUB_TOKEN }}
125+
body: ${{ steps.create_changelog.outputs.content }}
126+
tag_name: ${{ steps.create_changelog.outputs.version }}
127+
files: pgcli_*
128+
fail_on_unmatched_files: true
129+
draft: true
130+
131+
- name: βœ… Output Link to Worflow Summary
132+
run: |
133+
{
134+
echo "# πŸš€ Release completed!"
135+
echo ""
136+
echo "Here is the URL to the Release Draft:"
137+
echo ""
138+
echo "[Link](${{ steps.create-release.outputs.url }})"
139+
echo ""
140+
} >> "$GITHUB_STEP_SUMMARY"

β€Žcliff.toml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# git-cliff ~ default configuration file
2+
# https://git-cliff.org/docs/configuration
3+
#
4+
# Lines starting with "#" are comments.
5+
# Configuration options are organized into tables and keys.
6+
# See documentation for more information on available options.
7+
8+
[changelog]
9+
# template for the changelog header
10+
header = """
11+
# Changelog\n
12+
All notable changes to this project will be documented in this file.\n
13+
"""
14+
# template for the changelog body
15+
# https://keats.github.io/tera/docs/#introduction
16+
body = """
17+
{% if version %}\
18+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
19+
{% else %}\
20+
## [unreleased]
21+
{% endif %}\
22+
{% for group, commits in commits | group_by(attribute="group") %}
23+
### {{ group | striptags | trim | upper_first }}
24+
{% for commit in commits %}
25+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
26+
{% if commit.breaking %}[**breaking**] {% endif %}\
27+
{{ commit.message | upper_first }}\
28+
{% endfor %}
29+
{% endfor %}\n
30+
"""
31+
# template for the changelog footer
32+
footer = """
33+
<!-- generated by git-cliff -->
34+
"""
35+
# remove the leading and trailing s
36+
trim = true
37+
# postprocessors
38+
postprocessors = [
39+
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
40+
]
41+
# render body even when there are no releases to process
42+
# render_always = true
43+
# output file path
44+
# output = "test.md"
45+
46+
[git]
47+
# parse the commits based on https://www.conventionalcommits.org
48+
conventional_commits = true
49+
# filter out the commits that are not conventional
50+
filter_unconventional = true
51+
# process each line of a commit as an individual commit
52+
split_commits = false
53+
# regex for preprocessing the commit messages
54+
commit_preprocessors = [
55+
# Replace issue numbers
56+
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
57+
# Check spelling of the commit with https://github.com/crate-ci/typos
58+
# If the spelling is incorrect, it will be automatically fixed.
59+
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
60+
]
61+
# regex for parsing and grouping commits
62+
commit_parsers = [
63+
{ message = "^feat", group = "<!-- 0 -->πŸš€ Features" },
64+
{ message = "^fix", group = "<!-- 1 -->πŸ› Bug Fixes" },
65+
{ message = "^doc", group = "<!-- 3 -->πŸ“š Documentation" },
66+
{ message = "^perf", group = "<!-- 4 -->⚑ Performance" },
67+
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
68+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
69+
{ message = "^test", group = "<!-- 6 -->πŸ§ͺ Testing" },
70+
{ message = "^chore\\(release\\): prepare for", skip = true },
71+
{ message = "^chore\\(deps.*\\)", skip = true },
72+
{ message = "^chore\\(pr\\)", skip = true },
73+
{ message = "^chore\\(pull\\)", skip = true },
74+
{ message = "^chore|^ci", group = "<!-- 7 -->βš™οΈ Miscellaneous Tasks" },
75+
{ body = ".*security", group = "<!-- 8 -->πŸ›‘οΈ Security" },
76+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
77+
{ message = ".*", group = "<!-- 10 -->πŸ’Ό Other" },
78+
]
79+
# filter out the commits that are not matched by commit parsers
80+
filter_commits = false
81+
# sort the tags topologically
82+
topo_order = false
83+
# sort the commits inside sections by oldest/newest order
84+
sort_commits = "oldest"

0 commit comments

Comments
Β (0)