Reader small image

You're reading from  GitHub Actions Cookbook

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781835468944
Edition1st Edition
Concepts
Right arrow
Author (1)
Michael Kaufmann
Michael Kaufmann
author image
Michael Kaufmann

Michael Kaufmann believes that developers and engineers can be happy and productive at work. He loves DevOps, GitHub, Azure, and modern work. Microsoft has awarded him with the title Microsoft Regional Director (RD) and Microsoft Most Valuable Professional (MVP) – the latter in the category of DevOps and GitHub. Michael is also the founder and managing director of Xebia Microsoft Services, Germany – a consulting company that helps its customers become digital leaders by supporting them in their cloud, DevOps, and digital transformation. Michael shares his knowledge in books, training, and as a frequent speaker at international conferences.
Read more about Michael Kaufmann

Right arrow

Preface

GitHub is more than just a platform for hosting and sharing code. With millions of developers from all over the world collaborating on projects of every type and size, it has become the beating heart of the open source community. With GitHub Actions, GitHub now has its own workflow platform that allows engineers and developers to automate all kinds of repetitive engineering tasks – from Continuous Integration (CI) and Continuous Deployment (CD) to IssueOps, automatic issue triaging, and ChatOps.

This book will show you how to make the most of GitHub Actions in your day-to-day life. It is a practical book – so we will have you do as much as possible and explain the theory alongside the individual recipes.

Who this book is for

If you are looking for a practical approach to learning GitHub Actions, this book is for you, whether you are a software developer or a DevOps engineer. If you have already played around with Actions on your own but want to learn more; you have experience with other CI/CD tools, such as Jenkins or Azure Pipelines; or you are completely new to the topic – it doesn’t matter, you’ll find this book helpful.

In order to learn from this book, you should have a basic understanding of at least one programming or script language, Git as a version control system, and infrastructure topics such as Docker, the Linux and Windows filesystems, and authentication.

What this book covers

Chapter 1, GitHub Actions Workflows, will introduce you to GitHub Actions workflows and what you can do with them. You will learn about YAML basics, events that trigger workflows, and expressions, as well as how to use GitHub Actions from the marketplace to automate all kinds of tasks.

Chapter 2, Authoring and Debugging Workflows, will teach you best practices for authoring workflows: how to use Visual Studio Code and GitHub Codespaces and various add-ins to efficiently create, edit, and run workflows, check them for errors with powerful linters, develop them in branches, and run them locally. You will also learn how you can debug them and turn on advanced logging.

Chapter 3, Building GitHub Actions, explains the different types of GitHub actions, and you will learn how to use input and output. You will write your own Docker container action, a TypeScript action, and a composite action.

Chapter 4, The Workflow Runtime, is about the different runtime options for your workflows. You will learn how to use different GitHub-hosted runners and how to set up and scale ephemeral, self-hosted runners in Docker containers and Kubernetes with GitHub Actions Controller (GHAC).

Chapter 5, Automate Tasks in GitHub with GitHub Actions, will show you how to use Issue-Ops to automate common tasks within GitHub. You will learn how to authenticate with GitHub Apps, use GITHUB_TOKEN and workflow permissions, use the GitHub CLI to automate tasks, use environments for approvals and checks, and use reusable workflows and composite actions to share logic across workflows and repositories.

Chapter 6, Build and Validate Your Code, is about CI. You will learn how to build and test different versions of your code with the same workflow, find security vulnerabilities in your code with CodeQL, attach a Software Bill of Materials (SBOM) to your release, automate the versioning of your software, and use caching to speed up your workflows.

Chapter 7, Release Your Software with GitHub Actions, covers continuous delivery and continuous deployment. You will learn how to securely deploy to the cloud using OpenID Connect (OIDC) and how to deploy containers to Kubernetes – whether it is Microsoft Azure Kubernetes Service (AKS), Google Kubernetes Engine (GKE), or Elastic Container Services (ECS). You will also learn how to use Dependabot together with GitHub Actions to completely automate the update of your dependencies.

To get the most out of this book

You will need the following:

Software/hardware covered in the book

OS requirements

GitHub

All operating systems are compatible. You will need an account on https://github.com.

Visual Studio Code

All operating systems are compatible. If you want, you can use GitHub Codespaces for all recipes. In this case, you don’t have to install anything locally. If you want to work locally, then you’ll need Visual Studio Code (https://code.visualstudio.com/download) and the subsequent tools.

Git

Only required if you work locally. All operating systems are compatible. You should have an up-to-date version of Git installed (at least version 2.23).

GitHub CLI

Only required if you work locally. Install the GitHub CLI (https://cli.github.com/).

Node.js

Only required if you work locally. You’ll need an up-to-date version of Node.js (I’m using 21 at the time of writing). All operating systems are compatible. Download the latest version here: https://nodejs.org/en/download/current.

Docker

Only required if you work locally. Get Docker for all operating systems here: https://docs.docker.com/get-docker/.

Azure and the Azure CLI

For some chapters, you’ll need an Azure account and the Azure CLI. A free test version will be sufficient (https://azure.microsoft.com/en-us/free). If you want to work locally, you’ll also need the Azure CLI.

All recipes can be done with a free GitHub account in public repositories. You can use GitHub Codespaces to do anything in a virtual environment. This will use up your 120 free hours per month (180 with GitHub Pro). Be aware of that. Once the free hours are used, you’ll have to pay per minute for Codespaces.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/GitHub-Actions-Cookbook. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “We can do this, for example, using the sed 's/./&/g' command.”

A block of code is set as follows:

jobs:
  build-and-push-image:
    runs-on: ubuntu-latest
    permissions:
      packages: write

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

"dependencies": {
  "@wulfland/package-recipe": "^2.0.5",
  "express": "^4.18.2"
}

Any command-line input or output is written as follows:

$ npm start
> release-recipe@1.0.0 start
> node src/index.js
Server running at http://localhost:3000

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: “In your repository, navigate to Settings | Secrets and Variables | Actions.”

Tips or important notes

Appear like this.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., and There’s more...).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There’s more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share your thoughts

Once you’ve read GitHub Actions Cookbook, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781835468944

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
GitHub Actions Cookbook
Published in: Apr 2024Publisher: PacktISBN-13: 9781835468944
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Michael Kaufmann

Michael Kaufmann believes that developers and engineers can be happy and productive at work. He loves DevOps, GitHub, Azure, and modern work. Microsoft has awarded him with the title Microsoft Regional Director (RD) and Microsoft Most Valuable Professional (MVP) – the latter in the category of DevOps and GitHub. Michael is also the founder and managing director of Xebia Microsoft Services, Germany – a consulting company that helps its customers become digital leaders by supporting them in their cloud, DevOps, and digital transformation. Michael shares his knowledge in books, training, and as a frequent speaker at international conferences.
Read more about Michael Kaufmann