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
6 changes: 4 additions & 2 deletions _integration-test/test_02_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from os.path import join
import subprocess

import pytest


def test_sentry_admin(setup_backup_restore_env_variables):
sentry_admin_sh = os.path.join(os.getcwd(), "sentry-admin.sh")
Expand All @@ -19,7 +21,7 @@ def test_sentry_admin(setup_backup_restore_env_variables):
).stdout
assert "Usage: ./sentry-admin.sh permissions" in output


@pytest.mark.skipif(os.environ.get("SKIP_BACKUP_RESTORE_TEST") == "true", reason="Skipping backup and restore tests as SKIP_BACKUP_RESTORE_TEST is set to true")
def test_01_backup(setup_backup_restore_env_variables):
# Docker was giving me permission issues when trying to create this file and write to it even after giving read + write access
# to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file
Expand All @@ -40,7 +42,7 @@ def test_01_backup(setup_backup_restore_env_variables):
)
assert os.path.getsize(file_path) > 0


@pytest.mark.skipif(os.environ.get("SKIP_BACKUP_RESTORE_TEST") == "true", reason="Skipping backup and restore tests as SKIP_BACKUP_RESTORE_TEST is set to true")
def test_02_import(setup_backup_restore_env_variables):
# Bring postgres down and recreate the docker volume
subprocess.run(["docker", "compose", "--ansi", "never", "down"], check=True)
Expand Down
32 changes: 27 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ inputs:
compose_profiles:
required: false
description: "Docker Compose profile to use. Defaults to feature-complete."
no_restore_volume_cache:
required: false
description: "Whether to restore Docker volumes cache after the test run. Defaults to false."
skip_backup_restore_test:
required: false
description: "Whether to skip backup and restore test. Defaults to false."
CODECOV_TOKEN:
required: false
description: "The Codecov token to upload coverage."
Expand All @@ -25,8 +31,20 @@ runs:
COMPOSE_PROFILES: ${{ inputs.compose_profiles }}
run: |
if [[ -n "$PROJECT_NAME" && -n "$IMAGE_URL" ]]; then
image_var=$(echo "${PROJECT_NAME}_IMAGE" | tr '[:lower:]' '[:upper:]')
echo "${image_var}=$IMAGE_URL" >> ${{ github.action_path }}/.env
readarray -t project_names <<<"$PROJECT_NAME"
readarray -t image_urls <<<"$IMAGE_URL"
Comment thread
sentry[bot] marked this conversation as resolved.
if [ "${#project_names[@]}" -ne "${#image_urls[@]}" ]; then
echo "The number of project names and image URLs must match."
echo "project_name: $PROJECT_NAME, image_url: $IMAGE_URL"
exit 1
fi

for i in "${!project_names[@]}"; do
project="${project_names[$i]}"
image="${image_urls[$i]}"
image_var=$(echo "${project}_IMAGE" | tr '[:lower:]' '[:upper:]')
echo "${image_var}=${image}" >> ${{ github.action_path }}/.env
done
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing newline causes empty element in readarray

Medium Severity

When callers pass multiline inputs using YAML | block scalar syntax (the standard way), the value includes a trailing newline. The <<< herestring adds another newline, so readarray -t produces an extra empty string element in both project_names and image_urls. The length check passes (both arrays have the same extra element), but the loop then writes a garbage _IMAGE= entry to the .env file. Using < <(printf '%s' "$PROJECT_NAME") instead of <<<"$PROJECT_NAME" would avoid this.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 404e19e. Configure here.

elif [[ -z "$PROJECT_NAME" && -z "$IMAGE_URL" ]]; then
echo "No project name and image URL set. Skipping image configuration."
else
Expand Down Expand Up @@ -101,6 +119,7 @@ runs:
echo "ARCH=$(uname -m)" >> $GITHUB_OUTPUT

- name: Restore Sentry Volume Cache
if: ${{ inputs.no_restore_volume_cache != 'true' }}
id: restore_cache_sentry
uses: BYK/docker-volume-cache-action/restore@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
Expand All @@ -111,6 +130,7 @@ runs:
sentry-postgres

- name: Restore Snuba Volume Cache
if: ${{ inputs.no_restore_volume_cache != 'true' }}
id: restore_cache_snuba
uses: BYK/docker-volume-cache-action/restore@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
Expand All @@ -121,6 +141,7 @@ runs:
sentry-clickhouse

- name: Restore Kafka Volume Cache
if: ${{ inputs.no_restore_volume_cache != 'true' }}
id: restore_cache_kafka
uses: BYK/docker-volume-cache-action/restore@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
Expand Down Expand Up @@ -155,23 +176,23 @@ runs:
./install.sh --no-report-self-hosted-issues --skip-commit-check

- name: Save Sentry Volume Cache
if: steps.restore_cache_sentry.outputs.cache-hit != 'true'
if: steps.restore_cache_sentry.outputs.cache-hit != 'true' && inputs.no_restore_volume_cache != 'true'
uses: BYK/docker-volume-cache-action/save@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
key: ${{ steps.restore_cache_sentry.outputs.cache-primary-key }}
volumes: |
sentry-postgres

- name: Save Snuba Volume Cache
if: steps.restore_cache_snuba.outputs.cache-hit != 'true'
if: steps.restore_cache_snuba.outputs.cache-hit != 'true' && inputs.no_restore_volume_cache != 'true'
uses: BYK/docker-volume-cache-action/save@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
key: ${{ steps.restore_cache_snuba.outputs.cache-primary-key }}
volumes: |
sentry-clickhouse

- name: Save Kafka Volume Cache
if: steps.restore_cache_kafka.outputs.cache-hit != 'true'
if: steps.restore_cache_kafka.outputs.cache-hit != 'true' && inputs.no_restore_volume_cache != 'true'
uses: BYK/docker-volume-cache-action/save@0efa5cf5178c9906cb46ed8d1a357df8fd6b1a06
with:
key: ${{ steps.restore_cache_kafka.outputs.cache-primary-key }}
Expand Down Expand Up @@ -204,6 +225,7 @@ runs:
shell: bash
env:
COMPOSE_PROFILES: ${{ inputs.compose_profiles }}
SKIP_BACKUP_RESTORE_TEST: ${{ inputs.skip_backup_restore_test }}
run: |
sudo chown root /usr/bin/rsync && sudo chmod u+s /usr/bin/rsync
rsync -aW --super --numeric-ids --no-compress --mkpath \
Expand Down
Loading