Skip to content

Commit

Permalink
Feature/update/githooks (tianocore#302)
Browse files Browse the repository at this point in the history
enable pre-commit and add two separate configs that can be used when developing in the edk2-pytool-library project.
  • Loading branch information
Flickdm authored Apr 20, 2023
1 parent 0e64786 commit 097d94e
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 48 deletions.
9 changes: 7 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"DYNAMICVPD",
"DYNAMICEXHII",
"DYNAMICEXVPD",
"DYNAMICEX",
"PCD's",
"MDEPKG",
"iommu",
Expand All @@ -96,6 +97,10 @@
"nonlocalizable",
"mkdocs",
"DBXFILE",
"decodefs"
"decodefs",
"Guids",
"apath",
"vsvars",
"packagepatahlist"
]
}
}
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/doc_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ body:
label: Additional context
description: "Any other additional context about the problem not covered by the above."
validations:
required: false
required: false
18 changes: 9 additions & 9 deletions .github/workflows/CIRunner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ jobs:
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'

- name: Install pip Dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade -r requirements.txt
pip install --upgrade -r docs/user/requirements.txt
pip install -e .
- name: Set up Node ${{ inputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- name: Install npm Dependencies
run: |
npm install -g [email protected]
npm install -g [email protected]
- name: Run flake8
if: success() || failure()
run: flake8 ${{ inputs.package-src }}

- name: Run markdownlint
if: success() || failure()
run: markdownlint "**/*.md"

- name: Run cspell
if: success() || failure()
run: cspell -c .cspell.json "**/*.py" "**/*.md"

- name: Run pydocstyle
if: success() || failure()
run: pydocstyle ${{ inputs.package-src }}

- name: Run mkdocs build
if: success() || failure()
run: mkdocs build --strict

- name: Run basic dev tests
if: success() || failure()
run: python BasicDevTests.py
10 changes: 5 additions & 5 deletions .github/workflows/UnitTestRunner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
python-version: ${{ fromJson(inputs.python-versions) }}
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v3

Expand All @@ -31,24 +31,24 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install pip Dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade -r requirements.txt
pip install -e .
- name: Run Unit Tests
run: coverage run -m pytest

- name: Format Coverage results
run: coverage xml

- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
verbose: false

- uses: actions/upload-artifact@v3
with:
name: Artifacts-${{matrix.os}}-${{matrix.python-version}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/VariableProducer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
on:
workflow_call:
outputs:
python-versions:
python-versions:
description: 'Python Versions'
value: ${{ jobs.produce.outputs.python-versions }}
node-versions:
node-versions:
description: 'Node Versions'
value: ${{ jobs.produce.outputs.node-versions }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/doc-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
variables:
name: Variables
uses: ./.github/workflows/VariableProducer.yml

build:
name: Build
needs: variables
Expand All @@ -23,28 +23,28 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ fromJson(needs.variables.outputs.python-versions)[0] }}
uses: actions/setup-python@v4
with:
python-version: ${{ fromJson(needs.variables.outputs.python-versions)[0] }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade -r docs/user/requirements.txt
- name: Build Documentation
run: |
mkdocs build --strict
- name: Upload Github Pages Site Artifact
uses: actions/upload-pages-artifact@v1
with:
name: "github-pages"
path: "site/"

deploy:
name: Deploy

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ on:
branches: [ "master" ]

jobs:

variables:
name: Variables
uses: ./.github/workflows/VariableProducer.yml

ci:
needs: variables
name: CI
Expand All @@ -26,7 +26,7 @@ jobs:
python-version: ${{ fromJson(needs.variables.outputs.python-versions)[0] }}
node-version: ${{ fromJson(needs.variables.outputs.node-versions)[0] }}
package-src: edk2toollib

unit-test:
needs: [variables,ci]
name: Unit Test
Expand Down
2 changes: 1 addition & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{
"default": true,
"MD013": {"line_length": 120, "code_blocks": false }
}
}
2 changes: 1 addition & 1 deletion azure-pipelines/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
endpoint: tianocore

# trigger when a vXX.XX.XX tag is created
trigger:
trigger:
tags:
include:
- v*
Expand Down
43 changes: 39 additions & 4 deletions docs/contributor/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
INFO: Newer editors are very helpful in resolving source formatting errors
(whitespace, indentation, etc). In VSCode open the py file and use
++alt+shift+f++ to auto format.
++alt+shift+f++ to auto format.
2. Run a Basic Python docstring Check (using pydocstring) and resolve any issues
Expand Down Expand Up @@ -130,6 +130,41 @@
markdownlint "**/*.md"
```
### Githooks
Optionally, there are two githooks provided to automate testing locally before running CI
* githooks/basic-pre-commit-config.yaml
* This file runs only the quickest checks in order to test the code for common mistakes
* This yaml will pull in all the tools into an enviornment it needs to run
* githooks/advanced-pre-commit-config.yaml
* This file will run all the basic checks and the longer running checks
* This yaml will need mkdocs installed prior to running
#### Installing
Installing is entirely optional, a developer may choose to run this manually.
The following command will enable this pre-commit to prior to each commit. If it detects
issues it will fail to commit until they are fixed.
```bash
pre-commit install -c githooks/basic-pre-commit-config.yaml
```

#### Running across the entire repository (Manually)

This step is entirely manual but gives a good example of what the behavior of this tool will be.

```bash
pre-commit run --all-files -c githooks/basic-pre-commit-config.yaml
```

#### Uninstalling

```bash
pre-commit uninstall
```

## Conventions Shortlist

### File and folder names
Expand All @@ -140,7 +175,7 @@ naming should follow PEP8 (<https://www.python.org/dev/peps/pep-0008/>)
### Comments

Docstring style comments should be added to each public function and class.
\*Existing code should be updated to be compliant as it is modified.
\*Existing code should be updated to be compliant as it is modified.

### New Module or Class

Expand All @@ -150,7 +185,7 @@ purpose and provide general purpose support.
The module should be added to the package in which the interface is defined.

* For example for modules supporting interfaces defined in the UEFI
specification it would be in the __uefi__ package.
specification it would be in the __uefi__ package.
* If it is defined by EDK2 then it should be in the __uefi.edk2__ package.

Documentation of the feature should be added to the __docs/features__ folder in
Expand All @@ -162,7 +197,7 @@ parameters and usage info.

Unit tests should be written in python unittest or pytest format. A test module
should be added in the same folder or package as the module and the filename
should be same as the module plus "_test".
should be same as the module plus "_test".

### Spell Checking / False Positives

Expand Down
2 changes: 0 additions & 2 deletions docs/user/features/build_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ functionality. However, there are a few problems with that fact.
you to be in a defines section. You have no way to know this from the main
DSC file.

3.

## Why were they made

To better abstract away the essence of what a build is doing. DSC is a way to
Expand Down
12 changes: 8 additions & 4 deletions docs/user/features/windows_firmware_policy.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Windows Firmware Policy Library

This library supports creation and analysis of Windows Firmware Policy binaries
(unsigned)
(unsigned)

## Usage info

Expand All @@ -17,14 +17,18 @@ This library supports creation and analysis of Windows Firmware Policy binaries
covered here).
1. Construct a Dictionary with keys 'Manufacturer', 'Product', 'SerialNumber',
'OEM_01', 'OEM_02', & 'Nonce' populated with the targeting values read from
the device.
the device.
1. Construct an default ```FirmwarePolicy()``` object, then call
```SetDeviceTarget(target_dictionary)``` to populate it with the targeting
information

```SetDeviceTarget(target_dictionary)```

to populate it with the targeting information
1. Bitwise OR the desired ```FirmwarePolicy.FW_POLICY_VALUE_foo``` values into
an integer and pass to ```SetDevicePolicy(64_bit_device_policy)```
1. The FirmwarePolicy object is now ready, serialize it to a file stream using

```SerializeToStream(your_file_stream)```

1. For consumption by a secure device, sign the policy using instructions found
elsewhere

Expand Down
2 changes: 1 addition & 1 deletion edk2toollib/tests/parsers/test_gitingore_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_gitignoreparser_filter(self):
self.assertTrue(rule_tester(os.path.join(root, "reader", "testing.txt")))

# Test a rule which specifies that a folder at any depth from the
# root is correclty filtered.
# root is correctly filtered.

# Example line in a .gitignore
# **/Test/
Expand Down
4 changes: 2 additions & 2 deletions edk2toollib/uefi/edk2/parsers/dsc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __ParseLine(self, Line, file_name=None, lineno=None):
# Other parser returns line_resolved, []. Need to figure out which is right
return ("", [], None)

# not conditional keep procesing
# not conditional keep processing

# check if conditional is active
if (not self.InActiveCode()):
Expand Down Expand Up @@ -189,7 +189,7 @@ def __ParseDefineLine(self, Line):
# Other parser returns line_resolved, []. Need to figure out which is right
return ("", [])

# not conditional keep procesing
# not conditional keep processing

# check if conditional is active
if (not self.InActiveCode()):
Expand Down
Loading

0 comments on commit 097d94e

Please sign in to comment.