diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 3dbbf795..3b199408 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -27,7 +27,7 @@ jobs: - name: Test run: dotnet test -c Release --no-build --verbosity normal - - name: Pack + - name: Pack Packages run: | dotnet pack NetCord -c Release --no-build dotnet pack NetCord.Services -c Release --no-build @@ -35,14 +35,6 @@ jobs: dotnet pack Hosting/NetCord.Hosting.Services -c Release --no-build dotnet pack Hosting/NetCord.Hosting.AspNetCore -c Release --no-build - - name: Publish - run: | - dotnet nuget push NetCord/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -n -s https://api.nuget.org/v3/index.json --skip-duplicate - dotnet nuget push NetCord.Services/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -n -s https://api.nuget.org/v3/index.json --skip-duplicate - dotnet nuget push Hosting/NetCord.Hosting/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -n -s https://api.nuget.org/v3/index.json --skip-duplicate - dotnet nuget push Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -n -s https://api.nuget.org/v3/index.json --skip-duplicate - dotnet nuget push Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -n -s https://api.nuget.org/v3/index.json --skip-duplicate - - name: Setup Node uses: actions/setup-node@v4 @@ -53,6 +45,16 @@ jobs: npm install npm run build + - name: Publish Packages + env: + KEY: ${{ secrets.NUGET_API_KEY }} + run: | + dotnet nuget push NetCord/bin/Release/*.nupkg -k $KEY -n -s https://api.nuget.org/v3/index.json --skip-duplicate + dotnet nuget push NetCord.Services/bin/Release/*.nupkg -k $KEY -n -s https://api.nuget.org/v3/index.json --skip-duplicate + dotnet nuget push Hosting/NetCord.Hosting/bin/Release/*.nupkg -k $KEY -n -s https://api.nuget.org/v3/index.json --skip-duplicate + dotnet nuget push Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg -k $KEY -n -s https://api.nuget.org/v3/index.json --skip-duplicate + dotnet nuget push Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg -k $KEY -n -s https://api.nuget.org/v3/index.json --skip-duplicate + - name: Deploy Documentation uses: appleboy/scp-action@v0.1.7 with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40f83e57..62748037 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,16 +1,14 @@ name: Build on: - push: - branches-ignore: - - stable - - alpha pull_request: - types: [opened, synchronize] branches: - stable - alpha +concurrency: + group: ${{ github.ref_name }} + jobs: build: runs-on: ubuntu-latest @@ -32,7 +30,7 @@ jobs: - name: Test run: dotnet test -c Release --no-build --verbosity normal - - name: Pack + - name: Pack Packages run: | dotnet pack NetCord -c Release --no-build dotnet pack NetCord.Services -c Release --no-build @@ -40,6 +38,9 @@ jobs: dotnet pack Hosting/NetCord.Hosting.Services -c Release --no-build dotnet pack Hosting/NetCord.Hosting.AspNetCore -c Release --no-build + - name: Setup Node + uses: actions/setup-node@v4 + - name: Build Documentation working-directory: Documentation run: | diff --git a/.github/workflows/cleanup-documentation-preview.yml b/.github/workflows/cleanup-documentation-preview.yml index 9ae7241d..503e42cf 100644 --- a/.github/workflows/cleanup-documentation-preview.yml +++ b/.github/workflows/cleanup-documentation-preview.yml @@ -1,10 +1,12 @@ name: Cleanup Documentation Preview on: - pull_request: + pull_request_target: types: [closed] - paths: - - 'Documentation/**' + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true jobs: documentation-preview: diff --git a/.github/workflows/documentation-preview.yml b/.github/workflows/documentation-preview.yml index 89026e31..803573ac 100644 --- a/.github/workflows/documentation-preview.yml +++ b/.github/workflows/documentation-preview.yml @@ -1,10 +1,12 @@ name: Documentation Preview on: - pull_request: - types: [opened, synchronize] - paths: - - 'Documentation/**' + workflow_run: + workflows: [Build] + types: [completed] + +concurrency: + group: ${{ github.event.workflow_run.head_branch }} jobs: documentation-preview: @@ -12,30 +14,35 @@ jobs: permissions: pull-requests: write + actions: read steps: - - uses: actions/checkout@v4 + - name: Get PR context + id: pr-context + env: + # Token required for GH CLI: + GH_TOKEN: ${{ github.token }} + # Best practice for scripts is to reference via ENV at runtime. Avoid using the expression syntax in the script content directly: + PR_TARGET_REPO: ${{ github.repository }} + # If the PR is from a fork, prefix it with `:`, otherwise only the PR branch name is relevant: + PR_BRANCH: |- + ${{ + (github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login) + && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) + || github.event.workflow_run.head_branch + }} + # Query the PR number by repo + branch, then assign to step output: + run: | + gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \ + --json 'number' --jq '"number=\(.number)"' \ + >> "${GITHUB_OUTPUT}" - - name: Setup .NET - uses: actions/setup-dotnet@v4 + - name: Download Documentation + uses: actions/download-artifact@v4 with: - dotnet-version: 8.0.x - - - name: Restore dependencies - run: dotnet restore - - - name: Build - run: dotnet build -c Release --no-restore --warnaserror - - - name: Test - run: dotnet test -c Release --no-build --verbosity normal - - - name: Build Documentation - working-directory: Documentation - run: | - dotnet tool install docfx -g --version 2.75.3 - npm install - npm run build + name: Documentation Artifacts + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} - name: Deploy Documentation Preview uses: appleboy/scp-action@v0.1.7 @@ -45,18 +52,31 @@ jobs: port: ${{ secrets.SSH_PORT }} key: ${{ secrets.SSH_KEY }} rm: true - source: Documentation/_site - strip_components: 2 - target: ~/NetCord/preview/html/${{ github.event.pull_request.number }} + source: . + target: ~/NetCord/preview/html/${{ steps.pr-context.outputs.number }} - name: Notify Documentation Preview uses: actions/github-script@v7 + env: + PR_NUMBER: ${{ steps.pr-context.outputs.number }} with: script: | - const number = context.issue.number; - github.rest.issues.createComment({ + const number = process.env.PR_NUMBER; + + const { data: comments } = await github.rest.issues.listComments({ issue_number: number, owner: context.repo.owner, repo: context.repo.repo, - body: `The documentation preview is available at https://preview.netcord.dev/${number}.`, - }) + }); + + const body = `The documentation preview is available at https://preview.netcord.dev/${number}.`; + const duplicateComment = comments.find(comment => comment.user.id === 41898282 && comment.body === body); + + if (!duplicateComment) { + await github.rest.issues.createComment({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body, + }); + }