-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve workflows * Fix concurrency * Make documentation preview notification trigger only once * Update job permissions and standardize PR context step Updated job permissions in `documentation-preview.yml` to set `pull-requests` to `write` and `actions` to `read`. Standardized the step name for retrieving PR context by removing single quotes. Added an `id` field (`pr-context`) to the `Get PR context` step. Defined environment variables for the `Get PR context` step, including a comment on best practices for referencing environment variables.
- Loading branch information
Showing
4 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,22 +27,14 @@ 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 | ||
dotnet pack Hosting/NetCord.Hosting -c Release --no-build | ||
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/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,48 @@ | ||
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: | ||
runs-on: ubuntu-latest | ||
|
||
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 `<owner-login>:`, 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/[email protected] | ||
|
@@ -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, | ||
}); | ||
} |