Generate Blog Analytics #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Blog Analytics | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| years: | |
| description: '対象年(カンマ区切り、空欄で全年)' | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| generate: | |
| name: Generate Blog Statistics | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| run: uv python install 3.13 | |
| - name: Install dependencies | |
| working-directory: tools/blog-analytics | |
| run: uv sync | |
| - name: Create output directory | |
| run: mkdir -p output | |
| - name: Detect years with blog posts | |
| id: detect-years | |
| run: | | |
| if [ -n "${{ inputs.years }}" ]; then | |
| echo "years=${{ inputs.years }}" >> "$GITHUB_OUTPUT" | |
| else | |
| years=$(ls -d blog/[0-9][0-9][0-9][0-9] 2>/dev/null | xargs -n1 basename | tr '\n' ',' | sed 's/,$//') | |
| echo "years=$years" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Generate monthly charts | |
| working-directory: tools/blog-analytics | |
| run: | | |
| IFS=',' read -ra YEARS <<< "${{ steps.detect-years.outputs.years }}" | |
| for year in "${YEARS[@]}"; do | |
| year=$(echo "$year" | tr -d ' ') | |
| echo "Generating monthly chart for $year..." | |
| uv run python blog_analytics.py \ | |
| --year "$year" \ | |
| --blog-dir ../../blog \ | |
| --output "../../output/${year}-monthly.png" | |
| done | |
| - name: Generate daily charts | |
| working-directory: tools/blog-analytics | |
| run: | | |
| IFS=',' read -ra YEARS <<< "${{ steps.detect-years.outputs.years }}" | |
| for year in "${YEARS[@]}"; do | |
| year=$(echo "$year" | tr -d ' ') | |
| # Find months with posts for this year | |
| if [ -d "../../blog/$year" ]; then | |
| months=$(ls "../../blog/$year/" 2>/dev/null | grep -oE '^[0-9]{2}' | sort -u) | |
| for month in $months; do | |
| echo "Generating daily chart for $year-$month..." | |
| uv run python blog_analytics.py \ | |
| --year "$year" \ | |
| --month "$((10#$month))" \ | |
| --blog-dir ../../blog \ | |
| --output "../../output/${year}-${month}-daily.png" | |
| done | |
| fi | |
| done | |
| - name: List generated files | |
| run: ls -la output/ | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: blog-analytics-charts | |
| path: output/*.png | |
| retention-days: 1 |