|
| 1 | +name: "UTBot Java: collect statistics" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + runners: |
| 7 | + description: 'Runners number' |
| 8 | + required: false |
| 9 | + default: '1' |
| 10 | + type: string |
| 11 | + run_number: |
| 12 | + description: 'Number of run tries per runner' |
| 13 | + required: false |
| 14 | + default: '1' |
| 15 | + type: string |
| 16 | + message_prefix: |
| 17 | + description: 'Commit message prefix' |
| 18 | + required: false |
| 19 | + default: manual-run |
| 20 | + type: string |
| 21 | + aggregate: |
| 22 | + description: 'Aggregate data' |
| 23 | + required: false |
| 24 | + default: false |
| 25 | + type: boolean |
| 26 | + |
| 27 | + workflow_dispatch: |
| 28 | + inputs: |
| 29 | + runners: |
| 30 | + description: 'Runners number' |
| 31 | + required: false |
| 32 | + default: '1' |
| 33 | + type: string |
| 34 | + run_number: |
| 35 | + description: 'Number of run tries per runner' |
| 36 | + required: false |
| 37 | + default: '1' |
| 38 | + type: string |
| 39 | + message_prefix: |
| 40 | + description: 'Commit message prefix' |
| 41 | + required: false |
| 42 | + default: manual-run |
| 43 | + type: string |
| 44 | + aggregate: |
| 45 | + description: 'Aggregate data' |
| 46 | + required: false |
| 47 | + default: false |
| 48 | + type: boolean |
| 49 | + |
| 50 | +env: |
| 51 | + data_branch: monitoring-data |
| 52 | + data_path: monitoring/data |
| 53 | + aggregated_data_branch: monitoring-aggregated-data |
| 54 | + aggregated_data_path: monitoring/aggregated_data |
| 55 | + monitoring_properties: monitoring/monitoring.properties |
| 56 | + push_script: monitoring/push_with_rebase.sh |
| 57 | + |
| 58 | +jobs: |
| 59 | + setup_matrix: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + outputs: |
| 62 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 63 | + steps: |
| 64 | + - name: Create matrix |
| 65 | + id: set-matrix |
| 66 | + run: | |
| 67 | + arr=$(echo [$(seq -s , ${{ inputs.runners }})]) |
| 68 | + echo "::set-output name=matrix::$arr" |
| 69 | + echo $arr |
| 70 | +
|
| 71 | + build_and_collect_statistics: |
| 72 | + needs: setup_matrix |
| 73 | + continue-on-error: true |
| 74 | + strategy: |
| 75 | + matrix: |
| 76 | + value: ${{ fromJson(needs.setup_matrix.outputs.matrix) }} |
| 77 | + runs-on: ubuntu-20.04 |
| 78 | + container: unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0 |
| 79 | + steps: |
| 80 | + - name: Install git |
| 81 | + run: | |
| 82 | + apt-get upgrade -y |
| 83 | + apt-get update -y |
| 84 | + apt-get install git -y |
| 85 | + git config --global --add safe.directory $(pwd) |
| 86 | +
|
| 87 | + - name: Checkout repository |
| 88 | + uses: actions/checkout@v3 |
| 89 | + |
| 90 | + - name: Checkout monitoring data |
| 91 | + uses: actions/checkout@v3 |
| 92 | + with: |
| 93 | + ref: ${{ env.data_branch }} |
| 94 | + path: ${{ env.data_path }} |
| 95 | + |
| 96 | + - uses: actions/setup-python@v4 |
| 97 | + with: |
| 98 | + python-version: '3.9' |
| 99 | + |
| 100 | + - name: Build and run monitoring UTBot Java |
| 101 | + run: | |
| 102 | + gradle :utbot-junit-contest:monitoringJar |
| 103 | + for i in $(seq ${{ inputs.run_number }}) |
| 104 | + do |
| 105 | + java -jar \ |
| 106 | + -Dutbot.monitoring.settings.path=$monitoring_properties \ |
| 107 | + utbot-junit-contest/build/libs/monitoring.jar \ |
| 108 | + stats-$i.json |
| 109 | + mv logs/utbot.log logs/utbot-$i.log |
| 110 | + done |
| 111 | +
|
| 112 | + - name: Get current date |
| 113 | + id: date |
| 114 | + run: | |
| 115 | + echo "::set-output name=date::$(date +'%Y-%m-%d')" |
| 116 | + echo "::set-output name=timestamp::$(date +%s)" |
| 117 | + echo "::set-output name=last_month::$(date --date='last month' +%s)" |
| 118 | +
|
| 119 | + - name: Get metadata |
| 120 | + id: metadata |
| 121 | + run: | |
| 122 | + echo "::set-output name=commit::$(git rev-parse HEAD)" |
| 123 | + echo "::set-output name=short_commit::$(git rev-parse --short HEAD)" |
| 124 | + echo "::set-output name=branch::$(git name-rev --name-only HEAD)" |
| 125 | + echo "::set-output name=build::$(date +'%Y.%-m')" |
| 126 | +
|
| 127 | + - name: Insert metadata |
| 128 | + shell: bash |
| 129 | + run: | |
| 130 | + OUT_FILE="$data_path/data-$branch-$date-$timestamp-$short_commit-${{ matrix.value }}.json" |
| 131 | + INPUTS=($(seq ${{ inputs.run_number }})) |
| 132 | + INPUTS=(${INPUTS[@]/#/stats-}) |
| 133 | + INPUTS=(${INPUTS[@]/%/.json}) |
| 134 | + INPUTS=${INPUTS[@]} |
| 135 | + echo $INPUTS |
| 136 | + python monitoring/insert_metadata.py \ |
| 137 | + --stats_file $INPUTS \ |
| 138 | + --output_file "$OUT_FILE" \ |
| 139 | + --commit $commit \ |
| 140 | + --branch $branch \ |
| 141 | + --build "$build" \ |
| 142 | + --timestamp $timestamp \ |
| 143 | + --source_type "github-action" \ |
| 144 | + --source_id $run_id |
| 145 | + env: |
| 146 | + date: ${{ steps.date.outputs.date }} |
| 147 | + timestamp: ${{ steps.date.outputs.timestamp }} |
| 148 | + commit: ${{ steps.metadata.outputs.commit }} |
| 149 | + short_commit: ${{ steps.metadata.outputs.short_commit }} |
| 150 | + branch: ${{ steps.metadata.outputs.branch }} |
| 151 | + build: ${{ steps.metadata.outputs.build }} |
| 152 | + run_id: ${{ github.run_id }}-${{ matrix.value }} |
| 153 | + |
| 154 | + - name: Commit and push statistics |
| 155 | + run: | |
| 156 | + chmod +x $push_script |
| 157 | + ./$push_script |
| 158 | + env: |
| 159 | + target_branch: ${{ env.data_branch }} |
| 160 | + target_directory: ${{ env.data_path }} |
| 161 | + message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }} |
| 162 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 163 | + |
| 164 | + - name: Upload logs |
| 165 | + if: ${{ always() }} |
| 166 | + uses: actions/upload-artifact@v3 |
| 167 | + with: |
| 168 | + name: logs-${{ matrix.value }} |
| 169 | + path: logs/ |
| 170 | + |
| 171 | + aggregate: |
| 172 | + needs: build_and_collect_statistics |
| 173 | + if: ${{ inputs.aggregate }} |
| 174 | + runs-on: ubuntu-latest |
| 175 | + steps: |
| 176 | + - name: Checkout repository |
| 177 | + uses: actions/checkout@v3 |
| 178 | + |
| 179 | + - name: Checkout monitoring data |
| 180 | + uses: actions/checkout@v3 |
| 181 | + with: |
| 182 | + ref: ${{ env.data_branch }} |
| 183 | + path: ${{ env.data_path }} |
| 184 | + |
| 185 | + - name: Checkout aggregated monitoring data |
| 186 | + uses: actions/checkout@v3 |
| 187 | + with: |
| 188 | + ref: ${{ env.aggregated_data_branch }} |
| 189 | + path: ${{ env.aggregated_data_path }} |
| 190 | + |
| 191 | + - uses: actions/setup-python@v4 |
| 192 | + with: |
| 193 | + python-version: '3.9' |
| 194 | + |
| 195 | + - name: Get current date |
| 196 | + id: date |
| 197 | + run: | |
| 198 | + echo "::set-output name=date::$(date +'%Y-%m-%d')" |
| 199 | + echo "::set-output name=timestamp::$(date +%s)" |
| 200 | + echo "::set-output name=last_month::$(date --date='last month' +%s)" |
| 201 | +
|
| 202 | + - name: Build aggregated data (last month) |
| 203 | + run: | |
| 204 | + OUT_FILE=$aggregated_data_path/aggregated-data-$date.json |
| 205 | + python monitoring/build_aggregated_data.py \ |
| 206 | + --input_data_dir $data_path \ |
| 207 | + --output_file $OUT_FILE \ |
| 208 | + --timestamp_from $timestamp_from \ |
| 209 | + --timestamp_to $timestamp |
| 210 | + env: |
| 211 | + date: ${{ steps.date.outputs.date }} |
| 212 | + timestamp: ${{ steps.date.outputs.timestamp }} |
| 213 | + timestamp_from: ${{ steps.date.outputs.last_month }} |
| 214 | + |
| 215 | + - name: Commit and push aggregated statistics |
| 216 | + run: | |
| 217 | + chmod +x $push_script |
| 218 | + ./$push_script |
| 219 | + env: |
| 220 | + target_branch: ${{ env.aggregated_data_branch }} |
| 221 | + target_directory: ${{ env.aggregated_data_path }} |
| 222 | + message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }} |
| 223 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments