|
| 1 | +name: Azure Storage Tests |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - '**' |
| 6 | + paths: |
| 7 | + - 'tests/integration/withServerInstance/storage.tests.js' |
| 8 | + - 'Common/sources/storage/**' |
| 9 | + - 'DocService/sources/routes/static.js' |
| 10 | + - '.github/workflows/azureStorageTests.yml' |
| 11 | + |
| 12 | +jobs: |
| 13 | + azure-storage-tests: |
| 14 | + name: Azure Storage Tests |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + AZURITE_CONTAINER: azurite-${{ github.run_id }}-${{ github.run_attempt }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Check out repository code |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Pre-run cleanup |
| 24 | + run: | |
| 25 | + docker rm -f "$AZURITE_CONTAINER" 2>/dev/null || true |
| 26 | +
|
| 27 | + - name: Setup and start Azurite |
| 28 | + run: | |
| 29 | + # Detect network and set network arguments |
| 30 | + JOB_NET=$(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{printf "%s\n" $k}}{{end}}' "$(hostname)" 2>/dev/null | head -n1 || true) |
| 31 | +
|
| 32 | + if [ -n "$JOB_NET" ]; then |
| 33 | + NETWORK_ARGS="--network $JOB_NET" |
| 34 | + else |
| 35 | + NETWORK_ARGS="" |
| 36 | + fi |
| 37 | +
|
| 38 | + # Start Azurite container |
| 39 | + docker run --name "$AZURITE_CONTAINER" \ |
| 40 | + $NETWORK_ARGS \ |
| 41 | + -p 10000:10000 \ |
| 42 | + -p 10001:10001 \ |
| 43 | + -p 10002:10002 \ |
| 44 | + -d mcr.microsoft.com/azure-storage/azurite \ |
| 45 | + azurite-blob --blobHost 0.0.0.0 --loose |
| 46 | +
|
| 47 | + # Set host based on network configuration |
| 48 | + if [ -n "$JOB_NET" ]; then |
| 49 | + HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$AZURITE_CONTAINER") |
| 50 | + else |
| 51 | + HOST=127.0.0.1 |
| 52 | + fi |
| 53 | +
|
| 54 | + # Wait for Azurite to be ready |
| 55 | + echo "Waiting for Azurite at $HOST:10000..." |
| 56 | + for i in $(seq 1 15); do |
| 57 | + if curl -sS "http://$HOST:10000/" >/dev/null 2>&1; then |
| 58 | + echo "Azurite ready" |
| 59 | + break |
| 60 | + fi |
| 61 | + sleep 1 |
| 62 | + done |
| 63 | +
|
| 64 | + # Verify Azurite is running |
| 65 | + if ! curl -sS "http://$HOST:10000/" >/dev/null 2>&1; then |
| 66 | + echo "Azurite failed to start" |
| 67 | + docker logs "$AZURITE_CONTAINER" || true |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +
|
| 71 | + # Export host for subsequent steps |
| 72 | + echo "AZURITE_HOST=$HOST" >> "$GITHUB_ENV" |
| 73 | +
|
| 74 | + - name: Caching dependencies |
| 75 | + uses: actions/setup-node@v3 |
| 76 | + with: |
| 77 | + node-version: '20' |
| 78 | + cache: 'npm' |
| 79 | + cache-dependency-path: | |
| 80 | + ./npm-shrinkwrap.json |
| 81 | + ./Common/npm-shrinkwrap.json |
| 82 | + ./DocService/npm-shrinkwrap.json |
| 83 | +
|
| 84 | + - name: Install modules |
| 85 | + run: | |
| 86 | + npm ci |
| 87 | + npm --prefix Common ci |
| 88 | + npm --prefix DocService ci |
| 89 | +
|
| 90 | + - name: Setup Azure storage environment |
| 91 | + run: | |
| 92 | + # Create minimal Azure storage configuration |
| 93 | + cat > Common/config/local.json << EOF |
| 94 | + { |
| 95 | + "storage": { |
| 96 | + "name": "storage-az", |
| 97 | + "region": "", |
| 98 | + "endpoint": "http://${AZURITE_HOST:-127.0.0.1}:10000/devstoreaccount1", |
| 99 | + "bucketName": "test-container", |
| 100 | + "storageFolderName": "files", |
| 101 | + "cacheFolderName": "data", |
| 102 | + "accessKeyId": "devstoreaccount1", |
| 103 | + "secretAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" |
| 104 | + }, |
| 105 | + "persistentStorage": { |
| 106 | + "storageFolderName": "files/persistent" |
| 107 | + }, |
| 108 | + "commandOptions": { |
| 109 | + "az": { |
| 110 | + "uploadData": {}, |
| 111 | + "uploadStream": {}, |
| 112 | + "download": {}, |
| 113 | + "syncCopyFromURL": {}, |
| 114 | + "listBlobsFlat": { |
| 115 | + "maxPageSize": 1000 |
| 116 | + }, |
| 117 | + "deleteBlob": {} |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + EOF |
| 122 | +
|
| 123 | + echo "Azure storage configuration created" |
| 124 | +
|
| 125 | + - name: Create Azure container using Node.js from Common directory |
| 126 | + run: | |
| 127 | + # Wait a bit more for Azurite to be fully ready |
| 128 | + sleep 10 |
| 129 | +
|
| 130 | + # Run Node.js script from Common directory where Azure dependencies are installed |
| 131 | + cd Common |
| 132 | + node -e " |
| 133 | + (async () => { |
| 134 | + const { BlobServiceClient, StorageSharedKeyCredential } = require('@azure/storage-blob'); |
| 135 | + const endpoint = 'http://' + (process.env.AZURITE_HOST || '127.0.0.1') + ':10000/devstoreaccount1'; |
| 136 | + const client = new BlobServiceClient(endpoint, new StorageSharedKeyCredential('devstoreaccount1', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==')); |
| 137 | + await client.getContainerClient('test-container').createIfNotExists(); |
| 138 | + console.log('Azure environment ready'); |
| 139 | + })().catch(console.error); |
| 140 | + " |
| 141 | +
|
| 142 | + - name: Run storage tests |
| 143 | + run: npm run storage-tests |
| 144 | + |
| 145 | + - name: Final cleanup |
| 146 | + if: always() |
| 147 | + run: docker rm -f "$AZURITE_CONTAINER" || true |
0 commit comments