DEV Community

Cover image for Check Changed Files Helper ✔️ | GitHub Actions
Fum
Fum

Posted on

Check Changed Files Helper ✔️ | GitHub Actions

Need a way to automate checks on files pushed to your repository? This handy action provides a starting template for open source maintainers to get creative and perform customised checks on individual or multiple files changed on the repository.


My Workflow

Refer to repository README for full details.

GitHub logo funbeedev / CheckChangedFilesHelper

GitHub Action to detect all changed files pushed to repo and perform a check. Copy and configure to your needs.

Check Changed Files Helper ✔️

Check Changed Files Helper

📜 About 📜

Submitted for the GitHub Actions Hackathon on DEV. View the DEV post submission.

GitHub Actions are a feature provided by GitHub as a way to automate workflows useful for managing repositories.

Check Changed Files Helper is a GitHub Action workflow that performs a check on changes made to source files pushed to a repository. Customise this workflow to suit your own repository needs.

This repo shows an example of how GitHub Action workflows can be used to automate checks on files changed in the repo.

This project relies on the Get Changed Files Action available on the GitHub marketplace.
This Action provides all added, renamed and modified files as a JSON file within the runner filesystem. When a file or multiple files are changed on the repo, it will identify and list each in the JSON file.

Check Changed Files

This project relies on the Get Changed Files Action available on the GitHub marketplace.
This Action provides all added, renamed and modified files as a JSON file within the runner filesystem. When a file or multiple files are changed on the repo, it will identify and list each in the JSON file.

Check Changed Files Helper provides a means to add powerful checks for files changed on a repo by providing a bash script called by the Workflow. This script scans each changed file and performs a desired check according to the file extension type. In the examples provided in the repo, the checks are to ensure the following file types are executable: .c .py .js .sh.

The power of bash provides numerous possibilities on how to perform checks. A handy way to automate checks of files submitted to your repository!

Submission Category:

Wacky Wildcards

Yaml File - Code to run Workflow

What you need to use this Workflow
The files needed to run this workflow are placed under the repo path .github/workflows. Fork this repo or copy these files to start customising for your own use.

auto-check-changed-files.yml: YAML file containing the GitHub Actions workflow. This will setup any necessary dependencies and use the Get Changed Files Action to generate a JSON containing all files changed on the repository with every push to the main branch. Following this, the auto-check-changed-files.sh bash script is executed.

auto-check-changed-files.sh: Bash script containing custom check instructions. It scans through each changed file pushed to the repository and performs a basic execution check on each file. Edit this script to extend the recognised file types and checks to be performed.

Additional Resources / Info

Sample workflow checks

All checks successful:

Run echo "job: running script to check changed files:"
job: running script to check changed files:
run-sh: Inside auto-check-changed-files.sh
Content of files.json: [
    "hello-world.c",
    "hello-world.js",
    "hello-world.py",
    "hello-world.sh"
]
number of files to check = 4
checking file: hello-world.c
This is a .c file, executing
Hi from hello-world.c!
checking file: hello-world.js
This is a .js file, executing
Hi from hello-world.js!
checking file: hello-world.py
This is a .py file, executing
Hi from hello-world.py!
checking file: hello-world.sh
This is a .sh file, executing
Hi from hello-world.sh!
job: Done
Enter fullscreen mode Exit fullscreen mode

Some failed checks:

Run echo "job: running script to check changed files:"
job: running script to check changed files:
run-sh: Inside auto-check-changed-files.sh
Content of files.json: [
    "hello-world.c",
    "hello-world.js"
]
number of files to check = 2
checking file: hello-world.c
This is a .c file, executing
hello-world.c: In function ‘main’:
hello-world.c:14:39: error: expected ‘;’ before ‘}’ token
   14 |     printf("Hi from hello-world.c!\n")
      |                                       ^
      |                                       ;
   15 | }
      | ~                                      
checking file: hello-world.js
This is a .js file, executing
/home/runner/work/CheckChangedFilesHelper/CheckChangedFilesHelper/hello-world.js:8
console.logg("Hi from hello-world.js!");
        ^

TypeError: console.logg is not a function
    at Object.<anonymous> (/home/runner/work/CheckChangedFilesHelper/CheckChangedFilesHelper/hello-world.js:8:9)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47
Error: Process completed with exit code 1.
Enter fullscreen mode Exit fullscreen mode

Questions, suggestions and comments are welcome!

Top comments (0)