Skip to content

Instantly share code, notes, and snippets.

@tgotwig
Last active April 16, 2021 12:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgotwig/2b3c93655deb2c01efd3c7b589b4e2a9 to your computer and use it in GitHub Desktop.
Save tgotwig/2b3c93655deb2c01efd3c7b589b4e2a9 to your computer and use it in GitHub Desktop.
🤖 CI overview with Github Actions

🤖 CI overview with Github Actions

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.

Github Actions

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 🍎

Cloning another repo

❌ 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

Trigger workflows on Forks for Organizations

You need the check the following checkbox, otherwise the workflows will not trigger when pushing from a Fork.

  1. Go on https://github.com/organizations/YOUR_ORGANIZATION/settings/actions
  2. Click on the checkbox Run workflows from fork pull requests

Then you should be able to check that on the organizations repositories as well 👍

Small forked demo action

https://github.com/Snowbear-Squad/my-javascript-action

Git Hooks

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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment