Skip to content

Commit

Permalink
Tidy up CI.yaml and update versions in README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetmatharu committed Dec 16, 2024
1 parent 5de142b commit dc2f135
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@ name: CI

on:
push:
schedule:
- cron: 0 11 * * 2
pull_request:
branches:
- main
schedule:
- cron: "0 11 * * 2" # Every Tuesday at 11:00 UTC

jobs:
docker:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
# Checkout repository code
- name: Checkout code
uses: actions/checkout@v4

# Gather Docker metadata
- name: Gather metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
PuneetMatharu/cmake-format
images: PuneetMatharu/cmake-format

# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export to Docker

# Build and export Docker image
- name: Build and export Docker image
uses: docker/build-push-action@v4
with:
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
push: false # Don't push the image
load: true # Load the image into Docker daemon
tags: ${{ steps.meta.outputs.tags }} # Use metadata tags
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To use this action, pass arguments to the `args` element as you would to `cmake-
```yaml
- name: Format CMake files
id: cmake-format
uses: PuneetMatharu/cmake-format-lint-action@v1.0.4
uses: puneetmatharu/cmake-format-lint-action@v1.0.5
with:
# Arguments to be passed to cmake-format.
#
Expand All @@ -35,7 +35,7 @@ To use this action, pass arguments to the `args` element as you would to `cmake-
# Regex to select which files to apply cmake-format on.
#
# Defaults to '(.*\.cmake$|CMakeLists.txt$)'
file-regex: '(.*\.cmake$|.*\.cmake\.in$|CMakeLists.txt$)'
files: '(.*\.cmake$|.*\.cmake\.in$|CMakeLists.txt$)'
```
You will probably want to pair this with a GitHub Action (such as
Expand All @@ -57,13 +57,13 @@ jobs:
- name: Format CMake files
id: cmake-format
uses: PuneetMatharu/cmake-format-lint-action@v1.0.4
uses: puneetmatharu/cmake-format-lint-action@v1.0.5
with:
args: --config-files .cmake-format.json --in-place
file-regex: '(.*\.cmake$|.*\.cmake\.in$|CMakeLists.txt$)'
files: '(.*\.cmake$|.*\.cmake\.in$|CMakeLists.txt$)'
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: cmake-format-bot
commit_message: 'Automated commit of cmake-format changes.'
Expand Down
21 changes: 13 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inputs:
required: true
default: "--help"

file-regex:
files:
description: |
Regex to select which files to apply cmake-format on.
Expand All @@ -38,10 +38,15 @@ inputs:
default: '(.*\.cmake$|CMakeLists.txt$)'

runs:
using: "docker"
image: "Dockerfile"
args:
- "--file-regex"
- "${{ inputs.file-regex }}"
- "--args"
- "${{ inputs.args }}"
using: "composite"
steps:
- name: Set up python3
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Format CMake files
id: cmake-format
shell: bash
run: python3 format.py --cmake-format-args ${{ inputs.args }} --file-regex '${{ inputs.files }}'
5 changes: 2 additions & 3 deletions entrypoint.py → format.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def format_cmake_file(file_and_args: Tuple[Path, str]) -> Optional[str]:
cmake_format_result = subprocess.run(cmake_command, shell=True, capture_output=True, text=True)
if cmake_format_result.returncode != 0:
return f"Error formatting {file_path}: {cmake_format_result.stderr}"
return None
return f"Successfully formatted {file_path}!"


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -44,7 +44,6 @@ def parse_args() -> argparse.Namespace:
with Pool() as pool:
format_results = pool.map(format_cmake_file, matched_files)
for result in format_results:
if result:
print(result)
print(result)
else:
print("No files matched the given regex.")

0 comments on commit dc2f135

Please sign in to comment.