|
| 1 | +name: Test OSS Helper |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + test_type: |
| 7 | + description: 'Type of test to run' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - 'basic-upload' |
| 12 | + - 'multiple-files' |
| 13 | + - 'directory-upload' |
| 14 | + - 'advanced-options' |
| 15 | + - 'dry-run' |
| 16 | + default: 'dry-run' |
| 17 | + region: |
| 18 | + description: 'OSS Region (e.g., oss-cn-hangzhou)' |
| 19 | + required: false |
| 20 | + default: 'oss-cn-hangzhou' |
| 21 | + bucket: |
| 22 | + description: 'OSS Bucket Name' |
| 23 | + required: false |
| 24 | + default: 'test-bucket' |
| 25 | + custom_assets: |
| 26 | + description: 'Custom assets (optional, for advanced testing)' |
| 27 | + required: false |
| 28 | + default: '' |
| 29 | + |
| 30 | +jobs: |
| 31 | + test: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Setup Node.js |
| 38 | + uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: '20' |
| 41 | + |
| 42 | + - name: Create test files |
| 43 | + run: | |
| 44 | + # Create test directory structure |
| 45 | + mkdir -p test-files/{docs,images,config} |
| 46 | +
|
| 47 | + # Create various test files |
| 48 | + echo "# Test README" > test-files/README.md |
| 49 | + echo "Test content for documentation" > test-files/docs/guide.md |
| 50 | + echo "Configuration file content" > test-files/config/app.json |
| 51 | + echo "Binary-like content" > test-files/images/logo.png |
| 52 | +
|
| 53 | + # Create a larger file for testing |
| 54 | + head -c 1024 /dev/urandom > test-files/large-file.bin |
| 55 | +
|
| 56 | + # Create files with special characters |
| 57 | + echo "Unicode test 中文测试" > "test-files/unicode-测试.txt" |
| 58 | + echo "Spaces in filename" > "test-files/file with spaces.txt" |
| 59 | +
|
| 60 | + echo "📁 Created test files:" |
| 61 | + find test-files -type f -exec ls -lh {} \; |
| 62 | +
|
| 63 | + - name: Test - Dry Run |
| 64 | + if: inputs.test_type == 'dry-run' |
| 65 | + uses: ./ |
| 66 | + with: |
| 67 | + region: ${{ inputs.region }} |
| 68 | + key-id: 'test-key-id' |
| 69 | + key-secret: 'test-key-secret' |
| 70 | + bucket: ${{ inputs.bucket }} |
| 71 | + assets: | |
| 72 | + test-files/README.md:docs/readme.md |
| 73 | + timeout: 60 |
| 74 | + continue-on-error: true |
| 75 | + env: |
| 76 | + # This will fail but test the action logic |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Test - Basic Upload (Dry Run) |
| 80 | + if: inputs.test_type == 'basic-upload' |
| 81 | + uses: ./ |
| 82 | + with: |
| 83 | + region: ${{ inputs.region }} |
| 84 | + key-id: ${{ secrets.OSS_KEY_ID || 'test-key' }} |
| 85 | + key-secret: ${{ secrets.OSS_KEY_SECRET || 'test-secret' }} |
| 86 | + bucket: ${{ inputs.bucket }} |
| 87 | + assets: | |
| 88 | + test-files/README.md:docs/readme.md |
| 89 | + timeout: 120 |
| 90 | + continue-on-error: true |
| 91 | + |
| 92 | + - name: Test - Multiple Files |
| 93 | + if: inputs.test_type == 'multiple-files' |
| 94 | + uses: ./ |
| 95 | + with: |
| 96 | + region: ${{ inputs.region }} |
| 97 | + key-id: ${{ secrets.OSS_KEY_ID || 'test-key' }} |
| 98 | + key-secret: ${{ secrets.OSS_KEY_SECRET || 'test-secret' }} |
| 99 | + bucket: ${{ inputs.bucket }} |
| 100 | + assets: | |
| 101 | + test-files/README.md:docs/readme.md |
| 102 | + test-files/docs/guide.md:documentation/guide.md |
| 103 | + test-files/config/app.json:config/application.json |
| 104 | + timeout: 180 |
| 105 | + continue-on-error: true |
| 106 | + |
| 107 | + - name: Test - Directory Upload |
| 108 | + if: inputs.test_type == 'directory-upload' |
| 109 | + uses: ./ |
| 110 | + with: |
| 111 | + region: ${{ inputs.region }} |
| 112 | + key-id: ${{ secrets.OSS_KEY_ID || 'test-key' }} |
| 113 | + key-secret: ${{ secrets.OSS_KEY_SECRET || 'test-secret' }} |
| 114 | + bucket: ${{ inputs.bucket }} |
| 115 | + assets: | |
| 116 | + test-files/:website/ |
| 117 | + timeout: 180 |
| 118 | + continue-on-error: true |
| 119 | + |
| 120 | + - name: Test - Advanced Options |
| 121 | + if: inputs.test_type == 'advanced-options' |
| 122 | + uses: ./ |
| 123 | + with: |
| 124 | + region: ${{ inputs.region }} |
| 125 | + key-id: ${{ secrets.OSS_KEY_ID || 'test-key' }} |
| 126 | + key-secret: ${{ secrets.OSS_KEY_SECRET || 'test-secret' }} |
| 127 | + bucket: ${{ inputs.bucket }} |
| 128 | + assets: | |
| 129 | + test-files/README.md:docs/readme.md |
| 130 | + test-files/large-file.bin:files/large.bin |
| 131 | + timeout: 300 |
| 132 | + max-retries: 5 |
| 133 | + enable-gzip: true |
| 134 | + public-read: true |
| 135 | + headers: '{"Cache-Control":"max-age=3600","Content-Type":"text/html"}' |
| 136 | + continue-on-error: true |
| 137 | + |
| 138 | + - name: Test - Custom Assets |
| 139 | + if: inputs.custom_assets != '' |
| 140 | + uses: ./ |
| 141 | + with: |
| 142 | + region: ${{ inputs.region }} |
| 143 | + key-id: ${{ secrets.OSS_KEY_ID || 'test-key' }} |
| 144 | + key-secret: ${{ secrets.OSS_KEY_SECRET || 'test-secret' }} |
| 145 | + bucket: ${{ inputs.bucket }} |
| 146 | + assets: ${{ inputs.custom_assets }} |
| 147 | + timeout: 180 |
| 148 | + continue-on-error: true |
| 149 | + |
| 150 | + - name: Display Results |
| 151 | + if: always() |
| 152 | + run: | |
| 153 | + echo "🧪 Test completed!" |
| 154 | + echo "📊 Test type: ${{ inputs.test_type }}" |
| 155 | + echo "🌏 Region: ${{ inputs.region }}" |
| 156 | + echo "🪣 Bucket: ${{ inputs.bucket }}" |
| 157 | +
|
| 158 | + if [ -n "${{ inputs.custom_assets }}" ]; then |
| 159 | + echo "📋 Custom assets: ${{ inputs.custom_assets }}" |
| 160 | + fi |
| 161 | +
|
| 162 | + echo "" |
| 163 | + echo "💡 To test with real credentials:" |
| 164 | + echo "1. Add OSS_KEY_ID and OSS_KEY_SECRET to repository secrets" |
| 165 | + echo "2. Use a real bucket name" |
| 166 | + echo "3. Re-run this workflow" |
| 167 | + echo "" |
| 168 | + echo "🔍 Check the action logs above for detailed results" |
0 commit comments