diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e462ab9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: Continuous Integration + +on: + push: + branches: [develop] + pull_request: + +permissions: + contents: read + +jobs: + test: + name: Test + runs-on: ${{ matrix.os.fullname }} + timeout-minutes: 60 + env: + OSU_EXECUTION_MODE: ${{ matrix.threadingMode }} + strategy: + fail-fast: false + matrix: + os: + - { prettyname: Windows, fullname: windows-latest, configuration: Debug } + - { prettyname: macOS, fullname: macos-latest, configuration: Debug } # ARM: veja o item 3 abaixo + - { prettyname: Linux, fullname: ubuntu-latest, configuration: Debug } + - { prettyname: Linux, fullname: ubuntu-latest, configuration: Release } + threadingMode: ["SingleThread", "MultiThreaded"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install .NET 10.0.x + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Compile + run: dotnet build -c ${{ matrix.os.configuration }} osu-framework-msdf.slnx + + - name: Test + run: > + dotnet test osu-framework-msdf.slnx + -c ${{ matrix.os.configuration }} + --no-build + --results-directory ${{ github.workspace }}/TestResults + --logger "trx;LogFileName=TestResults-${{ matrix.os.prettyname }}-${{ matrix.threadingMode }}-${{ matrix.os.configuration }}.trx" + -- NUnit.ConsoleOut=0 + + # Sobe os resultados mesmo se o teste falhar. + - name: Upload Test Results + uses: actions/upload-artifact@v4 + if: ${{ always() }} + with: + name: libmsdf-test-results-${{ matrix.os.prettyname }}-${{ matrix.threadingMode }}-${{ matrix.os.configuration }} + path: ${{ github.workspace }}/TestResults/TestResults-${{ matrix.os.prettyname }}-${{ matrix.threadingMode }}-${{ matrix.os.configuration }}.trx + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9ac9f08 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,144 @@ +name: Package and NuGet + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+*" + +permissions: + contents: read + +jobs: + notify_process_deploy: + name: Notify start + runs-on: ubuntu-latest + continue-on-error: true + env: + WEBHOOK_URL: ${{ secrets.DISCORD_INFRA_WEBHOOK_URL }} + steps: + - name: Notify Deployment + run: | + export TITLE="🚀 Deployment in Progress: libmsdf ($GITHUB_REF_NAME)" + export URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + export DESCRIPTION="A new deployment for **libmsdf** has started."$'\n'"Stay tuned for updates!"$'\n'"➜ [View Workflow Run]($URL)" + export ACTOR_ICON="https://avatars.githubusercontent.com/u/$GITHUB_ACTOR_ID" + + BODY="$(jq --null-input '{ + embeds: [{ + title: env.TITLE, + color: 15098112, + description: env.DESCRIPTION, + url: env.URL, + author: { name: env.GITHUB_ACTOR, icon_url: env.ACTOR_ICON } + }] + }')" + + curl --fail -H "Content-Type: application/json" -d "$BODY" "$WEBHOOK_URL" + + test: + name: Test (${{ matrix.threadingMode }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: true + matrix: + threadingMode: ["SingleThread", "MultiThreaded"] # TODO: corte se não usar GameHost, igual ao ci.yml + env: + OSU_EXECUTION_MODE: ${{ matrix.threadingMode }} + steps: + - name: Checkout + uses: actions/checkout@v4 # TODO: fixar por SHA + with: + persist-credentials: false + + - name: Install .NET + uses: actions/setup-dotnet@v4 # TODO: fixar por SHA + with: + dotnet-version: "10.0.x" + + - name: Test + run: dotnet test SuaSolucao.sln -c Release # TODO: nome real da .sln + + pack: + name: Pack (libmsdf) + needs: [test] + runs-on: ubuntu-latest + environment: production + timeout-minutes: 15 + permissions: + contents: read + id-token: write + env: + ARTIFACTS: ${{ github.workspace }}/artifacts + VERSION: ${{ github.ref_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 # TODO: fixar por SHA + with: + persist-credentials: false + + - name: Install .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Pack (libmsdf) + run: dotnet pack lib -c Release /p:Version="${VERSION#v}" -o "$ARTIFACTS" + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: libmsdf + path: ${{ github.workspace }}/artifacts/*.nupkg + if-no-files-found: error + + - name: NuGet login (OIDC) + id: login + uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 + with: + user: ${{ vars.NUGET_USER }} + + - name: Publish packages to NuGet + env: + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} + run: > + dotnet nuget push "$ARTIFACTS"/*.nupkg + --api-key "$NUGET_API_KEY" + --source https://api.nuget.org/v3/index.json + --skip-duplicate + + notify_status_deploy: + name: Notify result + needs: [test, pack] + if: always() + runs-on: ubuntu-latest + continue-on-error: true + env: + PACK_RESULT: ${{ needs.pack.result }} + WEBHOOK_URL: ${{ secrets.DISCORD_INFRA_WEBHOOK_URL }} + steps: + - name: Notify Deployment Status + run: | + export TITLE="🚀 Deployment Completed: libmsdf ($GITHUB_REF_NAME)" + export URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + + if [ "$PACK_RESULT" = "success" ]; then + STATUS="✅ Deployment successful!"; export COLOR=3066993 + else + STATUS="❌ Deployment failed. Check logs for details."; export COLOR=15158332 + fi + + export DESCRIPTION="Deployment for **libmsdf** has finished."$'\n'"$STATUS"$'\n'"➜ [View Workflow Run]($URL)" + export ACTOR_ICON="https://avatars.githubusercontent.com/u/$GITHUB_ACTOR_ID" + + BODY="$(jq --null-input '{ + embeds: [{ + title: env.TITLE, + color: (env.COLOR | tonumber), + description: env.DESCRIPTION, + url: env.URL, + author: { name: env.GITHUB_ACTOR, icon_url: env.ACTOR_ICON } + }] + }')" + + curl --fail -H "Content-Type: application/json" -d "$BODY" "$WEBHOOK_URL" diff --git a/.github/workflows/report-nunit.yml b/.github/workflows/report-nunit.yml new file mode 100644 index 0000000..52aaba7 --- /dev/null +++ b/.github/workflows/report-nunit.yml @@ -0,0 +1,42 @@ +name: Annotate CI run with Test Results + +on: + workflow_run: + workflows: ["Continuous Integration"] + types: [completed] + +permissions: + contents: read + actions: read + checks: write + +jobs: + annotate: + name: Annotate CI run with Test Results + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion != 'cancelled' }} + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repository: ${{ github.event.workflow_run.repository.full_name }} + ref: ${{ github.event.workflow_run.head_sha }} + persist-credentials: false + + - name: Download results + uses: actions/download-artifact@v4 + with: + pattern: libmsdf-test-results-* + merge-multiple: true + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Annotate CI run with Test Results + uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 + with: + name: Results + path: "*.trx" + reporter: dotnet-trx + list-suites: "failed" + list-tests: "failed"