Skip to content

Commit

Permalink
c(ci): add initial C track action file
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 3, 2023
1 parent 0224be9 commit afd9480
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/citools/c/clang-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo clang-check-16 ./*.c ./*.h --
time clang-check-16 ./*.c ./*.h --
printf "\n"
5 changes: 5 additions & 0 deletions .github/citools/c/clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo clang-tidy-16 ./*.c ./*.h -checks=*,-llvm-header-guard --
time clang-tidy-16 ./*.c ./*.h -checks=*,-llvm-header-guard --
printf "\n"
101 changes: 101 additions & 0 deletions .github/workflows/c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
name: C Workflow
on: # yamllint disable-line rule:truthy
pull_request:

jobs:
stage1:
name: Change Check
runs-on: 'ubuntu-latest'
outputs:
docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }}
steps:
- name: Checkout Repo
id: checkout-repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
submodules: recursive
- name: Get Change List
id: check_file_changed
run: |
# Diff HEAD with the previous commit then output to stdout.
printf "=== Which files changed? ===\n"
GIT_DIFF="$(git diff --name-only HEAD^ HEAD)"
printf "%s\n" "${GIT_DIFF}"
printf "\n"
# Check if the files are present in the changed file list (added, modified, deleted) then output to stdout.
HAS_DIFF=false
printf "=== Which C files changed? ===\n"
if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.*[.][ch]|.*/[Ma]akefile|.github/workflows/c.yml)$'; then
HAS_DIFF=true
fi
printf "\n"
# Did Golang files change?
printf "=== Did C files change? ===\n"
printf "%s\n" "${HAS_DIFF}"
printf "\n"
# Set the output named "docs_changed"
printf "%s=%s\n" "docs_changed" "${HAS_DIFF}" >> "${GITHUB_OUTPUT}"
stage2:
name: C Checks
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
exclude:
- os: "macos-latest"
- os: "windows-latest"
runs-on: "${{ matrix.os }}"
needs: [stage1]
if: needs.stage1.outputs.docs_changed == 'True'
steps:
- name: Checkout Repo
id: checkout-repo
uses: actions/checkout@v3
- name: Install C Tools
id: install-c-tools
run: |
sudo tee -a /etc/apt/sources.list <<EOF
# deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main
# deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main
# deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main
# deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main
# deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main
# deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main
deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main
EOF
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt update
# sudo apt install -y clang-16 lldb-16 lld-16
# sudo apt install -y libllvm-14-ocaml-dev libllvm14 llvm-14 llvm-14-dev llvm-14-doc llvm-14-examples llvm-14-runtime
sudo apt install -y gcc clang-16 clang-tools-16 clang-tidy-16
# sudo apt install -y libssl-dev
# sudo apt install -y lcov
sudo apt install -y make
- name: CD to C Dir
id: cd-to-c-dir
run: |
pwd
ls
cd ./c
pwd
ls
- name: Analysing the code with clang-check
id: clang-check-16
run: |
cd ./c
./for_each ../../.github/citools/c/clang-check
- name: Analysing the code clang-tidy-16
id: clang-tidy-16
run: |
cd ./c
./for_each ../../.github/citools/c/clang-tidy
- name: Run Unit Tests
id: make-test
run: |-
cd ./c
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Exercism Workspace
[![Haskell Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/haskell.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/haskell.yml)
[![Python Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/python.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/python.yml)
[![Common Lisp Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml)
[![C Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml)

[![Git PR Checks](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml)
[![Check Links](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml)
Expand All @@ -64,6 +65,7 @@ Exercism Workspace
- [Haskell Workflow](.github/workflows/haskell.yml)
- [Python Workflow](.github/workflows/python.yml)
- [Common Lisp Workflow](.github/workflows/common-lisp.yml)
- [C Workflow](.github/workflows/c.yml)
- [Link Checker Workflow](.github/workflows/links.yml)
- [CodeQL Workflow](.github/workflows/codeql-analysis.yml)
- [Woke PR](.github/workflows/woke-pr.yml)
Expand Down

0 comments on commit afd9480

Please sign in to comment.