|
| 1 | +name: Packages Daily Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" |
| 6 | + timezone: "Asia/Shanghai" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + create_failure_issue: |
| 10 | + description: Create or update the failure issue when this manual run fails |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + |
| 15 | +permissions: {} |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: packages-daily-${{ github.ref }} |
| 19 | + cancel-in-progress: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + tools-check: |
| 23 | + if: ${{ github.repository == 'RT-Thread/packages' }} |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + uses: ./.github/workflows/aciont_tool.yml |
| 27 | + |
| 28 | + daily-url-check: |
| 29 | + if: ${{ github.repository == 'RT-Thread/packages' }} |
| 30 | + name: URL shard ${{ matrix.label }} |
| 31 | + runs-on: ubuntu-22.04 |
| 32 | + timeout-minutes: 45 |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + max-parallel: 8 |
| 36 | + matrix: |
| 37 | + include: |
| 38 | + - shard_index: 0 |
| 39 | + label: "1/8" |
| 40 | + - shard_index: 1 |
| 41 | + label: "2/8" |
| 42 | + - shard_index: 2 |
| 43 | + label: "3/8" |
| 44 | + - shard_index: 3 |
| 45 | + label: "4/8" |
| 46 | + - shard_index: 4 |
| 47 | + label: "5/8" |
| 48 | + - shard_index: 5 |
| 49 | + label: "6/8" |
| 50 | + - shard_index: 6 |
| 51 | + label: "7/8" |
| 52 | + - shard_index: 7 |
| 53 | + label: "8/8" |
| 54 | + permissions: |
| 55 | + contents: read |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ github.token }} |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v5 |
| 60 | + |
| 61 | + - name: Set up Python |
| 62 | + uses: actions/setup-python@v6 |
| 63 | + with: |
| 64 | + python-version: "3.11" |
| 65 | + |
| 66 | + - name: Install URL checker dependencies |
| 67 | + run: python -m pip install requests |
| 68 | + |
| 69 | + - name: Validate package URLs and metadata |
| 70 | + run: python ci.py --shard-count 8 --shard-index ${{ matrix.shard_index }} |
| 71 | + |
| 72 | + report-daily-failure: |
| 73 | + needs: |
| 74 | + - daily-url-check |
| 75 | + - tools-check |
| 76 | + if: ${{ always() && github.repository == 'RT-Thread/packages' && (github.event_name == 'schedule' || inputs.create_failure_issue) && (needs.daily-url-check.result == 'failure' || needs.tools-check.result == 'failure') }} |
| 77 | + runs-on: ubuntu-22.04 |
| 78 | + permissions: |
| 79 | + actions: read |
| 80 | + issues: write |
| 81 | + steps: |
| 82 | + - name: Create or update failure issue |
| 83 | + uses: actions/github-script@v8 |
| 84 | + with: |
| 85 | + script: | |
| 86 | + const marker = '<!-- daily-packages-check -->'; |
| 87 | + const title = '[CI] Daily packages check failed'; |
| 88 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 89 | + const urlResult = '${{ needs.daily-url-check.result }}'; |
| 90 | + const toolsResult = '${{ needs.tools-check.result }}'; |
| 91 | + const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, { |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + run_id: context.runId, |
| 95 | + filter: 'latest', |
| 96 | + per_page: 100, |
| 97 | + }); |
| 98 | + const failedJobs = jobs |
| 99 | + .filter((job) => job.conclusion === 'failure') |
| 100 | + .slice(0, 20) |
| 101 | + .map((job) => ` - [${job.name}](${job.html_url})`); |
| 102 | + const details = [ |
| 103 | + marker, |
| 104 | + '@CYFS3 @Rbb666', |
| 105 | + '', |
| 106 | + '每日软件包 URL/元数据检查失败,请协助处理。', |
| 107 | + '', |
| 108 | + `- URL/元数据检查:${urlResult}`, |
| 109 | + `- ToolsCI:${toolsResult}`, |
| 110 | + `- Commit:${context.sha}`, |
| 111 | + `- 运行记录:${runUrl}`, |
| 112 | + '', |
| 113 | + '失败 Jobs:', |
| 114 | + ...(failedJobs.length ? failedJobs : [' - 请查看运行记录中的失败步骤。']), |
| 115 | + ].join('\n'); |
| 116 | +
|
| 117 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 118 | + owner: context.repo.owner, |
| 119 | + repo: context.repo.repo, |
| 120 | + state: 'open', |
| 121 | + per_page: 100, |
| 122 | + }); |
| 123 | + const existing = issues.find((issue) => |
| 124 | + !issue.pull_request && issue.title === title && issue.body?.includes(marker) |
| 125 | + ); |
| 126 | +
|
| 127 | + if (existing) { |
| 128 | + await github.rest.issues.createComment({ |
| 129 | + owner: context.repo.owner, |
| 130 | + repo: context.repo.repo, |
| 131 | + issue_number: existing.number, |
| 132 | + body: details, |
| 133 | + }); |
| 134 | + } else { |
| 135 | + await github.rest.issues.create({ |
| 136 | + owner: context.repo.owner, |
| 137 | + repo: context.repo.repo, |
| 138 | + title, |
| 139 | + body: details, |
| 140 | + }); |
| 141 | + } |
0 commit comments