Files

1 line
8.1 KiB
JSON

{"repo": "arjun-rao-dev/blog", "files": {"content/posts/2025-11-10-/hugo-post.yml": {"ea3eb928b7d239d53f91190c55b60b8c6c7e75d2": {"t": 1785745265.4054651, "n": 7710, "h": "587c66a5abec3b24", "c": "name: Create Hugo Blog Post\n\non:\n push:\n branches:\n - main\n paths-ignore:\n - '.github/**'\n\njobs:\n create-blog-post:\n # Use the `production` environment so secrets defined in that environment\n # (for example `BLOG_REPO_TOKEN`) will be available to this job.\n environment: production\n runs-on: ubuntu-latest\n steps:\n - name: Checkout learning repo\n uses: actions/checkout@v3\n with:\n path: learning\n\n - name: Check required secrets and environment variables\n env:\n BLOG_REPO_TOKEN: ${{ secrets.BLOG_REPO_TOKEN }}\n DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}\n DEEPSEEK_URL: https://your-deepseek-api-url\n run: |\n set -euo pipefail\n missing=false\n # Check required secrets\n for v in BLOG_REPO_TOKEN DEEPSEEK_API_KEY; do\n if [ -z \"${!v:-}\" ]; then\n echo \"::error::Missing required secret $v in the production environment\"\n missing=true\n fi\n done\n # Check required environment variable\n if [ -z \"${DEEPSEEK_URL:-}\" ]; then\n echo \"::error::Missing required environment variable DEEPSEEK_URL\"\n missing=true\n fi\n if [ \"$missing\" = true ]; then\n echo \"One or more required secrets or environment variables are missing.\"\n echo \"Please add BLOG_REPO_TOKEN and DEEPSEEK_API_KEY to the 'production' environment in repository settings, and ensure DEEPSEEK_URL is set as an environment variable in the runner.\"\n exit 1\n fi\n\n - name: Checkout blog repo\n uses: actions/checkout@v3\n with:\n repository: Arjun-Rao-Dev/blog\n token: ${{ secrets.BLOG_REPO_TOKEN }}\n path: blog\n\n - name: Get changed files\n id: changed-files\n uses: tj-actions/changed-files@v39\n with:\n path: learning\n\n - name: Set up Hugo\n uses: peaceiris/actions-hugo@v2\n with:\n hugo-version: 'latest'\n extended: true\n\n - name: Create blog post\n env:\n # Map Deepseek variables from environment-level secrets (production environment)\n DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}\n # DEEPSEEK_URL is now expected to be set in the runner environment, not as a secret\n run: |\n set -euo pipefail\n cd blog\n\n # Ensure content/posts exists\n mkdir -p content/posts\n\n for file in ${{ steps.changed-files.outputs.all_changed_files }}; do\n src_path=\"../learning/$file\"\n\n # Determine the directory we should copy into the post bundle.\n if [ -d \"$src_path\" ]; then\n base_dir=\"$file\"\n else\n base_dir=$(dirname \"$file\")\n # If file is at repo root, use filename (without extension) as base_dir\n if [ \"$base_dir\" = \".\" ]; then\n base_dir=$(basename \"$file\" | sed 's/\\.[^.]*$//')\n fi\n fi\n\n # Normalize POST_NAME from base_dir\n POST_NAME=$(echo \"$base_dir\" | tr '/' '-' | sed 's/\\.[^.]*$//')\n DATE=$(date +%Y-%m-%d)\n POST_DIR=\"content/posts/$DATE-$POST_NAME\"\n mkdir -p \"$POST_DIR\"\n\n # Copy relevant files into the page bundle. This will include images, gifs and code files.\n SRC_DIR=\"../learning/$base_dir\"\n if [ -d \"$SRC_DIR\" ]; then\n # Copy everything from the source directory into the bundle (excluding .git)\n rsync -av --exclude='.git' \"$SRC_DIR/\" \"$POST_DIR/\" || true\n else\n # If there's no directory, try copying the single file\n if [ -f \"../learning/$file\" ]; then\n cp \"../learning/$file\" \"$POST_DIR/\"\n fi\n fi\n\n # Find a primary file to summarize (prefer README, md, or code files)\n main_candidate=\"\"\n if [ -f \"$POST_DIR/README.md\" ]; then\n main_candidate=\"$POST_DIR/README.md\"\n else\n main_candidate=$(find \"$POST_DIR\" -type f \\( -iname \"*.md\" -o -iname \"README*\" -o -iname \"*.py\" -o -iname \"*.js\" -o -iname \"*.go\" -o -iname \"*.java\" \\) | head -n 1 || true)\n fi\n\n # Generate summary using Deepseek if credentials and candidate exist\n SUMMARY=\"\"\n if [ -n \"${DEEPSEEK_API_KEY:-}\" ] && [ -n \"${DEEPSEEK_URL:-}\" ] && [ -n \"$main_candidate\" ]; then\n # Build a proper JSON payload using python to ensure escaping\n JSON_PAYLOAD=$(python3 -c \"import json,sys;print(json.dumps({'text':open(sys.argv[1]).read()}))\" \"$main_candidate\")\n\n SUMMARY=$(curl -s -X POST \"$DEEPSEEK_URL\" \\\n -H \"Authorization: Bearer $DEEPSEEK_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d \"$JSON_PAYLOAD\" \\\n | python3 -c 'import sys,json;print(json.load(sys.stdin).get(\"summary\",\"\"))' || true)\n\n # Truncate summary to 10000 chars to keep front matter/body manageable\n SUMMARY=$(echo \"$SUMMARY\" | awk '{s=substr($0,1,10000);print s}')\n fi\n\n # Compose index.md inside the page bundle\n INDEX_FILE=\"$POST_DIR/index.md\"\n TITLE=\"Post from $POST_NAME\"\n if [ -n \"$SUMMARY\" ]; then\n echo \"---\" > \"$INDEX_FILE\"\n echo \"title: \\\"$TITLE\\\"\" >> \"$INDEX_FILE\"\n echo \"date: $(date +\"%Y-%m-%dT%H:%M:%S%:z\")\" >> \"$INDEX_FILE\"\n echo \"draft: false\" >> \"$INDEX_FILE\"\n echo \"---\" >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n echo \"$SUMMARY\" >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n else\n # Minimal front matter if no summary\n echo \"---\" > \"$INDEX_FILE\"\n echo \"title: \\\"$TITLE\\\"\" >> \"$INDEX_FILE\"\n echo \"date: $(date +\"%Y-%m-%dT%H:%M:%S%:z\")\" >> \"$INDEX_FILE\"\n echo \"draft: false\" >> \"$INDEX_FILE\"\n echo \"---\" >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n echo \"This post was automatically generated from $file in the learning repository.\" >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n fi\n\n # Append code blocks for code files found in the bundle (inline for quick reading)\n find \"$POST_DIR\" -maxdepth 1 -type f \\( -iname \"*.py\" -o -iname \"*.js\" -o -iname \"*.go\" -o -iname \"*.java\" -o -iname \"*.sh\" \\) | while read -r codefile; do\n fname=$(basename \"$codefile\")\n ext=${fname##*.}\n echo \"### $fname\" >> \"$INDEX_FILE\"\n echo '```'\"$ext\" >> \"$INDEX_FILE\"\n sed 's/^/ /' \"$codefile\" >> \"$INDEX_FILE\"\n echo '```' >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n done\n\n # If there are image files, reference them in the post (Hugo page bundle will serve them)\n find \"$POST_DIR\" -maxdepth 1 -type f \\( -iname \"*.png\" -o -iname \"*.jpg\" -o -iname \"*.jpeg\" -o -iname \"*.gif\" -o -iname \"*.webp\" \\) | while read -r img; do\n iname=$(basename \"$img\")\n echo \"![${iname}](${iname})\" >> \"$INDEX_FILE\"\n echo \"\" >> \"$INDEX_FILE\"\n done\n\n done\n\n - name: Commit and push changes\n run: |\n cd blog\n git config --global user.name 'GitHub Actions'\n git config --global user.email 'actions@github.com'\n git add .\n git commit -m \"Add blog post for changes in learning repo\" || echo \"No changes to commit\"\n git push"}}}}