Skip to content
>_ TrueFileSize.com
··7 min read

Using Sample Files in CI/CD Pipelines — GitHub Actions & GitLab CI

Sample files are essential for CI/CD testing — file upload validation, image processing, video transcoding, and document parsing all need real files. This guide shows how to efficiently download, cache, and use sample files in GitHub Actions and GitLab CI.

The Problem

Your tests need real files (PDFs, images, videos), but you shouldn't commit large binaries to Git. Solution: download from TrueFileSize CDN at CI time, with caching to avoid slow re-downloads.

GitHub Actions

Basic: Download Before Tests

# .github/workflows/test.yml
name: Test
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Download test fixtures
        run: |
          mkdir -p tests/fixtures
          curl -sL -o tests/fixtures/sample-1mb.pdf \
            https://cdn.truefilesize.com/pdf/sample-1mb.pdf
          curl -sL -o tests/fixtures/sample-500kb.jpg \
            https://cdn.truefilesize.com/jpg/sample-500kb.jpg
          curl -sL -o tests/fixtures/sample-5mb.mp4 \
            https://cdn.truefilesize.com/mp4/sample-5mb.mp4
          curl -sL -o tests/fixtures/sample-100kb.json \
            https://cdn.truefilesize.com/json/sample-array.json

      - run: npm ci
      - run: npm test

With Caching (Recommended)

      - name: Cache test fixtures
        uses: actions/cache@v4
        id: fixture-cache
        with:
          path: tests/fixtures
          key: test-fixtures-v1

      - name: Download test fixtures
        if: steps.fixture-cache.outputs.cache-hit != 'true'
        run: |
          mkdir -p tests/fixtures
          cd tests/fixtures
          curl -sL -O https://cdn.truefilesize.com/pdf/sample-1mb.pdf
          curl -sL -O https://cdn.truefilesize.com/jpg/sample-500kb.jpg
          curl -sL -O https://cdn.truefilesize.com/mp4/sample-5mb.mp4

This downloads files only once. Subsequent runs use the cached versions — shaving minutes off your CI pipeline.

Parallel Jobs with Shared Fixtures

jobs:
  download-fixtures:
    runs-on: ubuntu-latest
    steps:
      - name: Download all test fixtures
        run: |
          mkdir -p fixtures
          curl -sL -O https://cdn.truefilesize.com/pdf/sample-1mb.pdf
          curl -sL -O https://cdn.truefilesize.com/jpg/sample-500kb.jpg
      - uses: actions/upload-artifact@v4
        with:
          name: test-fixtures
          path: fixtures/

  test-upload:
    needs: download-fixtures
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: test-fixtures
          path: tests/fixtures
      - run: npm ci && npm run test:upload

  test-processing:
    needs: download-fixtures
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: test-fixtures
          path: tests/fixtures
      - run: npm ci && npm run test:processing

GitLab CI

# .gitlab-ci.yml
stages:
  - setup
  - test

variables:
  FIXTURES_DIR: tests/fixtures

cache:
  key: test-fixtures-v1
  paths:
    - $FIXTURES_DIR/

download-fixtures:
  stage: setup
  script:
    - mkdir -p $FIXTURES_DIR
    - cd $FIXTURES_DIR
    - "[ -f sample-1mb.pdf ] || curl -sL -O https://cdn.truefilesize.com/pdf/sample-1mb.pdf"
    - "[ -f sample-500kb.jpg ] || curl -sL -O https://cdn.truefilesize.com/jpg/sample-500kb.jpg"

test-upload:
  stage: test
  needs: [download-fixtures]
  script:
    - npm ci
    - npm run test:upload

test-processing:
  stage: test
  needs: [download-fixtures]
  script:
    - npm ci
    - npm run test:processing

Download Script (Reusable)

Create a script your CI calls:

#!/bin/bash
# scripts/download-fixtures.sh
set -e

CDN="https://cdn.truefilesize.com"
DIR="${1:-tests/fixtures}"
mkdir -p "$DIR"

FILES=(
  "pdf/sample-1mb.pdf"
  "jpg/sample-500kb.jpg"
  "png/transparent-logo.png"
  "mp4/sample-5mb.mp4"
  "json/sample-array.json"
  "csv/sample-users.csv"
  "zip/sample-1mb.zip"
  "corrupted/sample-corrupt.pdf"
)

for file in "${FILES[@]}"; do
  name=$(basename "$file")
  if [ ! -f "$DIR/$name" ]; then
    echo "Downloading $name..."
    curl -sL -o "$DIR/$name" "$CDN/$file"
  else
    echo "Cached: $name"
  fi
done

echo "All fixtures ready in $DIR/"

Recommended Test Fixtures

| Use Case | File | Size | |----------|------|------| | Upload validation | sample-1mb.pdf | 1 MB | | Image processing | sample-500kb.jpg | 500 KB | | Transparency | transparent-logo.png | 6 KB | | Video processing | sample-5mb.mp4 | 5 MB | | API mocking | sample-array.json | 15 KB | | Data import | sample-users.csv | 50 KB | | Archive handling | sample-1mb.zip | 1 MB | | Error handling | sample-corrupt.pdf | 10 KB |

For larger files for stress testing: Download Tests (1MB to 10GB).