|
1 | | -# Continuous integration |
| 1 | +# Continuous Integration |
2 | 2 |
|
3 | | -!!!warning "Under Construction" |
| 3 | +## What |
4 | 4 |
|
5 | | - The workshop organiser is still working hard on this page! 🤓 |
| 5 | +Continuous Integration (CI) is the practice of automatically building, testing, and validating your code every time you make changes. |
| 6 | +Instead of manually running tests or checks before merging code, CI systems do this automatically. |
| 7 | + |
| 8 | +## Why |
| 9 | + |
| 10 | +In a sense, a good software developer is _lazy_. |
| 11 | +They dislike manual work, and want to automate as much as possible. |
| 12 | +CI allows you to stop doing all the checks/steps for every code change manually. |
| 13 | +The added benefit is that this is _much_ less error prone: e.g. your documentation will never be out of date because you forgot to deploy it. |
| 14 | + |
| 15 | +!!!example "Real-world scenario" |
| 16 | + |
| 17 | + You're maintaining a Python package, and someone wants to make a change to your code. |
| 18 | + Without CI, you'll have to test their changes locally: did they install/run the `pre-commit`? |
| 19 | + Are the tests passing for the Python versions you support? |
| 20 | + Ain't nobody got time for that! |
| 21 | + |
| 22 | +## How |
| 23 | + |
| 24 | +GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) platform built into GitHub. |
| 25 | +It lets you define workflows that run automatically in response to events like pushing code, opening pull requests, or adding a release tag. |
| 26 | + |
| 27 | +A GitHub actions workflow is defined in a YAML file, stored in the `.github/workflows` directory. |
| 28 | +Let's have a look at `deploy-mkdocs.yaml`: |
| 29 | + |
| 30 | +```yaml {.no-copy} |
| 31 | +# deploy-mkdocs.yaml |
| 32 | +name: Deploy MkDocs site to Github pages |
| 33 | +on: |
| 34 | + push: |
| 35 | + branches: |
| 36 | + - main |
| 37 | + |
| 38 | +permissions: |
| 39 | + contents: write |
| 40 | + |
| 41 | +jobs: |
| 42 | + deploy: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - uses: actions/setup-python@v5 |
| 48 | + with: |
| 49 | + python-version: 3.x |
| 50 | + |
| 51 | + - run: pip install mkdocs mkdocs-material |
| 52 | + - run: mkdocs gh-deploy --force |
| 53 | + |
| 54 | +``` |
0 commit comments