Skip to content

Commit 784b277

Browse files
authored
Move to semver (#391)
1 parent ee1a1d8 commit 784b277

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

.github/workflows/package.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: package
22
on:
33
push:
44
branches: ['main']
5+
release:
6+
types: [published]
57
workflow_dispatch:
68

79
env:
@@ -90,6 +92,9 @@ jobs:
9092
attestations: write
9193
id-token: write
9294
steps:
95+
- name: Checkout repository
96+
uses: actions/checkout@v4
97+
9398
- name: Download digests
9499
uses: actions/download-artifact@v4
95100
with:
@@ -107,6 +112,17 @@ jobs:
107112
- name: Set up Docker Buildx
108113
uses: docker/setup-buildx-action@v3
109114

115+
- name: Check for git tag
116+
id: tag
117+
run: |
118+
TAG=$(git describe --exact-match --tags HEAD 2>/dev/null || echo "")
119+
echo "tag=$TAG" >> $GITHUB_OUTPUT
120+
if [ -n "$TAG" ]; then
121+
echo "Git tag found: $TAG"
122+
else
123+
echo "No git tag found for current commit"
124+
fi
125+
110126
- name: Docker meta
111127
id: meta
112128
uses: docker/metadata-action@v5
@@ -118,6 +134,7 @@ jobs:
118134
type=semver,pattern={{version}}
119135
type=semver,pattern={{major}}.{{minor}}
120136
type=sha,prefix={{branch}}-,format=short
137+
${{ steps.tag.outputs.tag && format('type=raw,value={0}', steps.tag.outputs.tag) || '' }}
121138
122139
- name: Create manifest list and push
123140
working-directory: ${{ runner.temp }}/digests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ perf.data.old
4848

4949
# Ignore generated bindings
5050
pgdog-plugin/src/bindings.rs
51+
local/

pgdog/src/admin/show_version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::util::pgdog_version;
2+
13
use super::{
24
prelude::{DataRow, Field, Protocol, RowDescription},
35
*,
@@ -16,10 +18,8 @@ impl Command for ShowVersion {
1618
}
1719

1820
async fn execute(&self) -> Result<Vec<Message>, Error> {
19-
let version = env!("GIT_HASH");
20-
2121
let mut dr = DataRow::new();
22-
dr.add(format!("PgDog v{}", version));
22+
dr.add(format!("PgDog {}", pgdog_version()));
2323

2424
Ok(vec![
2525
RowDescription::new(&[Field::text("version")]).message()?,

pgdog/src/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use pgdog::frontend::listener::Listener;
99
use pgdog::net;
1010
use pgdog::plugin;
1111
use pgdog::stats;
12+
use pgdog::util::pgdog_version;
1213
use tokio::runtime::Builder;
1314
use tracing::info;
1415

15-
use std::ops::Deref;
1616
use std::process::exit;
1717

1818
#[cfg(not(target_env = "msvc"))]
@@ -60,11 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6060
_ => (),
6161
}
6262

63-
info!(
64-
"🐕 PgDog v{} ({})",
65-
env!("GIT_HASH"),
66-
pgdog_plugin::comp::rustc_version().deref()
67-
);
63+
info!("🐕 PgDog {}", pgdog_version());
6864
let config = config::load(&args.config, &args.users)?;
6965

7066
// Get databases from environment or from --database-url args.

pgdog/src/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! What's a project without a util module.
22
33
use chrono::{DateTime, Local, Utc};
4+
use pgdog_plugin::comp;
45
use rand::{distributions::Alphanumeric, Rng};
56
use std::time::Duration; // 0.8
67

@@ -75,6 +76,16 @@ pub fn escape_identifier(s: &str) -> String {
7576
s.replace("\"", "\"\"")
7677
}
7778

79+
/// Get PgDog's version string.
80+
pub fn pgdog_version() -> String {
81+
format!(
82+
"v{} [main@{}, {}]",
83+
env!("CARGO_PKG_VERSION"),
84+
env!("GIT_HASH"),
85+
comp::rustc_version().to_string()
86+
)
87+
}
88+
7889
#[cfg(test)]
7990
mod test {
8091

0 commit comments

Comments
 (0)