This guide covers how to integrate git-file-fetch into your CI/CD pipelines for automated file fetching and verification.
git-file-fetch is designed to work seamlessly in CI environments, providing:
- Reproducible builds through manifest tracking
- Dry-run verification without file modifications
- JSON output for machine-readable results
- Stable error codes for automation
name: Verify Dependencies
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Verify external files
run: |
npx git-file-fetch \
"https://github.com/octokit/core.js.git@main:LICENSE" \
"https://github.com/microsoft/TypeScript.git@main:README.md" \
--dry-run \
--json \
--quietverify:
image: node:22-alpine
before_script:
- apk add --no-cache git
script:
- npx git-file-fetch "https://github.com/user/repo.git@main:src/config.json" --dry-runpipeline {
agent { label 'nodejs' }
stages {
stage('Verify Dependencies') {
steps {
sh '''
npx git-file-fetch \\
"https://github.com/user/repo.git@main:src/utils.ts" \\
--dry-run \\
--json
'''
}
}
}
}Verify that external files haven't changed unexpectedly:
- name: Verify external dependencies
run: |
# Fetch files and compare with manifest
npx git-file-fetch --config deps.json --dry-run --json > verification.json
# Check if any files have changed
if jq -e '.results[] | select(.status != "unchanged")' verification.json; then
echo "External dependencies have changed!"
exit 1
fiUpdate external files on a schedule:
name: Update Dependencies
on:
schedule:
- cron: '0 2 * * 1' # Every Monday at 2 AM
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Update external files
run: |
npx git-file-fetch --config deps.json --out third_party
- name: Commit changes
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add third_party/ .git-remote-files.json
git commit -m "Update external dependencies" || exit 0
git pushTest against different environments:
strategy:
matrix:
environment: [staging, production]
node-version: [22, 23, 24]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Test with ${{ matrix.environment }} config
run: |
npx git-file-fetch \
--config configs/${{ matrix.environment }}.json \
--dry-run \
--json[
"https://github.com/user/repo.git@main:src/config.json",
"https://github.com/another/repo.git@v1.0.0:LICENSE"
][
{
"repo": "https://github.com/user/repo.git",
"ref": "main",
"path": "src/utils.ts",
"dest": "vendor/utils.ts"
},
{
"repo": "https://github.com/another/repo.git",
"ref": "develop",
"path": "templates/readme.md",
"dest": "docs/external-readme.md"
}
]Always use --dry-run in CI to verify files without modifying your repository:
npx git-file-fetch --config deps.json --dry-run --jsonInclude .git-remote-files.json in your repository for reproducible builds:
git add .git-remote-files.json
git commit -m "Update dependency manifest"Configure timeouts for network operations in CI:
export FETCH_GIT_FILE_TIMEOUT_MS=30000 # 30 seconds
export FETCH_GIT_FILE_RETRIES=3
npx git-file-fetch --config deps.jsonParse JSON output for programmatic handling:
npx git-file-fetch --config deps.json --json | jq '.results[] | select(.status == "error")'For private repositories, use appropriate authentication:
- name: Fetch private dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx git-file-fetch \
"https://github.com/org/private-repo.git@main:src/config.json" \
--dry-run0- Success1- One or more fetches failed2- Invalid usage
- Authentication failures - Ensure proper tokens are configured
- Network timeouts - Increase timeout values for slow networks
- File size limits - Adjust
--max-bytesfor large files - Git availability - Ensure Git is available in CI environment
Enable verbose output for troubleshooting:
npx git-file-fetch --config deps.json --verbose --dry-run- Never commit secrets - Use environment variables for tokens
- Validate file sources - Only fetch from trusted repositories
- Set file size limits - Prevent abuse through large file downloads
- Use dry-run in CI - Verify without making changes
See examples/ci-workflows for complete working examples of various CI integrations.