|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +# shellcheck source=./ci-utils.sh disable=SC1091 |
| 6 | +source "$SCRIPT_DIR/ci-utils.sh" |
| 7 | + |
| 8 | +OUTPUT_DIR="" |
| 9 | +INTEGRATION="" |
| 10 | +ALL=false |
| 11 | + |
| 12 | +INTEGRATIONS_DIR="3rd-party-integrations" |
| 13 | + |
| 14 | +ALL_DIR_NAMES="SentrySwiftLog SentrySwiftyBeaver SentryPulse SentryCocoaLumberjack" |
| 15 | + |
| 16 | +archive_name_for() { |
| 17 | + case "$1" in |
| 18 | + SentrySwiftLog) echo "sentry-apple-swift-log" ;; |
| 19 | + SentrySwiftyBeaver) echo "sentry-apple-swiftybeaver" ;; |
| 20 | + SentryPulse) echo "sentry-apple-pulse" ;; |
| 21 | + SentryCocoaLumberjack) echo "sentry-apple-cocoalumberjack" ;; |
| 22 | + *) echo "" ;; |
| 23 | + esac |
| 24 | +} |
| 25 | + |
| 26 | +usage() { |
| 27 | + cat <<EOF |
| 28 | +Usage: $(basename "$0") [options] |
| 29 | +
|
| 30 | +Create .tgz archives for 3rd-party integration distribution repos. |
| 31 | +Copies sources, tests, README, .gitignore, and LICENSE.md. |
| 32 | +
|
| 33 | +OPTIONS: |
| 34 | + --integration <name> Directory name under $INTEGRATIONS_DIR |
| 35 | + (e.g. SentrySwiftLog) |
| 36 | + --all Archive all integrations |
| 37 | + --output-dir <path> Directory to write archives to (default: repo root) |
| 38 | + -h, --help Show this help message |
| 39 | +
|
| 40 | +EXAMPLES: |
| 41 | + $(basename "$0") --all |
| 42 | + $(basename "$0") --integration SentrySwiftLog |
| 43 | + $(basename "$0") --all --output-dir XCFrameworkBuildPath |
| 44 | +
|
| 45 | +EOF |
| 46 | + exit 1 |
| 47 | +} |
| 48 | + |
| 49 | +while [[ $# -gt 0 ]]; do |
| 50 | + case $1 in |
| 51 | + --integration) INTEGRATION="$2"; shift 2 ;; |
| 52 | + --all) ALL=true; shift ;; |
| 53 | + --output-dir) OUTPUT_DIR="$2"; shift 2 ;; |
| 54 | + -h|--help) usage ;; |
| 55 | + *) log_error "Unknown option: $1"; usage ;; |
| 56 | + esac |
| 57 | +done |
| 58 | + |
| 59 | +if [ "$ALL" = false ] && [ -z "$INTEGRATION" ]; then |
| 60 | + log_error "Either --all or --integration <name> is required" |
| 61 | + usage |
| 62 | +fi |
| 63 | + |
| 64 | +REPO_ROOT="$SCRIPT_DIR/.." |
| 65 | + |
| 66 | +if [ -z "$OUTPUT_DIR" ]; then |
| 67 | + OUTPUT_DIR="$REPO_ROOT" |
| 68 | +fi |
| 69 | + |
| 70 | +mkdir -p "$OUTPUT_DIR" |
| 71 | + |
| 72 | +create_archive() { |
| 73 | + local dir_name="$1" |
| 74 | + local archive_name |
| 75 | + archive_name=$(archive_name_for "$dir_name") |
| 76 | + local src_dir="$REPO_ROOT/$INTEGRATIONS_DIR/$dir_name" |
| 77 | + |
| 78 | + if [ -z "$archive_name" ]; then |
| 79 | + log_error "Unknown integration: $dir_name" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + |
| 83 | + if [ ! -d "$src_dir" ]; then |
| 84 | + log_error "Directory not found: $src_dir" |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + |
| 88 | + local archive_file="$archive_name.tgz" |
| 89 | + local archive_path="$OUTPUT_DIR/$archive_file" |
| 90 | + |
| 91 | + begin_group "Create $archive_file" |
| 92 | + |
| 93 | + local staging_dir |
| 94 | + staging_dir=$(create_staging_dir) |
| 95 | + |
| 96 | + cp "$src_dir/Package.swift" "$staging_dir/Package.swift" |
| 97 | + cp "$src_dir/.gitignore" "$staging_dir/.gitignore" |
| 98 | + cp "$src_dir/README.md" "$staging_dir/README.md" |
| 99 | + cp "$REPO_ROOT/LICENSE.md" "$staging_dir/LICENSE.md" |
| 100 | + |
| 101 | + cp -R "$src_dir/Sources" "$staging_dir/Sources" |
| 102 | + cp -R "$src_dir/Tests" "$staging_dir/Tests" |
| 103 | + |
| 104 | + create_tgz_from_staging "$staging_dir" "$archive_path" |
| 105 | + |
| 106 | + end_group |
| 107 | +} |
| 108 | + |
| 109 | +if [ "$ALL" = true ]; then |
| 110 | + for dir_name in $ALL_DIR_NAMES; do |
| 111 | + create_archive "$dir_name" |
| 112 | + done |
| 113 | +else |
| 114 | + create_archive "$INTEGRATION" |
| 115 | +fi |
0 commit comments