diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 4701200a..ebbf6365 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -1,37 +1,45 @@ -name: 'Build' +name: "Build" + inputs: sln-path: - description: 'Path to the solution file relative to the root of the project' + description: "Path to the solution file relative to the root of the project" required: false - default: '.' + default: "." build-config: - description: 'Configuration to build' + description: "Configuration to build" required: true + artifact-name: + description: "Artifact file name" + required: false + default: compiled-dll-${{ github.sha }} + runs: using: "composite" steps: - - name: Add MSBuild to PATH - uses: microsoft/setup-msbuild@v1 + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1 - - name: Restore NuGet packages - working-directory: ${{env.GITHUB_WORKSPACE}} - run: nuget restore ${{inputs.sln-path}} - shell: cmd + - name: Restore NuGet packages + working-directory: ${{ env.GITHUB_WORKSPACE }} + run: nuget restore ${{ inputs.sln-path }} + shell: cmd - - uses: ammaraskar/msvc-problem-matcher@master + - uses: ammaraskar/msvc-problem-matcher@master - - name: Build - working-directory: ${{env.GITHUB_WORKSPACE}} - # Add additional options to the MSBuild command line here (like platform or verbosity level). - # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference - run: msbuild /m /p:Configuration=${{inputs.build-config}} /p:GitCommit=${{github.sha}} /p:GitBranch=${{github.ref}} ${{inputs.sln-path}} - shell: cmd + - name: Build + working-directory: ${{ env.GITHUB_WORKSPACE }} + # Add additional options to the MSBuild command line here (like platform or verbosity level). + # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference + run: msbuild /m /p:Configuration=${{inputs.build-config}} /p:GitCommit=${{github.sha}} /p:GitBranch=${{github.ref}} ${{inputs.sln-path}} + shell: cmd - - name: Upload Artifact - if: ${{success()}} - uses: actions/upload-artifact@v2 - with: - name: compiled-dll-${{github.sha}} - path: | - ${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.dll - ${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.pdb + - name: Upload Artifact + if: ${{ success() }} + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.artifact-name }} + path: | + ${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.dll + ${{inputs.sln-path}}/${{inputs.build-config}}/cncnet5.pdb + ./LICENSE.md + ./README.md diff --git a/.github/workflows/editorconfig.yml b/.github/workflows/editorconfig-checker.yml similarity index 77% rename from .github/workflows/editorconfig.yml rename to .github/workflows/editorconfig-checker.yml index 839ffe73..2ecb28f2 100644 --- a/.github/workflows/editorconfig.yml +++ b/.github/workflows/editorconfig-checker.yml @@ -1,4 +1,4 @@ -name: EditorConfig +name: "Editor Config Checker" on: pull_request: @@ -12,6 +12,6 @@ jobs: lint: runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: editorconfig-checker run: scripts/editorconfig-checker.bat diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml new file mode 100644 index 00000000..4971b231 --- /dev/null +++ b/.github/workflows/nightly-build.yml @@ -0,0 +1,26 @@ +name: "Nightly Build" + +on: + push: + branches: + - main + - develop + +env: + SOLUTION_PATH: . + BUILD_CONFIGURATION: DevBuild + +jobs: + build: + runs-on: windows-2019 + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build + uses: ./.github/actions/build + with: + sln-path: ${{ env.SOLUTION_PATH }} + build-config: ${{ env.BUILD_CONFIGURATION }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml deleted file mode 100644 index 6a66e33a..00000000 --- a/.github/workflows/nightly.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Nightly Build - -on: - push: - branches: - - master - - main - - develop - -env: - # Path to the solution file relative to the root of the project. - SOLUTION_FILE_PATH: . - - # Configuration type to build. - # You can convert this to a build matrix if you need coverage of multiple configuration types. - # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - BUILD_CONFIGURATION: DevBuild - # GIT_COMMIT: $(git rev-parse --short "$GITHUB_SHA") - # GIT_BRANCH: ${GITHUB_REF#refs/heads/} - -jobs: - build: - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Build - uses: ./.github/actions/build # Build steps are reused - with: - sln-path: ${{env.SOLUTION_FILE_PATH}} - build-config: ${{env.BUILD_CONFIGURATION}} diff --git a/.github/workflows/pr-nightly-build.yml b/.github/workflows/pr-nightly-build.yml new file mode 100644 index 00000000..0ccbe7b4 --- /dev/null +++ b/.github/workflows/pr-nightly-build.yml @@ -0,0 +1,23 @@ +name: "Pull Request Nightly Build" + +on: + pull_request: + +env: + SOLUTION_PATH: . + BUILD_CONFIGURATION: DevBuild + +jobs: + build: + runs-on: windows-2019 + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build + uses: ./.github/actions/build + with: + sln-path: ${{ env.SOLUTION_PATH }} + build-config: ${{ env.BUILD_CONFIGURATION }} diff --git a/.github/workflows/pr-nightly-comment.yml b/.github/workflows/pr-nightly-comment.yml new file mode 100644 index 00000000..9284cbdb --- /dev/null +++ b/.github/workflows/pr-nightly-comment.yml @@ -0,0 +1,68 @@ +name: "Nightly Build Comment on Pull Request" +on: + workflow_run: + workflows: ['Pull Request Nightly Build'] + types: [completed] +jobs: + pr_comment: + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + steps: + - name: Get the PR number + run: | + # Query the issue search API to get the PR associated with it + PR_RAW=$(curl 'https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_commit.id }}') + # Get the event number from the search results, which will + # be the PR number + # Filter by PRs only in this repository, as a PR with an identical head commit may be made in another repository (e.g. a fork) + # Assume the 0th index in the array of found PRs is the correct one (it seems to usually be the latest one) + PR_NUM=$(echo $PR_RAW | jq '.items | map(select(.repository_url=="https://api.github.com/repos/${{ github.repository }}")) | .[0].number') + echo "PR_NUM=${PR_NUM}" >> ${GITHUB_ENV} + + - name: Comment on PR + uses: actions/github-script@v7 + with: + # This snippet is public-domain, taken from + # https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml + # and modified to allow comments on external PRs + script: | + async function upsertComment(owner, repo, issue_number, purpose, body) { + const {data: comments} = await github.rest.issues.listComments( + {owner, repo, issue_number}); + + const marker = ``; + body = marker + "\n" + body; + + const existing = comments.filter((c) => c.body.includes(marker)); + if (existing.length > 0) { + const last = existing[existing.length - 1]; + core.info(`Updating comment ${last.id}`); + await github.rest.issues.updateComment({ + owner, repo, + body, + comment_id: last.id, + }); + } else { + core.info(`Creating a comment in issue / PR #${issue_number}`); + await github.rest.issues.createComment({issue_number, body, owner, repo}); + } + } + + const {owner, repo} = context.repo; + const run_id = ${{github.event.workflow_run.id}}; + + const artifacts = await github.paginate( + github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id}); + if (!artifacts.length) { + return core.error(`No artifacts found`); + } + let body = `Nightly build for this pull request:\n`; + for (const art of artifacts) { + body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`; + } + + body += `\nThese artifacts will expire in 90 days and will not be available for download after that time.`; + body += `\n\n_This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build._`; + + core.info("Review thread message body:", body); + await upsertComment(owner, repo, ${{ env.PR_NUM }}, "nightly-link", body); diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 00000000..97407b5e --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,62 @@ +name: "Release Build" + +on: + push: + tags: + - "v*.*.*.*" + +env: + RELEASE_NAME: ${{ github.ref_name }} + ARTIFACT_NAME: cncnet5_${{ github.ref_name }}.zip + + SOLUTION_PATH: . + BUILD_CONFIGURATION: Release + +jobs: + build: + runs-on: windows-2019 + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build + uses: ./.github/actions/build + with: + sln-path: ${{ env.SOLUTION_PATH }} + build-config: ${{ env.BUILD_CONFIGURATION }} + + - name: Create Archive For Release + run: | + mkdir ./artifact + copy ./LICENSE.md ./artifact/LICENSE.md + copy ./README.md ./artifact/README.md + copy ./${{ env.BUILD_CONFIGURATION }}/cncnet5.pdb ./artifact/cncnet5.pdb + copy ./${{ env.BUILD_CONFIGURATION }}/cncnet5.dll ./artifact/cncnet5.dll + 7z a ${{ env.ARTIFACT_NAME }} ./artifact/* + + - name: Upload New Release + uses: softprops/action-gh-release@v2 + with: + name: ${{ env.RELEASE_NAME }} + tag_name: ${{ env.RELEASE_NAME }} + body: ${{ env.RELEASE_NAME }} + append_body: true + draft: true + files: | + ${{ env.ARTIFACT_NAME }} + + request-anti-cheat-build: + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Request AntiCheat Build + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/cncnet/yrpp-spawner-private/actions/workflows/release-build-by-request.yml/dispatches \ + -d '{"ref":"main", "inputs":{"tag": "${{ github.ref_name }}"}}'