-
Notifications
You must be signed in to change notification settings - Fork 625
Enable spec-lint action in 1.0-dev branch #191
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "Registrations": [ | ||
| { | ||
| "Component": { | ||
| "Type": "git", | ||
| "Git": { | ||
| "RepositoryUrl": "https://github.com/rpm-software-management/spec-cleaner", | ||
| "CommitHash": "f24cd83e5e2775b061696d4fd7fcf47f63514b50" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "Version": 1 | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| name: Spec Linting | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - '**.spec' | ||
| branches: [main, dev, 1.0*] | ||
| pull_request: | ||
| paths: | ||
| - '**.spec' | ||
| branches: [main, dev, 1.0*] | ||
|
|
||
| jobs: | ||
| spec-lint: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Checkout the branch of our repo that triggered this action | ||
| - name: Workflow trigger checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Get base commit for PRs | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| run: | | ||
| git fetch origin ${{ github.base_ref }} | ||
| echo "base_sha=$(git rev-parse origin/${{ github.base_ref }})" >> $GITHUB_ENV | ||
| echo "Merging ${{ github.sha }} into ${{ github.base_ref }}" | ||
|
|
||
| - name: Get base commit for Pushes | ||
| if: ${{ github.event_name == 'push' }} | ||
| run: | | ||
| git fetch origin ${{ github.event.before }} | ||
| echo "base_sha=${{ github.event.before }}" >> $GITHUB_ENV | ||
| echo "Merging ${{ github.sha }} into ${{ github.event.before }}" | ||
|
|
||
| - name: Get the changed files | ||
| run: | | ||
| echo "Files changed: '$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }})'" | ||
| changed_specs=$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }} | { grep "\.spec$" || test $? = 1; }) | ||
| echo "Files to validate: '${changed_specs}'" | ||
| echo "updated-specs=$(echo ${changed_specs})" >> $GITHUB_ENV | ||
|
|
||
| - name: Main branch checkout | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| ref: 'main' | ||
| path: 'main-checkout' | ||
|
|
||
| # Our linter is based on the spec-cleaner tool from the folks at openSUSE | ||
| # We apply a patch to modify it for CBL-Mariner's needs | ||
| - name: spec-cleaner checkout | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| repository: 'rpm-software-management/spec-cleaner' | ||
| ref: 'spec-cleaner-1.2.0' | ||
| path: 'spec-cleaner' | ||
|
|
||
| # For consistency, we use the same major/minor version of Python that CBL-Mariner ships | ||
| - name: Setup Python 3.7 | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: 3.7 | ||
|
|
||
| # We take our version of the linting tool from the master branch to ensure rules | ||
| # are consistent across all branches | ||
| - name: Patch spec-cleaner with Mariner-specific lints | ||
| run: | | ||
| pushd spec-cleaner | ||
| git apply ../main-checkout/.github/workflows/mariner-spec-cleaner.patch | ||
| popd | ||
|
|
||
| - name: Install patched spec-cleaner | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ./spec-cleaner | ||
|
|
||
| # Set continue-on-error to true if we're blocking too many PRs here | ||
| # We don't want this tool to have a low signal-to-noise ratio | ||
| - name: Lint changed spec files | ||
| continue-on-error: true | ||
| run: | | ||
| mkdir -p linted_specs | ||
| spec-cleaner -o linted_specs ${{ env.updated-specs }} | ||
| [ -n "$(ls -A linted_specs)" ] \ | ||
| && echo "Specs are not correctly formatted." \ | ||
| && echo "The linted_specs artifact contains linted versions of the specs you're checking in." \ | ||
| && echo "Please properly format your specs according to that output before merging." \ | ||
| && exit 1 | ||
|
|
||
| - uses: actions/upload-artifact@v2 | ||
| with: | ||
| name: linted_specs | ||
| path: linted_specs | ||
| if-no-files-found: ignore | ||
| if: always() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind
test $? = 1;at the very end? It looks like it would make us succeed even ifgrepfound no .spec files being modified, which I guess should never happen considering thepathsat the beginning of this file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall my reasoning (I wrote the cgmanifest script this filter was taken from)... grep returns an error if it doesn't find any matches, so you need to explicitly catch that return code and ignore it.