File: rerun.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (113 lines) | stat: -rw-r--r-- 4,344 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Rerun Job

on:
  workflow_dispatch:
    inputs:
      run_id:
        required: true
  workflow_run:
    workflows: [Tests]
    types:
      - completed

jobs:
  rerun:
    if: github.event_name == 'workflow_dispatch'
    permissions: 
      actions: write
    runs-on: ubuntu-latest
    steps:
      - name: rerun ${{ inputs.run_id }}
        env:
          GH_REPO: ${{ github.repository }}
          GH_TOKEN: ${{ github.token }}
        run: |
          gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
          gh run rerun ${{ inputs.run_id }} --failed

  rerun-pr:
    if: github.event.workflow_run && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.run_attempt < 5
    permissions:
      actions: write
    env:
      GH_REPO: ${{ github.repository }}
      GH_TOKEN: ${{ github.token }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Get PR number
        uses: actions/github-script@v7
        with:
          script: |
            let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: context.payload.workflow_run.id,
            });
            let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "pr_number"
            })[0];
            let download = await github.rest.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: matchArtifact.id,
              archive_format: 'zip',
            });
            let fs = require('fs');
            fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
           
      - name: Unzip PR number
        run: unzip pr_number.zip

      - name: Check for rerun label
        run: |
          labels=$(gh pr view $(cat pr_number) --json labels | jq -r '.labels[].name')
          if grep -q '^Auto rerun spread$' <<<$labels; then
            echo "AUTO_RERUN=true" >> $GITHUB_ENV
          fi

      - name: Check for draft and approvals
        if: env.AUTO_RERUN == 'true'
        run: |
          pr=$(cat pr_number)
          if [ "$(gh pr view "$pr" --json isDraft --jq '.isDraft')" = "true" ]; then
            echo "setting auto rerun to false because the PR is a draft"
            echo "AUTO_RERUN=false" >> $GITHUB_ENV
            exit 0
          fi
          num_approvals=$(gh pr view "$pr" --json reviews --jq '.reviews[] | select(.state == "APPROVED") | .state' | wc -l)
          if [ $num_approvals = "0" ]; then
            echo "setting auto rerun to false because it has no approvals"
            echo "AUTO_RERUN=false" >> $GITHUB_ENV
          fi
      
      - name: Set run ID
        if: env.AUTO_RERUN == 'true'
        run: |
          run_id=$(awk -F'/' '{print $(NF-1)}' <<<"${{ github.event.workflow_run.rerun_url }}")
          echo "RUN_ID=$run_id" >> $GITHUB_ENV

      - name: Check number of fundamental failures
        if: env.AUTO_RERUN == 'true'
        run: |
          failed_fund=$(gh run view "$RUN_ID" --json jobs --jq '.jobs[] | select(.name | test("\\(fundamental\\)")) | select(.conclusion == "failure") | .databaseId')
          for failed in $failed_fund; do

            # The number of failed tasks are reported in the logs as a line with 
            # a date and timestamp, followed by "Failed tasks: " and the number
            # ex: 2025-07-03 08:31:46 Failed tasks: 2
            # That line will appear multiple times in the logs since the spread
            # analyzer will echo out that same line, so grab the first occurrence.
            num_failed=$(gh run view --log-failed --job "$failed" | grep -oP '(?:\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) Failed tasks: \K\d+$' | head -1)
            
            if [ -n "$num_failed" ] && [ $num_failed -ge 20 ]; then 
              echo "Setting rerun to false because there were 20 or more failures on a fundamental system"
              echo "AUTO_RERUN=false" >> $GITHUB_ENV
            fi
          done
      
      - name: Rerun workflow
        if: env.AUTO_RERUN == 'true'
        run: gh run rerun "$RUN_ID" --failed