diff --git a/_integration-test/test_02_backup.py b/_integration-test/test_02_backup.py index ad42824524e..f8270c02e6f 100644 --- a/_integration-test/test_02_backup.py +++ b/_integration-test/test_02_backup.py @@ -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") @@ -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 @@ -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) diff --git a/action.yaml b/action.yaml index 532fabf509e..7e43f2c2333 100644 --- a/action.yaml +++ b/action.yaml @@ -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." @@ -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" + 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 elif [[ -z "$PROJECT_NAME" && -z "$IMAGE_URL" ]]; then echo "No project name and image URL set. Skipping image configuration." else @@ -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: @@ -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: @@ -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: @@ -155,7 +176,7 @@ 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 }} @@ -163,7 +184,7 @@ runs: 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 }} @@ -171,7 +192,7 @@ runs: 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 }} @@ -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 \