In this Quickstart guide, I want to introduce you to GitHub Actions and show you how you can use GitHub Actions to create CI/CD pipelines to automate boring, repetitive tasks.
GitHub Actions is a versatile tool that developers can use to organise their software development processes more efficiently. You can mainly use GitHub Actions as a CI/CD pipeline (CI = Continuous Integration, CD = Continuous Delivery) and is therefore comparable with or for my , deploy to a Kubernetes cluster, create/build apps, deploy to various services of all common cloud providers, code security scans, etc. This list can be extended almost endlessly 😉
A workflow in GitHub Actions consists of one or more actions that are executed as steps in a defined sequence. These workflows are defined in YAML files and saved in the .github/workflows directory of the repository.
for private repositories, which lasts for quite a while and resets every month.
Creating a GitHub Actions Workflow
To create a new GitHub actions workflow, you can simply use the ‘Actions’ tab in your GitHub repo or alternatively create a YAML file in the path .github/workflows.
version 20 in the current environment.
npm install command to install the project dependencies.npm test command to run the tests of the project.This example shows you the basic structure of a pipeline. You can execute any number of steps and jobs per GitHub Actions workflow.
Triggers & Events
GitHub Actions provides a flexible way to execute workflows based on various triggers and events. These triggers determine when a workflow is started and can respond to a variety of GitHub events, such as code changes, issues and schedules.
Code changes/new commits on a specific branch:
This workflow is only executed when a commit is pushed to the develop branch.
on:
push:
branches:
- develop
Tags that correspond to a specific pattern:
Here, the workflow is only started if a tag beginning with release- (e.g. release-1.0.0) is pushed.
on:
push:
tags:
- 'release-*'
Regular execution:
This workflow is executed every Monday at 12 noon.
on:
schedule:
- cron: '0 12 * * 1'
It is also very useful to carry out tests and linting, for example, before a pull request can be confirmed.
is a central point of contact for predefined actions that you can integrate into your workflows to speed up and simplify the development process. Here you will find a variety of actions created by the community and GitHub itself to automate common tasks such as testing, code analysis and much more.
Suppose you want to use an action that automatically checks your code for formatting errors. A popular action for this purpose is the Prettier action, which formats the code with Prettier.
Here is an example of how you can integrate this action into your workflow:
name: Format Code
on: [push, pull_request]
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Run Prettier
uses: creyD/[email protected]
with:
prettier_options: --write **/*.js
This workflow is executed for every push and pull request and checks whether the JavaScript code is formatted correctly. The prettier_action is integrated from the GitHub Marketplace and configured with the desired options.
Using the GitHub Marketplace offers considerable advantages, such as time savings, as you have immediate access to numerous ready-made actions without having to develop your own solutions. In addition, the regular maintenance and updating of the actions ensures high quality and security. Thanks to the support of the GitHub community, you benefit from constantly improved and new actions.
Other useful actions
: Automated scan of your code for security vulnerabilities.
images directly from your workflow.
, directly from GitHub.
Some texts were created with the help of AI. All content has been thoroughly checked!
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
SOCIAL SHARE CARD GENERATOR