2023-10-05 12:32:20 +08:00
# ## Description
#
# Uses [diffcalc-sheet-generator](https://github.com/smoogipoo/diffcalc-sheet-generator) to run two builds of osu and generate an SR/PP/Score comparison spreadsheet.
#
# ## Requirements
#
# Self-hosted runner with installed:
# - `docker >= 20.10.16`
# - `docker-compose >= 2.5.1`
# - `lbzip2`
# - `jq`
#
# ## Usage
#
# The workflow can be run in two ways:
# 1. Via workflow dispatch.
2023-10-17 19:15:00 +08:00
# 2. By an owner of the repository posting a pull request or issue comment containing `!diffcalc`.
# For pull requests, the workflow will assume the pull request as the target to compare against (i.e. the `OSU_B` variable).
2023-10-05 12:32:20 +08:00
# Any lines in the comment of the form `KEY=VALUE` are treated as variables for the generator.
#
# ## Google Service Account
#
# Spreadsheets are uploaded to a Google Service Account, and exposed with read-only permissions to the wider audience.
#
# 1. Create a project at https://console.cloud.google.com
# 2. Enable the `Google Sheets` and `Google Drive` APIs.
# 3. Create a Service Account
# 4. Generate a key in the JSON format.
# 5. Encode the key as base64 and store as an **actions secret** with name **`DIFFCALC_GOOGLE_CREDENTIALS`**
#
# ## Environment variables
#
# The default environment may be configured via **actions variables**.
#
# Refer to [the sample environment](https://github.com/smoogipoo/diffcalc-sheet-generator/blob/master/.env.sample), and prefix each variable with `DIFFCALC_` (e.g. `DIFFCALC_THREADS`, `DIFFCALC_INNODB_BUFFER_SIZE`, etc...).
name : Run difficulty calculation comparison
2023-10-05 12:20:07 +08:00
run-name : "${{ github.event_name == 'workflow_dispatch' && format('Manual run: {0}', inputs.osu-b) || 'Automatic comment trigger' }}"
2021-09-03 16:56:56 +08:00
on :
issue_comment :
2023-03-27 23:07:01 +08:00
types : [ created ]
2023-10-05 12:20:07 +08:00
workflow_dispatch :
inputs :
osu-b :
description : "The target build of ppy/osu"
type : string
required : true
ruleset :
description : "The ruleset to process"
type : choice
required : true
options :
- osu
- taiko
- catch
- mania
converts :
description : "Include converted beatmaps"
type : boolean
required : false
default : true
ranked-only :
description : "Only ranked beatmaps"
type : boolean
required : false
default : true
generators :
description : "Comma-separated list of generators (available: [sr, pp, score])"
type : string
required : false
default : 'pp,sr'
osu-a :
description : "The source build of ppy/osu"
type : string
required : false
default : 'latest'
difficulty-calculator-a :
description : "The source build of ppy/osu-difficulty-calculator"
type : string
required : false
default : 'latest'
difficulty-calculator-b :
description : "The target build of ppy/osu-difficulty-calculator"
type : string
required : false
default : 'latest'
score-processor-a :
description : "The source build of ppy/osu-queue-score-statistics"
type : string
required : false
default : 'latest'
score-processor-b :
description : "The target build of ppy/osu-queue-score-statistics"
type : string
required : false
default : 'latest'
permissions :
pull-requests : write
2021-09-03 16:56:56 +08:00
env :
2023-10-20 02:26:12 +08:00
EXECUTION_ID : execution-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
2021-09-03 16:56:56 +08:00
2024-11-11 11:47:55 +08:00
defaults :
run :
shell : bash -euo pipefail {0}
2021-09-03 16:56:56 +08:00
jobs :
2023-10-17 19:15:00 +08:00
check-permissions :
name : Check permissions
2023-10-05 12:20:07 +08:00
runs-on : ubuntu-latest
2023-10-17 19:15:00 +08:00
if : ${{ github.event_name == 'workflow_dispatch' || contains(github.event.comment.body, '!diffcalc') }}
2023-10-05 12:20:07 +08:00
steps :
2023-10-17 19:15:00 +08:00
- name : Check permissions
2024-03-27 12:37:47 +08:00
run : |
2024-07-08 12:58:42 +08:00
ALLOWED_USERS=(smoogipoo peppy bdach frenzibyte)
2024-03-27 12:37:47 +08:00
for i in "${ALLOWED_USERS[@]}"; do
if [[ "${{ github.actor }}" == "$i" ]]; then
exit 0
fi
done
exit 1
2023-10-05 12:20:07 +08:00
2024-11-09 13:54:19 +08:00
run-diffcalc :
name : Run spreadsheet generator
needs : check-permissions
uses : ./.github/workflows/_diffcalc_processor.yml
with :
# Can't reference env... Why GitHub, WHY?
id : execution-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
head-sha : https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha || github.sha }}
pr-url : ${{ github.event.issue.pull_request.html_url || '' }}
pr-text : ${{ github.event.comment.body || '' }}
dispatch-inputs : ${{ toJSON(inputs) }}
secrets :
DIFFCALC_GOOGLE_CREDENTIALS : ${{ secrets.DIFFCALC_GOOGLE_CREDENTIALS }}
2023-10-05 12:20:07 +08:00
create-comment :
name : Create PR comment
2024-11-09 13:54:19 +08:00
needs : check-permissions
2023-10-05 12:20:07 +08:00
runs-on : ubuntu-latest
2023-10-17 19:15:00 +08:00
if : ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
2023-10-05 12:20:07 +08:00
steps :
- name : Create comment
2024-03-28 23:25:03 +08:00
uses : thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
2023-10-05 12:20:07 +08:00
with :
2023-10-20 02:26:12 +08:00
comment_tag : ${{ env.EXECUTION_ID }}
2023-10-05 12:20:07 +08:00
message : |
Difficulty calculation queued -- please wait! (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
*This comment will update on completion*
2023-10-17 19:15:00 +08:00
output-cli :
2024-11-09 13:54:19 +08:00
name : Info
needs : run-diffcalc
2023-10-17 19:15:00 +08:00
runs-on : ubuntu-latest
steps :
2023-10-05 12:20:07 +08:00
- name : Output info
2021-09-03 16:56:56 +08:00
run : |
2024-11-09 13:54:19 +08:00
echo "Target: ${{ needs.run-diffcalc.outputs.target }}"
echo "Spreadsheet: ${{ needs.run-diffcalc.outputs.sheet }}"
2023-10-20 10:34:08 +08:00
2023-10-05 12:20:07 +08:00
update-comment :
name : Update PR comment
2024-11-09 13:54:19 +08:00
needs : [ create-comment, run-diffcalc ]
2023-10-05 12:20:07 +08:00
runs-on : ubuntu-latest
2023-10-17 19:36:24 +08:00
if : ${{ always() && needs.create-comment.result == 'success' }}
2023-10-05 12:20:07 +08:00
steps :
- name : Update comment on success
2024-11-09 13:54:19 +08:00
if : ${{ needs.run-diffcalc.result == 'success' }}
2024-03-28 23:25:03 +08:00
uses : thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
2023-10-05 12:20:07 +08:00
with :
2023-10-20 02:26:12 +08:00
comment_tag : ${{ env.EXECUTION_ID }}
2024-10-07 14:50:59 +08:00
mode : recreate
2023-10-05 12:20:07 +08:00
message : |
2024-11-09 13:54:19 +08:00
Target : ${{ needs.run-diffcalc.outputs.target }}
Spreadsheet : ${{ needs.run-diffcalc.outputs.sheet }}
2023-10-05 12:20:07 +08:00
- name : Update comment on failure
2024-11-09 13:54:19 +08:00
if : ${{ needs.run-diffcalc.result == 'failure' }}
2024-03-28 23:25:03 +08:00
uses : thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
2023-10-05 12:20:07 +08:00
with :
2023-10-20 02:26:12 +08:00
comment_tag : ${{ env.EXECUTION_ID }}
2024-10-07 14:50:59 +08:00
mode : recreate
2023-10-05 12:20:07 +08:00
message : |
2023-10-05 12:32:20 +08:00
Difficulty calculation failed : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
2023-10-17 19:36:24 +08:00
- name : Update comment on cancellation
2024-11-09 13:54:19 +08:00
if : ${{ needs.run-diffcalc.result == 'cancelled' }}
2024-03-28 23:25:03 +08:00
uses : thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
2023-10-17 19:36:24 +08:00
with :
2023-10-20 02:26:12 +08:00
comment_tag : ${{ env.EXECUTION_ID }}
2023-10-17 19:36:24 +08:00
mode : delete
message : '.' # Appears to be required by this action for non-error status code.