用途:为 Riksdagsmonitor 的静态站点 CI/CD 流水线优化 GitHub Actions 工作流,覆盖质量检查、安全扫描与部署三类场景。
主要能力:质量检查工作流在 push 到 main 及 pull_request 时触发,使用 htmlhint 校验 HTML、linkinator 递归检查链接;安全扫描工作流在 push 与 pull_request 时运行 CodeQL(javascript)分析与 dependency-check 依赖扫描;部署工作流在 push 到 main 时通过 configure-pages、upload-pages-artifact、deploy-pages 发布到 GitHub Pages。
使用方式:将工作流文件放在 .github/workflows/ 目录。质量检查示例中先 actions/checkout@v4,再执行 npm install -g htmlhint 与 htmlhint *.html,链接检查用 python3 -m http.server 8080 启动本地服务后运行 linkinator http://localhost:8080/ --recurse。安全扫描需 permissions: security-events: write,使用 github/codeql-action/init@v3 与 analyze@v3,以及 dependency-check/Dependency-Check_Action@main。部署需 contents: read、pages: write、id-token: write 权限,并设置 github-pages 环境。
最佳实践:最小权限、将 Action 固定到 SHA、缓存依赖、并行任务、矩阵测试。
限制:资料未提供具体缓存与矩阵配置示例、版本兼容细节及实际运行效果,相关事实暂未提供。参考文档见 https://docs.github.com/en/actions。