|
1 |
| -# Github-Actions-for-c-based-42Projects |
2 |
| -offer a github action implementation example for 42Network c based projects |
| 1 | + |
| 2 | + |
| 3 | +# GitHub Actions for C-based 42 Projects |
3 | 4 |
|
4 |
| -```yml |
| 5 | +This README offers examples of how to set up GitHub Actions for 42 Network C-based projects, including norminette checks and build processes. |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Example 1: Basic Norminette and Build Workflow](#example-1-basic-norminette-and-build-workflow) |
| 10 | +- [Example 2: MinilibX Docker Integration Workflow](#example-2-minilibx-docker-integration-workflow) |
| 11 | +- [Customization](#customization) |
| 12 | +- [Docker Image](#docker-image) |
| 13 | + |
| 14 | +## Example 1: Basic Norminette and Build Workflow |
| 15 | + |
| 16 | +This example demonstrates a basic GitHub Actions workflow for C-based projects, focusing on norminette checks and building the project. |
| 17 | + |
| 18 | +```yaml |
5 | 19 | ---
|
6 |
| - name: NORM AND FLAGS CHECKS |
7 |
| - |
8 |
| - on: |
9 |
| - push: |
10 |
| - branches: |
11 |
| - - main |
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 dependencies |
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 |
| 20 | +name: NORM AND FLAGS CHECKS |
| 21 | + |
| 22 | +on: |
| 23 | + push: |
| 24 | + branches: |
| 25 | + - main |
| 26 | + pull_request: |
| 27 | + branches: |
| 28 | + - '*' |
| 29 | + |
| 30 | +jobs: |
| 31 | + check-norm: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v2 |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v2 |
| 39 | + with: |
| 40 | + python-version: 3.12 |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: | |
| 44 | + pip install setuptools norminette |
| 45 | +
|
| 46 | + - name: Run norminette checks |
| 47 | + run: | |
| 48 | + norminette |
| 49 | +
|
| 50 | + make-with-flags: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: check-norm |
| 53 | + steps: |
| 54 | + - name: Checkout repository |
| 55 | + uses: actions/checkout@v2 |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + run: | |
| 59 | + sudo apt-get update |
| 60 | + sudo apt-get install -y make gcc |
| 61 | +
|
| 62 | + - name: Create Makefile for testing |
| 63 | + run: | |
| 64 | + 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 |
| 65 | + - name: Run Services |
| 66 | + run: | |
| 67 | + make |
54 | 68 | ```
|
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 | 69 |
|
| 70 | +### Explanation |
65 | 71 |
|
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. |
| 72 | +1. **`check-norm` Job:** |
| 73 | + - Runs on the latest Ubuntu. |
| 74 | + - Checks out the code using [actions/checkout@v2](https://github.com/actions/checkout). |
| 75 | + - Sets up Python 3.12 using [actions/setup-python@v2](https://github.com/actions/setup-python). |
| 76 | + - Installs `setuptools` and `norminette` using pip. |
| 77 | + - Runs `norminette` to check the code. |
74 | 78 |
|
75 |
| -This workflow is triggered on every push and pull request to any branch of your repository. |
| 79 | +2. **`make-with-flags` Job:** |
| 80 | + - Runs on the latest Ubuntu and depends on the successful completion of `check-norm`. |
| 81 | + - Checks out the code using [actions/checkout@v2](https://github.com/actions/checkout). |
| 82 | + - Installs `make` and `gcc` using `apt-get`. |
| 83 | + - Creates a `Makefile` for testing, which compiles `.c` files and links them into an executable. |
| 84 | + - Runs `make` to build the executable. |
76 | 85 |
|
77 |
| -you can customize it by specifying on which branches to run this workflow : |
| 86 | +## Example 2: MinilibX Docker Integration Workflow |
| 87 | + |
| 88 | +This example demonstrates a GitHub Actions workflow for integrating MinilibX using Docker. |
78 | 89 |
|
79 | 90 | ```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 |
| 91 | +--- |
| 92 | +name: NORM AND FLAGS CHECKS FOR MINILIBX PROJECT |
89 | 93 |
|
| 94 | +on: |
| 95 | + push: |
| 96 | + branches: |
| 97 | + - '*' |
| 98 | + pull_request: |
| 99 | + branches: |
| 100 | + - '*' |
| 101 | +
|
| 102 | +jobs: |
| 103 | + check-norm: |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v2 |
| 108 | +
|
| 109 | + - name: Set up Python |
| 110 | + uses: actions/setup-python@v2 |
| 111 | + with: |
| 112 | + python-version: 3.12 |
| 113 | +
|
| 114 | + - name: Install dependencies |
| 115 | + run: | |
| 116 | + pip install setuptools norminette |
| 117 | +
|
| 118 | + - name: Run norminette checks |
| 119 | + run: | |
| 120 | + norminette |
| 121 | +
|
| 122 | + make-with-flags: |
| 123 | + runs-on: ubuntu-latest |
| 124 | + needs: check-norm |
| 125 | + steps: |
| 126 | + - name: Checkout code |
| 127 | + uses: actions/checkout@v3 |
| 128 | +
|
| 129 | + - name: Pull Docker image |
| 130 | + run: | |
| 131 | + docker pull ahlyelamine/minilibx:latest |
| 132 | +
|
| 133 | + - name: Build and run project |
| 134 | + run: | |
| 135 | + docker run --rm -v ${{ github.workspace }}:/opt ahlyelamine/minilibx:latest |
| 136 | +``` |
| 137 | + |
| 138 | +### Explanation |
| 139 | + |
| 140 | +1. **`check-norm` Job:** |
| 141 | + - Runs on the latest Ubuntu. |
| 142 | + - Checks out the code using [actions/checkout@v2](https://github.com/actions/checkout). |
| 143 | + - Sets up Python 3.12 using [actions/setup-python@v2](https://github.com/actions/setup-python). |
| 144 | + - Installs `setuptools` and `norminette` using pip. |
| 145 | + - Runs `norminette` to check the code. |
| 146 | + |
| 147 | +2. **`make-with-flags` Job:** |
| 148 | + - Runs on the latest Ubuntu and depends on the successful completion of `check-norm`. |
| 149 | + - Checks out the code using [actions/checkout@v3](https://github.com/actions/checkout). |
| 150 | + - Pulls the Docker image [`ahlyelamine/minilibx:latest`](https://hub.docker.com/r/ahlyelamine/minilibx). |
| 151 | + - Builds and runs the project using Docker with the workspace mounted to `/opt` in the container. |
| 152 | + |
| 153 | +## Customization |
| 154 | + |
| 155 | +To customize the branches that trigger these workflows, modify the `on` section: |
| 156 | + |
| 157 | +```yaml |
| 158 | +on: |
| 159 | + push: |
| 160 | + branches: |
| 161 | + - main |
| 162 | + - feature-branch |
| 163 | + pull_request: |
| 164 | + branches: |
| 165 | + - main |
| 166 | + - feature-branch |
90 | 167 | ```
|
| 168 | + |
| 169 | +This workflow triggers on every push and pull request to the specified branches. |
| 170 | + |
| 171 | +## Docker Image |
| 172 | + |
| 173 | +The Docker image used in Example 2 is available on [Docker Hub](https://hub.docker.com/r/ahlyelamine/minilibx). |
0 commit comments