From b10343fc3226852b0d72b2a7a691b9a226e823e0 Mon Sep 17 00:00:00 2001 From: Edvaldo Szymonek Date: Thu, 26 Feb 2026 13:32:49 -0300 Subject: [PATCH] cria tag e release automaticamente quando algo vai para master --- .github/workflows/release.yml | 65 +++++++++++++++++++++++++ script/database-sync/database-sync.sh | 22 ++++----- script/database-sync/docker-compose.yml | 6 +-- script/database-sync/entrypoint.sh | 2 +- 4 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..cbcb85f7 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/script/database-sync/database-sync.sh b/script/database-sync/database-sync.sh index 866b6bf6..a6b26e5a 100755 --- a/script/database-sync/database-sync.sh +++ b/script/database-sync/database-sync.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -e -set -o pipefail +set -euo pipefail EXCLUDE_PARAMS="" if [ -n "$SYNC_EXCLUDE_TABLES" ]; then @@ -9,7 +8,7 @@ if [ -n "$SYNC_EXCLUDE_TABLES" ]; then 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" @@ -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}" diff --git a/script/database-sync/docker-compose.yml b/script/database-sync/docker-compose.yml index 2aa8e08c..fbea10e4 100644 --- a/script/database-sync/docker-compose.yml +++ b/script/database-sync/docker-compose.yml @@ -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" diff --git a/script/database-sync/entrypoint.sh b/script/database-sync/entrypoint.sh index 69adea0f..52ec2108 100755 --- a/script/database-sync/entrypoint.sh +++ b/script/database-sync/entrypoint.sh @@ -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