diff --git a/.github/actions/build_dotnet/action.yml b/.github/actions/build_dotnet/action.yml new file mode 100644 index 0000000..b118164 --- /dev/null +++ b/.github/actions/build_dotnet/action.yml @@ -0,0 +1,37 @@ +name: 'Build .Net' +description: 'Build .Net project' +inputs: + output_folder: + description: 'Output folder' + required: false + default: "./build" + project_name: + description: 'Project name' + required: false + default: "ZZZTOJ.Botris" + self_contained: + description: 'Self contained' + required: false + default: "false" + single_file: + description: 'Publish single file' + required: false + default: "true" +runs: + using: "composite" + steps: + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Install dependencies + shell: bash + run: dotnet restore + - name: Build and publish + shell: bash + run: | + mkdir ${{ inputs.output_folder }} + dotnet publish ${{ inputs.project_name }} -p:PublishSingleFile=${{ inputs.single_file }} --self-contained ${{ inputs.self_contained }} -o ${{ inputs.output_folder }} + - name: Remove pdb files + shell: bash + run: rm ${{ inputs.output_folder }}/*.pdb \ No newline at end of file diff --git a/.github/actions/get_tetris_ai/action.yml b/.github/actions/get_tetris_ai/action.yml new file mode 100644 index 0000000..74c5ef3 --- /dev/null +++ b/.github/actions/get_tetris_ai/action.yml @@ -0,0 +1,31 @@ +name: 'Get tetris_ai_runner' +description: 'Get tetris_ai_runner' +inputs: + os: + description: 'Running OS' + required: true + output_folder: + description: 'Output folder' + required: false + default: "./build" +runs: + using: "composite" + steps: + - name: Download tetris_ai_runner + env: + TETRIS_AI_INPUT_FILENAME: ${{ fromJSON('{"macos":"libtetris_ai.dylib","ubuntu":"libtetris_ai.so","windows":"tetris_ai.dll"}')[inputs.os] }} + uses: robinraju/release-downloader@v1.9 + with: + repository: TetrisAI/tetris_ai_runner + latest: true + preRelease: true + fileName: ${{ TETRIS_AI_INPUT_FILENAME }} + tarBall: false + zipBall: false + out-file-path: ${{ inputs.output_folder }} + - name: Rename tetris_ai_runner + env: + TETRIS_AI_INPUT_FILENAME: ${{ fromJSON('{"macos":"libtetris_ai.dylib","ubuntu":"libtetris_ai.so","windows":"tetris_ai.dll"}')[inputs.os] }} + TETRIS_AI_OUTPUT_FILENAME: ${{ fromJSON('{"macos":"zzz_botris.dylib","ubuntu":"zzz_botris.so","windows":"zzz_botris.dll"}')[inputs.os] }} + shell: bash + run: mv ${{ inputs.output_folder }}/${{ env.TETRIS_AI_INPUT_FILENAME }} ${{ inputs.output_folder }}/${{ env.TETRIS_AI_OUTPUT_FILENAME }} \ No newline at end of file diff --git a/.github/workflows/connect.yml b/.github/workflows/connect.yml new file mode 100644 index 0000000..e90a725 --- /dev/null +++ b/.github/workflows/connect.yml @@ -0,0 +1,74 @@ +name: ZZZBotris Connect To the Room + +on: + workflow_dispatch: + inputs: + os: + description: "Runnning OS" + required: true + type: choice + options: + - macos + - ubuntu + - windows + default: "ubuntu" + token: + description: "BotrisBattle API token" + required: true + type: string + master_key: + description: "BotrisBattle Room Master Key" + required: true + type: string + next_count: + description: "Next count" + required: false + type: number + default: 6 + level: + description: "Level" + required: false + type: number + default: 8 + bpm: + description: "BPM" + required: false + type: number + default: 200 + +jobs: + connect: + runs-on: ${{ inputs.os }}-latest + env: + OUTPUT_FOLDER: ./build + PROJECT_NAME: ZZZTOJ.Botris + steps: + - uses: actions/checkout@v4 + - name: Build Project + uses: ./.github/actions/build_dotnet + with: + output_folder: ${{ env.OUTPUT_FOLDER }} + project_name: ${{ env.PROJECT_NAME }} + - name: Get tetris_ai_runner + uses: ./.github/actions/get_tetris_ai + with: + os: ${{ inputs.os }} + output_folder: ${{ env.OUTPUT_FOLDER }} + - name: Generate bot config + shell: python3 {0} + run: | + import json + config = { + "NextCnt": ${{ inputs.next_count }}, + "Level": ${{ inputs.level }}, + "BPM": ${{ inputs.bpm }}, + "Token": "${{ inputs.token }}", + "RoomKey": "${{ inputs.master_key }}" + } + json.dump(config, open("${{ env.OUTPUT_FOLDER }}/botconfig.json", "w")) + - name: Run bot + shell: bash + run: | + pushd ${{ env.OUTPUT_FOLDER }} + chmod +x ${{ env.PROJECT_NAME }} + ./${{ env.PROJECT_NAME }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 59512c4..c150e9c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -23,30 +23,16 @@ jobs: TETRIS_AI_OUTPUT_FILENAME: ${{ fromJSON('{"macos":"zzz_botris.dylib","ubuntu":"zzz_botris.so","windows":"zzz_botris.dll"}')[matrix.os] }} steps: - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 + - name: Build Project + uses: ./.github/actions/build_dotnet with: - dotnet-version: 8.0.x - - name: Install dependencies - run: dotnet restore - - name: Build and publish - run: | - mkdir ${{ env.OUTPUT_FOLDER }} - dotnet publish ${{ env.PROJECT_NAME }} -p:PublishSingleFile=true --self-contained false -o ${{ env.OUTPUT_FOLDER }} - - name: Remove pdb files - run: rm ${{ env.OUTPUT_FOLDER }}/*.pdb + output_folder: ${{ env.OUTPUT_FOLDER }} + project_name: ${{ env.PROJECT_NAME }} - name: Get tetris_ai_runner - uses: robinraju/release-downloader@v1.9 + uses: ./.github/actions/get_tetris_ai with: - repository: TetrisAI/tetris_ai_runner - latest: true - preRelease: true - fileName: ${{ env.TETRIS_AI_INPUT_FILENAME }} - tarBall: false - zipBall: false - out-file-path: ${{ env.OUTPUT_FOLDER }} - - name: Rename tetris_ai_runner - run: mv ${{ env.OUTPUT_FOLDER }}/${{ env.TETRIS_AI_INPUT_FILENAME }} ${{ env.OUTPUT_FOLDER }}/${{ env.TETRIS_AI_OUTPUT_FILENAME }} + os: ${{ matrix.os }} + output_folder: ${{ env.OUTPUT_FOLDER }} - name: Upload dotnet test results uses: actions/upload-artifact@v4 with: