|
1 | 1 | # Github-Actions-for-c-based-42Projects
|
2 | 2 | offer a github action implementation example for 42Network c based projects
|
| 3 | + |
| 4 | +```yml |
| 5 | +--- |
| 6 | + name: NORM AND FLAGS CHECKS |
| 7 | + |
| 8 | + on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - '*' |
| 12 | + pull_request: |
| 13 | + branches: |
| 14 | + - '*' |
| 15 | + |
| 16 | + jobs: |
| 17 | + check-norm: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v2 |
| 25 | + with: |
| 26 | + python-version: 3.12 |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: | |
| 30 | + pip install setuptools norminette |
| 31 | +
|
| 32 | + - name: Run norminette checks |
| 33 | + run: | |
| 34 | + norminette |
| 35 | +
|
| 36 | + make-with-flags: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: check-norm |
| 39 | + steps: |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@v2 |
| 42 | + |
| 43 | + - name: install docker-compose |
| 44 | + run: | |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y make gcc |
| 47 | +
|
| 48 | + - name: Create Makefile for testing |
| 49 | + run: | |
| 50 | + echo -e 'SRCS= $(shell find . -type f -name "*.c")\nINCLUDES= $(shell find . -type f -name "*.h")\nOBJS= $(SRCS:.c=.o)\nCC= cc\nCFLAGS= -Wall -Wextra -Werror\nNAME= uniq_name_][\nall: $(NAME)\n$(NAME): $(OBJS)\n\t$(CC) $(OBJS) -o $(NAME)\n%.o: %.c $(INCLUDES)\n\t$(CC) $(CFLAGS) -c $< -o $@' > Makefile |
| 51 | + - name: Run Services |
| 52 | + run: | |
| 53 | + make |
| 54 | +``` |
| 55 | +--- |
| 56 | +This is a GitHub Actions workflow file written in YAML. It defines two jobs: `check-norm` and `make-with-flags`. |
| 57 | +--- |
| 58 | +1. `check-norm` job: |
| 59 | + - It runs on the latest version of Ubuntu. |
| 60 | + - It checks out your code using the `actions/checkout@v2` action. |
| 61 | + - It sets up Python 3.12 using the `actions/setup-python@v2` action. |
| 62 | + - It installs `setuptools` and `norminette` using pip. |
| 63 | + - It runs `norminette` to check your code. |
| 64 | + |
| 65 | + |
| 66 | +--- |
| 67 | +2. `make-with-flags` job: |
| 68 | + - It also runs on the latest version of Ubuntu. |
| 69 | + - It depends on the `check-norm` job, meaning it will only run if `check-norm` completes successfully. |
| 70 | + - It checks out your code using the `actions/checkout@v2` action. |
| 71 | + - It installs `make` and `gcc` using `apt-get`. |
| 72 | + - It creates a `Makefile` for testing. The `Makefile` compiles all `.c` files found in the repository and links them into a single executable named `uniq_name_][`. |
| 73 | + - It runs `make` to build the executable. |
| 74 | + |
| 75 | +This workflow is triggered on every push and pull request to any branch of your repository. |
| 76 | + |
| 77 | +you can customize it by specifying on which branches to run this workflow : |
| 78 | + |
| 79 | +```yaml |
| 80 | + on: |
| 81 | + push: |
| 82 | + branches: |
| 83 | + - main |
| 84 | + - and so on for example |
| 85 | + pull_request: |
| 86 | + branches: |
| 87 | + - main |
| 88 | + - and so on for example |
| 89 | +
|
| 90 | +``` |
0 commit comments