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
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Date Release

on:
push:
branches:
- master

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # important to fetch all tags

- name: Generate version based on date
id: version
run: |
BASE_VERSION=$(date -u +'%Y.%-m.%-d')
echo "Base version: $BASE_VERSION"

# Fetch tags
git fetch --tags

# Find existing tags for today
MATCHING_TAGS=$(git tag -l "${BASE_VERSION}*")

if [ -z "$MATCHING_TAGS" ]; then
FINAL_VERSION=$BASE_VERSION
else
# Extract numeric suffixes
MAX_SUFFIX=$(echo "$MATCHING_TAGS" \
| grep -E "^${BASE_VERSION}-[0-9]+$" \
| sed -E "s/^${BASE_VERSION}-//" \
| sort -n \
| tail -n 1)

if [ -z "$MAX_SUFFIX" ]; then
FINAL_VERSION="${BASE_VERSION}-1"
else
NEXT=$((MAX_SUFFIX + 1))
FINAL_VERSION="${BASE_VERSION}-${NEXT}"
fi
fi

echo "Final version: $FINAL_VERSION"
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT

- name: Create tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag ${{ steps.version.outputs.version }}
git push origin ${{ steps.version.outputs.version }}

- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
22 changes: 10 additions & 12 deletions script/database-sync/database-sync.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/bash

set -e
set -o pipefail
set -euo pipefail

EXCLUDE_PARAMS=""
if [ -n "$SYNC_EXCLUDE_TABLES" ]; then
IFS=',' read -ra TABLES <<< "$SYNC_EXCLUDE_TABLES"
for table in "${TABLES[@]}"; do
table=$(echo "$table" | xargs)
if [ -n "$table" ]; then
EXCLUDE_PARAMS="$EXCLUDE_PARAMS --exclude-table=$table"
EXCLUDE_PARAMS="$EXCLUDE_PARAMS --exclude-table-data=$table"
fi
done
echo "Excluding tables: $SYNC_EXCLUDE_TABLES"
Expand All @@ -21,18 +20,17 @@ PGPASSWORD="$SYNC_SOURCE_PASSWORD" pg_dump \
-h "$SYNC_SOURCE_HOST" \
-p "$SYNC_SOURCE_PORT" \
-U "$SYNC_SOURCE_USER" \
--clean \
--if-exists \
--no-owner \
--no-acl \
--format plain \
$EXCLUDE_PARAMS \
"$SYNC_SOURCE_DATABASE" | \
PGPASSWORD="$SYNC_DEST_PASSWORD" psql \
-d "$SYNC_SOURCE_DATABASE" \
-Fc \
$EXCLUDE_PARAMS | \
PGPASSWORD="$SYNC_DEST_PASSWORD" pg_restore \
-h "$SYNC_DEST_HOST" \
-p "$SYNC_DEST_PORT" \
-U "$SYNC_DEST_USER" \
-d "$SYNC_DEST_DATABASE" \
--single-transaction
--clean \
--if-exists \
--no-owner \
--no-privileges

echo "Synchronization completed successfully: ${SYNC_SOURCE_DATABASE} -> ${SYNC_DEST_DATABASE}"
6 changes: 3 additions & 3 deletions script/database-sync/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ services:
container_name: database-sync
build: .
environment:
SYNC_SOURCE_HOST: "127.0.0.1"
SYNC_SOURCE_HOST: "172.26.136.2"
SYNC_SOURCE_PORT: "5432"
SYNC_SOURCE_USER: "postgres"
SYNC_SOURCE_PASSWORD: "masterkey"
SYNC_SOURCE_DATABASE: "herbario_prod"
SYNC_DEST_HOST: "127.0.0.1"
SYNC_DEST_HOST: "172.26.136.2"
SYNC_DEST_PORT: "5432"
SYNC_DEST_USER: "postgres"
SYNC_DEST_PASSWORD: "masterkey"
SYNC_DEST_DATABASE: "herbario_dev"
SYNC_EXCLUDE_TABLES: ""
SYNC_EXCLUDE_TABLES: "public.usuarios"
CRON_SCHEDULE: "*/2 * * * *"
TZ: "America/Sao_Paulo"
2 changes: 1 addition & 1 deletion script/database-sync/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

echo "Configuring cron job with schedule: $CRON_SCHEDULE (timezone: $TZ)"
echo "Configuring cron job with schedule: $CRON_SCHEDULE ($TZ)"

# ensure environment variables are passed to the cron job
printenv | grep -E "^SYNC_" >> /etc/environment
Expand Down
Loading