Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/cgmanifest.json
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
}
95 changes: 95 additions & 0 deletions .github/workflows/lint-specs.yml
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; })
Copy link
Copy Markdown
Contributor

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 if grep found no .spec files being modified, which I guess should never happen considering the paths at the beginning of this file.

Copy link
Copy Markdown
Contributor

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.

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()
Loading