Skip to content
Open
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
80 changes: 80 additions & 0 deletions .github/workflows/compile-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: COBOL Compile Check

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
compile-check:
runs-on: ubuntu-latest

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

- name: Install GnuCOBOL
run: |
sudo apt-get update
sudo apt-get install -y gnucobol

- name: Verify GnuCOBOL installation
run: cobc --version

- name: Syntax check all .cbl files
run: |
echo "=== Syntax checking all .cbl files ==="
# sql/ files contain EXEC SQL blocks that require the esqlOC
# precompiler before they can be parsed by cobc, so exclude them.
failed=0
for f in $(find . -name "*.cbl" -not -path "./sql/*" | sort); do
echo "Checking: $f"
if ! cobc -fsyntax-only "$f"; then
echo "FAILED: $f"
failed=1
fi
done
if [ "$failed" -eq 1 ]; then
echo "Some files failed syntax checking."
exit 1
fi
echo "All files passed syntax checking."

- name: Compile non-interactive examples
run: |
echo "=== Compiling non-interactive examples ==="

# Skipped examples:
# - sql/: Requires the esqlOC precompiler and libocsql library, which are not available in CI
# - accept/: Programs use ACCEPT statements requiring interactive terminal input
# - mouse/: Program uses mouse input handling requiring a terminal
# - screen_size/: Program uses ACCEPT statements for screen dimensions requiring a terminal

compile_and_verify() {
local src="$1"
local out="$2"
echo "Compiling: $src -> $out"
cobc -x "$src" -o "$out"
if [ -f "$out" ] && [ -x "$out" ]; then
echo " OK: $out exists and is executable"
else
echo " FAILED: $out was not produced"
return 1
fi
}

failed=0
compile_and_verify json_generate/json_generate.cbl /tmp/json_generate || failed=1
compile_and_verify xml_generate/xml_generate.cbl /tmp/xml_generate || failed=1
compile_and_verify numval_test/numval_test.cbl /tmp/numval_test || failed=1
compile_and_verify comp_test/comp_test.cbl /tmp/comp_test || failed=1
compile_and_verify trim/trim.cbl /tmp/trim || failed=1
compile_and_verify is_numeric/is_numeric.cbl /tmp/is_numeric || failed=1
compile_and_verify merge_sort/merge_sort_test.cbl /tmp/merge_sort_test || failed=1

if [ "$failed" -eq 1 ]; then
echo "Some examples failed to compile."
exit 1
fi
echo "All non-interactive examples compiled successfully."
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[![COBOL Compile Check](https://github.com/COG-GTM/COBOL-Examples/actions/workflows/compile-check.yml/badge.svg)](https://github.com/COG-GTM/COBOL-Examples/actions/workflows/compile-check.yml)

# COBOL Examples
This is a collection of example and test COBOL programs I've written. I'm currently in the process of updating
each folder with a README.md file and more comments so that the examples are easier to follow along with.


All program were written using [GnuCOBOL](https://gnucobol.sourceforge.io/) in Linux.
All program were written using [GnuCOBOL](https://gnucobol.sourceforge.io/) in Linux.