Skip to content

actions/telemetry: explain why we collect telemetry data (#3887) #874

actions/telemetry: explain why we collect telemetry data (#3887)

actions/telemetry: explain why we collect telemetry data (#3887) #874

name: Export Edu Documentation to GCS
on:
push:
branches: [ main ]
paths:
- 'content/**'
- 'data/**'
- '**.md'
- 'scripts/generate_image_catalog.py'
- '.github/workflows/export-edu-docs-to-gcs.yaml'
schedule:
- cron: '30 1 * * 0' # Weekly on Sundays at 1:30 AM (same as other repos)
workflow_dispatch:
permissions: {}
jobs:
export-docs:
if: github.repository == 'chainguard-dev/edu'
runs-on: ubuntu-latest
permissions:
contents: write # Required for repository dispatch events
id-token: write # Required for workload identity federation
steps:
- name: Harden Runner
uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false # Don't persist auth token
- name: Authenticate to Google Cloud
uses: step-security/google-github-auth@775fc4c80760272ef389c9f9f8d98de7db0c170d # v3.0.2
with:
workload_identity_provider: "projects/456977358484/locations/global/workloadIdentityPools/chainguard-academy/providers/chainguard-edu"
service_account: "github-chainguard-academy@chainguard-academy.iam.gserviceaccount.com"
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1
- name: Prepare documentation export
run: |
set -euo pipefail # Exit on error, undefined variable, or pipe failure
echo "Preparing edu documentation export..."
# Use mktemp for secure temp directory
EXPORT_DIR=$(mktemp -d)
trap 'rm -rf "$EXPORT_DIR"' EXIT # Clean up on exit
# Copy content directory (main documentation)
if [ -d "content" ]; then
echo "Copying and cleaning content directory..."
# Create content directory structure
find content -type d | while read -r dir; do
mkdir -p "$EXPORT_DIR/$dir"
done
# Process each markdown file to remove HTML comments
find content -name "*.md" -type f | while read -r file; do
# Remove HTML comments and clean up empty lines
sed -E 's/<!--[^>]*-->//g' "$file" | \
sed '/^[[:space:]]*$/N;/\n[[:space:]]*$/d' > "$EXPORT_DIR/$file"
done
echo "✓ Processed $(find content -name "*.md" -type f | wc -l) markdown files in content/"
else
echo "Warning: content directory not found"
fi
# Create a content index for reference
echo "Creating content index..."
find "$EXPORT_DIR" -name "*.md" -type f | \
sed "s|$EXPORT_DIR/||" | \
sort > "$EXPORT_DIR/content-index.txt"
# Create metadata file with proper JSON escaping
cat > "$EXPORT_DIR/metadata.json" << EOF
{
"repository": "chainguard-dev/edu",
"export_time": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"commit": "$GITHUB_SHA",
"ref": "$GITHUB_REF",
"triggered_by": "$GITHUB_EVENT_NAME",
"files_count": $(find "$EXPORT_DIR" -name "*.md" -type f | wc -l),
"total_size": "$(du -sh "$EXPORT_DIR" | cut -f1)"
}
EOF
# Validate JSON
python3 -m json.tool "$EXPORT_DIR/metadata.json" > /dev/null
# Display summary
echo ""
echo "Export Summary:"
echo "---------------"
echo "Total markdown files: $(find "$EXPORT_DIR" -name "*.md" -type f | wc -l)"
echo "Total size: $(du -sh "$EXPORT_DIR" | cut -f1)"
# Create tarball with restricted permissions
cd "$(dirname "$EXPORT_DIR")"
tar --owner=0 --group=0 --mode='u+rwX,go+rX,go-w' \
-czf /tmp/docs-export.tar.gz "$(basename "$EXPORT_DIR")"
echo ""
echo "Documentation bundle created:"
ls -lh /tmp/docs-export.tar.gz
- name: Upload to GCS
run: |
set -euo pipefail
echo "Uploading edu documentation to GCS..."
# Upload with specific content type and cache control
gcloud storage cp /tmp/docs-export.tar.gz \
"gs://academy-all-docs/edu/docs-export.tar.gz" \
--project=chainguard-academy \
--content-type="application/gzip" \
--cache-control="no-cache"
# Extract for metadata upload
EXPORT_DIR=$(mktemp -d)
trap 'rm -rf "$EXPORT_DIR"' EXIT
tar -xzf /tmp/docs-export.tar.gz -C "$EXPORT_DIR" --strip-components=1
# Upload metadata
gcloud storage cp "$EXPORT_DIR/metadata.json" \
"gs://academy-all-docs/edu/metadata.json" \
--project=chainguard-academy \
--content-type="application/json" \
--cache-control="no-cache"
# Upload content index
gcloud storage cp "$EXPORT_DIR/content-index.txt" \
"gs://academy-all-docs/edu/content-index.txt" \
--project=chainguard-academy \
--content-type="text/plain" \
--cache-control="no-cache"
echo "✓ Successfully uploaded edu documentation to GCS"
- name: Trigger compilation workflow
if: github.event_name == 'push' || github.event_name == 'schedule'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Wait a moment to ensure all repos have uploaded if running on schedule
if (context.eventName === 'schedule') {
await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
}
await github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'ai-docs-source-updated',
client_payload: {
repository: 'chainguard-dev/edu',
commit: context.sha,
source: 'edu'
}
});
console.log('Triggered AI docs compilation workflow');