Stands for Continous Integration and is something which helps you to keep up the integrity of your software by running tests when updates were made to find bugs as soon as possible (fast feedback loop):
Writing code and open a PR 👉 Let it Build 👉 Let it run Unittests and Linters
Integration-Tests and E2E-Tests are Continuous Delivery (CD) tests.
Best practices:
- 🐹 Features should be as small as possible
- 🌈 Run the tests on different operating systems (same Java program can can work for Ubuntu but fail on Windows)
- ⏱ Do pulling the deps and running the code in seperate steps to see how long it takes and seperate the logs
- 💰 Keep care of the costs, I think running the CI only on PRs is fine
- 🤗 Put Emojis left besides your task names
Can be done by software like Github Actions, Jenkins, CircleCI or Travis.
A Service from Github for doing CI / CD with Github projects, workflow files are in yaml-format and looks like:
name: 🚀 Java CI with Maven
on: pull_request
jobs:
job:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: 👕 Check linting by Checkstyle
run: mvn checkstyle:checkstyle
- name: ⬇ Download deps
run: mvn clean install -DskipTests
- name: 🧪 Run tests
run: mvn test
Where Set up JDK 11
isn't really necessary, because it comes with a lot of preinstalled tools.
- Took 1min 45s on Ubuntu 🐧
- Took 2min 26s on Windows 🌈
- Took 3min 41s on MacOS 🍎
❌ Didn't work:
- name: Check out my other private repo
uses: actions/checkout@master
with:
repository: orgname/reponame
token: ${{ secrets.my_pat }}
✅ Did work:
- name: Check out my other private repo
run: git clone https://tgotwig:5c9aeda35aef5e9b9729878e22c75c28421948e1@github.com/Snowbear-Squad/ci-cd-demo-ms-1.git
You need the check the following checkbox, otherwise the workflows will not trigger when pushing from a Fork.
- Go on https://github.com/organizations/YOUR_ORGANIZATION/settings/actions
- Click on the checkbox
Run workflows from fork pull requests
Then you should be able to check that on the organizations repositories as well 👍
https://github.com/Snowbear-Squad/my-javascript-action
Helps to find bugs before commits were even pushed, nice to detects bugs earlier, here for linters:
rm .git/hooks/*
echo "#!/bin/sh" > .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
echo "make lint" >> .git/hooks/commit-msg
But this also checks unstaged files, need to fix this 😅