Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PG-1095 Add format validation CI workflow and format sources #308

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
113 changes: 113 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Checks
on:
pull_request:

jobs:
# cppcheck:
# name: Cppcheck
# runs-on: ubuntu-22.04
# timeout-minutes: 5

# steps:
# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y libcurl4-openssl-dev

# - name: Checkout sources
# uses: actions/checkout@v4
# with:
# path: src/pg_tde

# - name: Configure pg_tde
# run: ./configure
# working-directory: src/pg_tde

# - name: Checkout cppcheck sources
# uses: actions/checkout@v4
# with:
# repository: "danmar/cppcheck"
# ref: "2.13.4"
# path: src/cppcheck

# - name: Build and install cppcheck
# working-directory: src/cppcheck
# run: |
# mkdir build
# cd build
# cmake ..
# cmake --build .
# sudo cmake --install .

# - name: Execute linter check with cppcheck
# working-directory: src/pg_tde
# run: |
# set -x
# cppcheck --enable=all --inline-suppr --template='{file}:{line},{severity},{id},{message}' --error-exitcode=1 --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unmatchedSuppression:pg_tde.c --check-config .

format:
name: Format
runs-on: ubuntu-22.04
timeout-minutes: 5

steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev

- name: Clone postgres repository
uses: actions/checkout@v4
with:
repository: 'postgres/postgres'
ref: 'REL_17_STABLE'

- name: Checkout sources
uses: actions/checkout@v4
with:
path: 'contrib/pg_tde'

- name: Configure postgres
run: ./configure

- name: Configure pg_tde
run: ./configure
working-directory: contrib/pg_tde

- name: Install perltidy
run: sudo cpan -T SHANCOCK/Perl-Tidy-20230309.tar.gz

- name: Install pg_bsd_indent
working-directory: src/tools/pg_bsd_indent
run: sudo make install

- name: Add pg_bsd_indent and pgindent to path
run: |
echo "/usr/local/pgsql/bin" >> $GITHUB_PATH
echo "${{ github.workspace }}/src/tools/pgindent" >> $GITHUB_PATH

- name: Format sources
working-directory: contrib/pg_tde
run: |
make update-typedefs
make indent

- name: Check files are formatted and no source code changes
working-directory: contrib/pg_tde
run: |
git status
git diff --exit-code

# license:
# name: License
# runs-on: ubuntu-22.04
# timeout-minutes: 5

# steps:
# - name: Checkout sources
# uses: actions/checkout@v4

# - name: Check license headers
# uses: apache/skywalking-eyes/[email protected]
# with:
# token: "" # Prevent comments
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ __pycache__
/autom4te.cache
/configure~
t/results

# tools files
typedefs-full.list
11 changes: 11 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ include $(top_srcdir)/contrib/contrib-global.mk
endif

override SHLIB_LINK += @tde_LDFLAGS@ -lcrypto -lssl

# Fetches typedefs list for PostgreSQL core and merges it with typedefs defined in this project.
# https://wiki.postgresql.org/wiki/Running_pgindent_on_non-core_code_or_development_code
update-typedefs:
wget -q -O - "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?branch=REL_17_STABLE" | cat - typedefs.list | sort | uniq > typedefs-full.list

# Indents projects sources.
indent:
pgindent --typedefs=typedefs-full.list .

.PHONY: update-typedefs indent
58 changes: 30 additions & 28 deletions src/access/pg_tde_ddl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,39 @@
static object_access_hook_type prev_object_access_hook = NULL;

static void tdeheap_object_access_hook(ObjectAccessType access, Oid classId,
Oid objectId, int subId, void *arg);
Oid objectId, int subId, void *arg);

void SetupTdeDDLHooks(void)
void
SetupTdeDDLHooks(void)
{
prev_object_access_hook = object_access_hook;
object_access_hook = tdeheap_object_access_hook;
prev_object_access_hook = object_access_hook;
object_access_hook = tdeheap_object_access_hook;
}

static void
tdeheap_object_access_hook(ObjectAccessType access, Oid classId, Oid objectId,
int subId, void *arg)
{
Relation rel = NULL;

if (prev_object_access_hook)
prev_object_access_hook(access, classId, objectId, subId, arg);

if (access == OAT_DROP && classId == RelationRelationId)
{
ObjectAccessDrop *drop_arg = (ObjectAccessDrop *) arg;
rel = relation_open(objectId, AccessShareLock);
}
if (rel != NULL)
{
if ((rel->rd_rel->relkind == RELKIND_RELATION ||
rel->rd_rel->relkind == RELKIND_TOASTVALUE ||
rel->rd_rel->relkind == RELKIND_MATVIEW) &&
(subId == 0) && is_tdeheap_rel(rel))
{
pg_tde_delete_key_map_entry(&rel->rd_locator);
}
relation_close(rel, AccessShareLock);
}
tdeheap_object_access_hook(ObjectAccessType access, Oid classId, Oid objectId,
int subId, void *arg)
{
Relation rel = NULL;

if (prev_object_access_hook)
prev_object_access_hook(access, classId, objectId, subId, arg);

if (access == OAT_DROP && classId == RelationRelationId)
{
ObjectAccessDrop *drop_arg = (ObjectAccessDrop *) arg;

rel = relation_open(objectId, AccessShareLock);
}
if (rel != NULL)
{
if ((rel->rd_rel->relkind == RELKIND_RELATION ||
rel->rd_rel->relkind == RELKIND_TOASTVALUE ||
rel->rd_rel->relkind == RELKIND_MATVIEW) &&
(subId == 0) && is_tdeheap_rel(rel))
{
pg_tde_delete_key_map_entry(&rel->rd_locator);
}
relation_close(rel, AccessShareLock);
}
}
Loading
Loading