Skip to content

Commit 2fa1346

Browse files
feat: release pipeline
1 parent 2497e83 commit 2fa1346

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

.github/workflows/release.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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_tiny_test_build.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_tiny_test_build ./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@v1
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
with:
123+
token: ${{ secrets.GITHUB_TOKEN }}
124+
body: ${{ steps.create_changelog.outputs.content }}
125+
tag_name: ${{ steps.create_changelog.outputs.version }}
126+
files: pgcli_*
127+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)