mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-23 14:42:28 +01:00
CODEBASE: Combine the title and dist checks (#361)
This commit is contained in:
parent
af8528c777
commit
f916007f2d
12
.github/PULL_REQUEST_TEMPLATE
vendored
12
.github/PULL_REQUEST_TEMPLATE
vendored
@ -1,5 +1,3 @@
|
|||||||
# Only bugfix are accepted
|
|
||||||
|
|
||||||
# DELETE THIS AFTER READING
|
# DELETE THIS AFTER READING
|
||||||
|
|
||||||
# READ CONTRIBUTING.md
|
# READ CONTRIBUTING.md
|
||||||
@ -7,10 +5,10 @@
|
|||||||
# PR title
|
# PR title
|
||||||
|
|
||||||
Formatted as such:
|
Formatted as such:
|
||||||
SECTION: PLAYER DESCRIPTION
|
CATEGORY: Change Description
|
||||||
|
|
||||||
SECTION is something like "API", "UI", "MISC", "STANEK", "CORPORATION"
|
CATEGORY is something like "API", "UI", "MISC", "STANEK", etc, and must be uppercase.
|
||||||
PLAYER DESCRIPTION is what you'd tell a non-contributor to convey what is changed.
|
Change Description is what you'd tell a non-contributor to convey what is changed.
|
||||||
|
|
||||||
# Linked issues
|
# Linked issues
|
||||||
|
|
||||||
@ -24,8 +22,8 @@ It'll automate the process.
|
|||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
- DO NOT CHANGE any markdown/\*.md, these files are autogenerated from NetscriptDefinitions.d.ts and will be overwritten
|
- If your PR includes ns API function changes, do not manually modify markdown files.
|
||||||
- DO NOT re-generate the documentation, makes it harder to review.
|
- Instead, you can run `npm run doc` to autogenerate new markdown files that reflect your submitted API changes.
|
||||||
|
|
||||||
# Bug fix
|
# Bug fix
|
||||||
|
|
||||||
|
55
.github/workflows/check-for-generated-files.yml
vendored
55
.github/workflows/check-for-generated-files.yml
vendored
@ -1,55 +0,0 @@
|
|||||||
name: Check for Generated Files
|
|
||||||
|
|
||||||
on:
|
|
||||||
# Triggers the workflow on push or pull request events but only for the dev branch
|
|
||||||
pull_request:
|
|
||||||
branches: [dev]
|
|
||||||
|
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
checkFiles:
|
|
||||||
name: Check Files
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout files
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Check bundle files
|
|
||||||
id: changed-bundle-files
|
|
||||||
uses: tj-actions/changed-files@v18.4
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
dist/*
|
|
||||||
index.html
|
|
||||||
|
|
||||||
- name: Warn when bundle files were changed
|
|
||||||
id: warn-bundles-changed
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "Creating label (if it does not exist)"
|
|
||||||
LABEL="validation: bundle files modified"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
label create "$LABEL" --description "Modifications to this pull request are suggested" --color D93F0B || true
|
|
||||||
|
|
||||||
if [ "${{ steps.changed-bundle-files.outputs.any_changed }}" == "false" ]; then
|
|
||||||
echo "No forbidden files included, removing warning"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr edit "${{ github.event.number }}" --remove-label "$LABEL" || true
|
|
||||||
else
|
|
||||||
echo "Forbidden files included, generating warning"
|
|
||||||
|
|
||||||
touch comment.txt
|
|
||||||
echo "## Generated build files were included. PRs should not normally contain generated files." >> comment.txt
|
|
||||||
echo "" >> comment.txt
|
|
||||||
echo "Review the changes and ensure that including generated files was necessary." >> comment.txt
|
|
||||||
|
|
||||||
echo "Add pr label"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr edit "${{ github.event.number }}" --add-label "$LABEL"
|
|
||||||
echo "And comment on the pr"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr comment "${{ github.event.number }}" --body-file comment.txt --edit-last || pr comment "${{ github.event.number }}" --body-file comment.txt
|
|
||||||
fi
|
|
70
.github/workflows/title-and-dist-checks.yml
vendored
Normal file
70
.github/workflows/title-and-dist-checks.yml
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
name: Validate Title and Check for Dist Changes
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Triggers the workflow on a few types of pull request events but only for the dev branch
|
||||||
|
pull_request:
|
||||||
|
branches: [dev]
|
||||||
|
types: [opened, edited, synchronize, reopened]
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checkFiles:
|
||||||
|
name: Check Files and Title
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout files
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Check bundle files
|
||||||
|
id: changed-bundle-files
|
||||||
|
uses: tj-actions/changed-files@v18.4
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
dist/*
|
||||||
|
|
||||||
|
- name: Warn when dist was changed or title is invalid
|
||||||
|
id: warn-bundles-changed
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Creating labels for dist modification and for invalid title"
|
||||||
|
LABELDIST="warning: includes dist changes"
|
||||||
|
LABELTITLE="error: invalid title"
|
||||||
|
gh --repo "${{ github.repository }}" label create "$LABELDIST" --description "Dist changes should not normally be included" --color EBAE34 || true
|
||||||
|
gh --repo "${{ github.repository }}" label create "$LABELTITLE" --description "PR title must follow specific format" --color D93F0B || true
|
||||||
|
|
||||||
|
echo "Determine dist portion of comment text, and add/remove dist label as appropriate"
|
||||||
|
if [ "${{ steps.changed-bundle-files.outputs.any_changed }}" == "false" ]; then
|
||||||
|
echo "No forbidden files included, removing warning"
|
||||||
|
gh --repo "${{ github.repository }}" pr edit "${{ github.event.number }}" --remove-label "$LABELDIST" || true
|
||||||
|
distText="### No dist changes are detected."
|
||||||
|
else
|
||||||
|
echo "Forbidden files included, generating warning"
|
||||||
|
gh --repo "${{ github.repository }}" pr edit "${{ github.event.number }}" --add-label "$LABELDIST"
|
||||||
|
distText="## Dist changes were included. PRs should not normally contain any changes in the dist folder.\n\nReview the changes and ensure that the included dist changes were necessary."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Validate title"
|
||||||
|
PR_TITLE=$(gh --repo "${{ github.repository }}" pr view "${{ github.event.number }}" --json title --jq .title)
|
||||||
|
TITLE_REGEX="^[0-9A-Z\-]*: .*$"
|
||||||
|
PR_TITLE_VALID=$(echo "$PR_TITLE" | grep -Eq "$TITLE_REGEX" && echo "true" || echo "false")
|
||||||
|
|
||||||
|
echo "Determine title portion of comment text, and add/remove title label as appropriate"
|
||||||
|
if [ "$PR_TITLE_VALID" == "true" ]; then
|
||||||
|
gh --repo "${{ github.repository }}" pr edit "${{ github.event.number }}" --remove-label "$LABELTITLE" || true
|
||||||
|
commentText="$distText \n\n### Title is valid."
|
||||||
|
makeNewComment="${{ steps.changed-bundle-files.outputs.any_changed }}"
|
||||||
|
else
|
||||||
|
gh --repo "${{ github.repository }}" pr edit "${{ github.event.number }}" --add-label "$LABELTITLE" || true
|
||||||
|
commentText="$distText \n\n## The title \`$PR_TITLE\` should match \`$TITLE_REGEX\`\n\nCATEGORY: Change Description\n\nCATEGORY is something like 'API', 'UI', 'MISC', 'STANEK', etc.\n\nChange Description is what you'd tell a non-contributor to convey what is changed."
|
||||||
|
makeNewComment="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Edit existing comment or make a new one (if no comment present and one of the tests failed)"
|
||||||
|
if [ "$makeNewComment" == "true" ]; then
|
||||||
|
gh --repo "${{ github.repository }}" pr comment "${{ github.event.number }}" --body "$(echo -e $commentText)" --edit-last || gh --repo "${{ github.repository }}" pr comment "${{ github.event.number }}" --body "$(echo -e $commentText)"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
gh --repo "${{ github.repository }}" pr comment "${{ github.event.number }}" --body "$(echo -e $commentText)" --edit-last || true
|
||||||
|
fi
|
64
.github/workflows/validate-pr.yml
vendored
64
.github/workflows/validate-pr.yml
vendored
@ -1,64 +0,0 @@
|
|||||||
name: Validate PR
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [dev]
|
|
||||||
types: [opened, edited, synchronize, reopened]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
checkTitle:
|
|
||||||
name: Check Title
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
steps:
|
|
||||||
- name: Validate Title
|
|
||||||
id: validate-pr-title
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "Creating label (if it does not exist)"
|
|
||||||
LABEL="validation: invalid title"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
label create "$LABEL" --description "Modifications to this pull request are requested" --color D93F0B || true
|
|
||||||
|
|
||||||
PR_TITLE=$(\
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr view "${{ github.event.number }}" --json title --jq .title)
|
|
||||||
echo "::set-output name=title::$PR_TITLE"
|
|
||||||
echo "PR Title: $PR_TITLE"
|
|
||||||
|
|
||||||
TITLE_REGEX="^[0-9A-Z\-]*: .*$"
|
|
||||||
PR_TITLE_VALID=$(echo "$PR_TITLE" | grep -Eq "$TITLE_REGEX" && echo "true" || echo "false")
|
|
||||||
|
|
||||||
if [ "$PR_TITLE_VALID" == "true" ]; then
|
|
||||||
echo "Title is valid, removing label"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr edit "${{ github.event.number }}" --remove-label "$LABEL" || true
|
|
||||||
else
|
|
||||||
echo "Invalid Title"
|
|
||||||
ERROR_MSG="$PR_TITLE -> should match -> $TITLE_REGEX"
|
|
||||||
echo "$ERROR_MSG"
|
|
||||||
echo "::set-output name=invalid::true"
|
|
||||||
echo "::set-output name=errorMessage::$ERROR_MSG"
|
|
||||||
|
|
||||||
touch comment.txt
|
|
||||||
echo "## The title \`$PR_TITLE\` should match \`$TITLE_REGEX\`" >> comment.txt
|
|
||||||
echo "" >> comment.txt
|
|
||||||
echo "SECTION: FIX #xzyw PLAYER DESCRIPTION" >> comment.txt
|
|
||||||
echo "" >> comment.txt
|
|
||||||
echo 'SECTION is something like "API", "UI", "MISC", "STANEK", "CORPORATION"' >> comment.txt
|
|
||||||
echo 'FIX #xyzw is the issue number, if any' >> comment.txt
|
|
||||||
echo "PLAYER DESCRIPTION is what you'd tell a non-contributor to convey what is changed." >> comment.txt
|
|
||||||
|
|
||||||
echo "Add pr label"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr edit "${{ github.event.number }}" --add-label "$LABEL"
|
|
||||||
echo "And comment on the pr"
|
|
||||||
gh --repo "${{ github.repository }}" \
|
|
||||||
pr comment "${{ github.event.number }}" --body-file comment.txt
|
|
||||||
fi
|
|
||||||
- name: Flag workflow error
|
|
||||||
if: steps.validate-pr-title.outputs.invalid == 'true'
|
|
||||||
run: |
|
|
||||||
echo "${{ steps.validate-pr-title.outputs.errorMessage }}"
|
|
||||||
exit 1
|
|
Loading…
Reference in New Issue
Block a user