test(announce): test #5
Workflow file for this run
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: Update Announcement Bar | |
| on: | |
| push: | |
| branches: [ci-test] | |
| paths: | |
| - 'CHANGELOG.md' | |
| jobs: | |
| announce: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Get latest CHANGELOG diff | |
| id: changelog | |
| run: | | |
| # git fetch origin ci-test --depth | |
| # 获取本次提交中CHANGELOG.md的diff | |
| git diff HEAD^ HEAD -- CHANGELOG.md > changelog.diff | |
| # 提取新增内容(以+开头且非+++的行) | |
| grep '^+[^+]' changelog.diff | sed 's/^+//' > changelog_added.txt | |
| echo "added<<EOF" >> $GITHUB_OUTPUT | |
| cat changelog_added.txt >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| # - name: Run AI inference | |
| # id: inference | |
| # uses: actions/ai-inference@v1 | |
| # with: | |
| # prompt: | | |
| # Please summarize the following update in one sentence, suitable for posting in the website announcement bar: | |
| # ${{ steps.changelog.outputs.added }} | |
| # model: deepseek/deepseek-r1 | |
| - name: Run DeepSeek inference | |
| id: inference | |
| run: | | |
| RESPONSE=$(curl -s https://api.deepseek.com/v1/chat/completions \ | |
| -H "Authorization: Bearer ${{ secrets.DEEPSEEK_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "model": "deepseek-chat", | |
| "messages": [ | |
| {"role": "system", "content": "You are a helpful assistant"}, | |
| {"role": "user", "content": "Please summarize the following update in one sentence, suitable for posting in the website announcement bar: ${{ steps.changelog.outputs.added }}"} | |
| ] | |
| }' | jq -r '.choices[0].message.content') | |
| echo "response<<EOF" >> $GITHUB_OUTPUT | |
| echo "$RESPONSE" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Update main.html announce | |
| run: | | |
| summary="${{ steps.inference.outputs.response }}" | |
| sed -i "/{% block announce %}/,/{% endblock %}/c\\ | |
| {% block announce %}\\ | |
| <strong>📢 ${summary} <a href=\"/plotfig/changelog\">更新日志</a></strong>\\ | |
| {% endblock %}" overrides/main.html | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add overrides/main.html | |
| git commit -m "docs(announce): update announcement bar automatically" | |
| git push |