Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: formatting: add check on push and pull-request #810

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
}
},
"remoteUser": "root"
}
}
20 changes: 19 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
* text=auto
* text=auto
kkanas marked this conversation as resolved.
Show resolved Hide resolved

# Explicitly declare text files you want to always be normalized and converted to LF upon checkout.
*.c text eol=lf
*.cpp text eol=lf
*.h text eol=lf
*.txt text eol=lf
*.json text eol=lf
*.yml text eol=lf
*.md text eol=lf

# Explicitly declare text files you want to always be normalized and converted to CRLF upon checkout.
*.cmd text eol=crlf
kkanas marked this conversation as resolved.
Show resolved Hide resolved
*.csrpoj text eol=crlf


# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
- [ ] I have read the [contribution guidelines](https://github.com/Azure/azure-osconfig/blob/main/CONTRIBUTING.md).
- [ ] I added unit-tests to validate my changes. All unit tests are passing.
- [ ] I have merged the latest `dev` branch prior to this PR submission.
- [ ] I submitted this PR against the `dev` branch.
- [ ] I submitted this PR against the `dev` branch.
2 changes: 1 addition & 1 deletion .github/actions/check-perf/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:

echo "Checking '$perflog' for any performance warnings"
echo "Contents of '$perflog':"
cat "$perflog"
cat "$perflog"

warnings=$(grep -i "$mark" $perflog || true)

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/check-run/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ runs:
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $token" \
-d @data.json
shell: bash
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/container-run/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ runs:

echo Container ID: $id
echo id=$id >> $GITHUB_OUTPUT
shell: bash
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/footprint-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ runs:
if [ "$result" == 1 ]; then
echo "::error Binary footprint validation failed. Delta: $delta" && exit 1
fi
shell: bash
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/gtest-xml/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ runs:

with open(output, 'w') as f:
new_tree.write(f, encoding='unicode')
shell: python
shell: python
2 changes: 1 addition & 1 deletion .github/actions/pmc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM mcr.microsoft.com/pmc/pmc-cli:latest

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion .github/workflows/build-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
description: 'Rebuild all containers'
default: false
type: boolean

env:
REGISTRY: ghcr.io
BUILD_TYPE: Release
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fail-fast: false
matrix:
target: ${{ fromJson(needs.create-ci-matrix.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -118,4 +118,4 @@ jobs:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: 'ci-test/*-sanitizer.xml'
files: 'ci-test/*-sanitizer.xml'
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
# ]
# EOL
# )"
#
#
# Add arm64 distros only on scheduled runs to prevent long CI times for PRs
# if [ "${{ github.event_name }}" == "schedule" ]; then
# matrix=$(jq --argjson arm64Targets "$arm64Targets" '. += $arm64Targets' <<< "$matrix")
Expand All @@ -71,7 +71,7 @@ jobs:
fail-fast: false
matrix:
target: ${{ fromJson(needs.create-ci-matrix.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -149,9 +149,9 @@ jobs:
with:
path: ci-test
pattern: 'unit-test-*'
merge-multiple: true
merge-multiple: true

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: 'ci-test/*.xml'
files: 'ci-test/*.xml'
18 changes: 18 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Code Formatting

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
2 changes: 1 addition & 1 deletion .github/workflows/fuzzing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
target: ${{ matrix.target.os }}-${{ matrix.target.version }}
arch: ${{ matrix.arch }}
package-type: ${{ matrix.target.package-type }}
timeout-seconds: 3600
timeout-seconds: 3600
2 changes: 1 addition & 1 deletion .github/workflows/insiders-fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
target:
[
# Skip ARM64 CI builds for now
# Skip ARM64 CI builds for now
{ os: amazonlinux, version: 2, arch: amd64, dist: amazonlinux2, package-type: RPM, repo: microsoft-amazonlinux2-insiders-fast-prod-yum, container-tag: latest },
{ os: centos, version: 7, arch: amd64, dist: centos7, package-type: RPM, repo: microsoft-centos7-insiders-fast-prod-yum, container-tag: latest },
{ os: centos, version: 8, arch: amd64, dist: centos8, package-type: RPM, repo: microsoft-centos8-insiders-fast-prod-yum, container-tag: latest },
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/module-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
target: ${{ matrix.target.os }}-${{ matrix.target.version }}
arch: ${{ matrix.arch }}
package-type: ${{ matrix.target.package-type }}
excluded-tests: ${{ matrix.target.excluded-tests }}
excluded-tests: ${{ matrix.target.excluded-tests }}
2 changes: 1 addition & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ jobs:
--target ${{ github.sha }} \
--generate-notes \
--latest \
*.deb
*.deb
6 changes: 3 additions & 3 deletions .github/workflows/universalnrp-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ jobs:
Write-Host "Renaming $($_.Name) to $name.zip"
Rename-Item -Path $_.Name -NewName "$name.zip"
}

- name: Check package size
if: success() || failure()
uses: ./.github/actions/check-size
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
with:
perflog: /var/log/osconfig_asb_perf.log
mark: "is longer than"

- name: Stage OSConfig Logs
if: success() || failure()
run: |
Expand Down Expand Up @@ -339,4 +339,4 @@ jobs:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: 'universal-nrp-test/*testResults.xml'
files: 'universal-nrp-test/*testResults.xml'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ node_modules
# Terraform
.terraform/
.terraform.lock.hcl
*.tfstate*
*.tfstate*
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
exclude: |
(?x)(
^src/tests/fuzzer/seed_corpus/.*$
)$
- id: trailing-whitespace
- id: mixed-line-ending
args: ['--fix', 'lf']
files: |
(?x)(
.*\.c|
.*\.h|
.*\.cpp|
.*\.hpp|
.*\.cs|
.*\.md|
.*\.cmake|
.*\.toml|
.*\.json|
.*\.txt
)$
- id: mixed-line-ending
args: ['--fix', 'crlf']
files: |
(?x)(
.*\.cmd|
.*\.csrpoj
)$
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"files.associations": {
"*.json": "jsonc"
}
}
}
47 changes: 45 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
# Contributing

We welcome contributions to OSConfig. The main way of contributing to and extending OSConfig is via developing new **Management Modules**. For more information see [OSConfig Management Modules](docs/modules.md).

Pull requests with few exceptions must contain appropriate unit-tests. We cannot allow test coverage to go down. Pull requests containing code changes without accompanying unit tests may be rejected.
Pull requests needs to be formatted according to .pre-commit-config.yaml. Each pull request is checked by [Forrmating Tests](https://github.com/Azure/azure-osconfig/blob/dev/.github/workflows/formatting.yml).

Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

Expand All @@ -25,6 +25,49 @@ Most contributions require you to agree to a Contributor License Agreement (CLA)

The OSConfig Core team will respond to a PR that passes all checks in 3 business days.

### Run code Formatting locally for PR

Azure Device OS Configuration (OSConfig) uses [pre-commit](https://pre-commit.com/) configured in .pre-commit-config.yaml
To set it up as git pre-commit hook:

#### 0. Install python

##### Windows

```cmd
python
```
If python is not installed this will open browser and with Microsoft Store, where you can install python3.
Then go to step 1. Linux & Windows

##### Linux

```bash
sudo apt-get install python3
```

##### 1. Linux & Windows

1. Install python pre-commit-hook package

```cmd
pip3 install pre_commit
```

2. Install .git/pre-commit hook

```cmd
python3 -m pre_commit install
```

This will install allow pre-commit to run locally on each commit.

To run pre-commit manually you can always

```
python3 -m pre_commit run --all-files
```

# Contact

You may contact the OSConfig Core team at [[email protected]](mailto:[email protected]) to ask questions about OSConfig, to report bugs, to suggest new features, or inquire about any other OSConfig related topic.
MariusNi marked this conversation as resolved.
Show resolved Hide resolved
You may contact the OSConfig Core team at [[email protected]](mailto:[email protected]) to ask questions about OSConfig, to report bugs, to suggest new features, or inquire about any other OSConfig related topic.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
```
Loading
Loading