Skip to content

Commit

Permalink
Check Makefiles using GitHub actions (#3)
Browse files Browse the repository at this point in the history
This PR introduces GitHub actions.
  • Loading branch information
jdingel authored Nov 15, 2023
1 parent d3bc964 commit 4d7325f
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 15 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/check_makefiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is a basic workflow to help you get started with Actions

name: Check Makefiles

# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, review_requested, ready_for_review]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
tasks:
description: 'Tasks to check (optional); default is all tasks'
default: ''
required: false

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
check:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Check Makefiles
working-directory: tasks/check_makefiles/code
run: bash check_makefiles.sh ${{ github.event.inputs.tasks }}
29 changes: 29 additions & 0 deletions .github/workflows/check_nontask_makefiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This is a basic workflow to help you get started with Actions

name: Check non-task Makefiles

# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, review_requested]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Inputs the workflow accepts.
inputs:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
check:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Check Makefiles
working-directory: tasks/check_makefiles/code
run: bash check_nontask_makefiles.sh
17 changes: 7 additions & 10 deletions paper/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
## DEFINITIONS

FOLDERS = input
PAPER_SECTIONS = $(shell grep '\\input' paper.tex | grep -v '%.*\\input' | sed 's/^.*\\input{\(.*\.tex\)}.*/\1/')
#These two lines are commented out because paper.tex lacks content at the moment:
#PAPER_INPUTS_TEX = $(shell grep '\\input{' $(PAPER_SECTIONS) | grep -v '%.*\\input' | sed 's/^.*\\input{\(.*\.tex\)}.*/\1/')
#PAPER_INPUTS_IMG = $(shell grep --no-filename '\\includegraphics' $(PAPER_SECTIONS) | grep -v '%.*\\includegraphics' | sed 's/^.*\\includegraphics\[.*\]{\(.*\)}.*/\1/')
PAPER_SECTIONS = $(shell grep -v '%.*input' paper.tex | grep -o 'sections/[A-Za-z_]*\.tex')
PAPER_INPUTS = $(shell grep --no-filename 'input/' $(PAPER_SECTIONS) paper.tex | grep -v '^%.*\\input' | grep -o 'input/[A-Za-z0-9_\.\-]*\.[a-z]*')

## RECIPES

all: $(FOLDERS) $(PAPER_INPUTS_TEX) $(PAPER_INPUTS_IMG) paper.pdf
all: paper.pdf

$(FOLDERS):
mkdir $@

paper.pdf: paper.tex $(PAPER_INPUTS_TEX) $(PAPER_INPUTS_IMG)
paper.pdf: paper.tex $(PAPER_INPUTS)
if command -v sbatch > /dev/null ; then module load texlive; fi
pdflatex -draftmode paper.tex
bibtex paper.aux
pdflatex -draftmode paper.tex
pdflatex paper.tex
rm paper.log paper.aux paper.out
rm paper.bbl paper.blg

input/:
mkdir $@
9 changes: 4 additions & 5 deletions slides/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#DEFINITIONS

SLIDES_SECTIONS := $(shell grep '\\input{' slides.tex | grep -v '%.*\\input' | sed 's/^.*\\input{\(.*\.tex\).*/\1/')
TEX_INPUTS := $(shell grep '\\input{.*\.tex}' $(slides_sections) | grep -v '%.*\\input' | sed 's/^.*\\input{\(.*\.tex\).*/\1/')
IMG_INPUTS := $(shell grep '\\includegraphics' $(slides_sections) | grep -v '%.*\\includegraphics' | sed 's/^.*\\includegraphics\[.*\]{\([\./a-zA-Z0-9_]*\)}.*/\1/')
slides_sections := $(shell grep '\\input' slides.tex | grep -v '%.*input' | grep -o 'sections/[A-Za-z0-9_\-]*\.tex')
slides_inputs := $(shell grep --no-filename 'input/' $(slides_sections) slides.tex | grep -v '^%' | grep -o 'input/[A-Za-z0-9_\.\-]*\.[a-z]*')

all: slides.pdf

Expand All @@ -12,7 +11,7 @@ clean:
input/:
mkdir $@

slides.pdf: slides.tex $(SLIDES_SECTIONS) $(TEX_INPUTS) $(IMG_INPUTS)
slides.pdf: slides.tex $(slides_sections) $(slides_inputs)
#module load texlive
pdflatex -draftmode $<
bibtex slides.aux
Expand All @@ -23,7 +22,7 @@ slides.pdf: slides.tex $(SLIDES_SECTIONS) $(TEX_INPUTS) $(IMG_INPUTS)
rm slides.blg slides.bbl
#module unload texlive

slides_notesonly.pdf: slides.tex $(SLIDES_SECTIONS) $(TEX_INPUTS) $(IMG_INPUTS)
slides_notesonly.pdf: slides.tex $(slides_sections) $(slides_inputs)
sed 's/notes=hide/notes=only/' slides.tex > slides_notesonly.tex
pdflatex slides_notesonly.tex #This will fail due to natbib's bug with notes-only beamer
rm slides_notesonly.tex slides_notesonly.log
Expand Down
13 changes: 13 additions & 0 deletions tasks/check_makefiles/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Check Makefiles

This task includes bash scripts to verify the makefiles in the repo.
These are used by GitHub Actions.

## Code
* `check_makefiles.sh`:
This script runs `make -n` for each task listed.
If an error occurs, the script exits with a non-zero exit code.
If no task-list argument is provided, the script check all task folders.
* `check_nontask_makefiles.sh`:
This script runs `make -n` in the paper, slides, and logbook folders.
If an error occurs, the script exits with a non-zero exit code.
32 changes: 32 additions & 0 deletions tasks/check_makefiles/code/check_makefiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

# this script runs `make -nC` on the given tasks to check Makefiles
# and assume an error occurs when the output includes "Stop."
# note: if no input is provided,
# then all tasks with a Makefile will be checked.

TASKS="$@" # read in given tasks

# if no task was given, run over all tasks with Makefiles
if [ "$TASKS" == "" ]
then
TASKS=$(find ../.. -name 'Makefile' | awk -F '/' '{print $3}')
fi

# default exit status
status=0

# run on the given tasks
for task in $TASKS
do
make_res=$(make -nC ../../$task/code 2>&1 |
grep "Stop." | sed "s|.*code: ||" | sed "s/Makefile:/Line /")
if [ "$make_res" != "" ]
then
status=1
echo "::error file=tasks/$task/code/Makefile::tasks/$task/code/Makefile $make_res"
fi
done

exit $status

22 changes: 22 additions & 0 deletions tasks/check_makefiles/code/check_nontask_makefiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# this script runs `make -nC` in the paper, slides, and logbook folders
# It flags an error when the output includes "Stop.""

# default exit status
status=0

# Run Make in the relevant folders
for folder in paper slides logbook
do
make_res=$(make -nC ../../../$folder 2>&1 |
grep "Stop." | sed "s|.*code: ||" | sed "s/Makefile:/Line /")
if [ "$make_res" != "" ]
then
status=1
echo "::error file=$folder/Makefile::$folder/Makefile $make_res"
fi
done

exit $status

0 comments on commit 4d7325f

Please sign in to comment.