Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
GitHub Actions Cookbook
GitHub Actions Cookbook

GitHub Actions Cookbook: A practical guide to automating repetitive tasks and streamlining your development process

Arrow left icon
Profile Icon Michael Kaufmann
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (5 Ratings)
Paperback Apr 2024 250 pages 1st Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Michael Kaufmann
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (5 Ratings)
Paperback Apr 2024 250 pages 1st Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

GitHub Actions Cookbook

Authoring and Debugging Workflows

This chapter goes a step further and you will learn best practices for authoring workflows. This includes using Visual Studio Code, running your workflows locally, linting, working in branches, and using advanced logging and monitoring. This will be the foundation for the other chapters, as it gives you plenty of options on how to write your workflows.

This chapter covers the following:

  • Using Visual Studio Code for authoring workflows
  • Developing workflows in branches
  • Linting workflows
  • Writing messages to the log
  • Enabling debug logging
  • Running your workflows locally

Technical requirements

For this chapter, you need Visual Studio Code (VS Code) installed on your local machine. It is available for Windows (x64, x86, and Arm64), Linux (x64, x86, and Arm64), and Mac (Intel and Apple silicon), and you can install it from the following website if you haven’t already done this: https://code.visualstudio.com/download...

Using Visual Studio Code for authoring workflows

Visual Studio Code (VS Code) is one of the most popular and widely used code editors in the world. It has gained significant popularity in the developer community due to its flexibility, extensive ecosystem of extensions, and strong community support.

VS Code has a high level of integration with GitHub. It offers features such as Git integration, the synchronization of your settings using your GitHub account, direct access to repositories, and the ability to create, edit, and manage GitHub Action workflows from within the editor using the extension provided by GitHub. This tight integration simplifies the workflow creation process and streamlines collaboration on GitHub action workflows.

In this recipe, we’ll install the VS Code extension for GitHub Actions and inspect what you can do with it.

Getting ready…

Before we begin, check that your email address and name are set correctly in Git:

$ git config --global...

Developing workflows in branches

Starting in a greenfield repository, it is best to create your workflows on the main branch. However, if you must create the workflow in an active repository that developers are working in and you don’t want to get in their way, then it is possible to write workflows in a branch and merge them back to the main branch using a pull request.

However, some triggers might not work as expected. If you want to run your workflow manually using the workflow_dispatch trigger, your first action must be to merge the workflow with the trigger back to main or use the API to trigger the workflow. After that, you can author the workflow in a branch and select the branch when triggering the workflow through the UI.

If your workflow needs webhook triggers, such as push, pull_request, or pull_request_target, it might be necessary to create the workflow in a fork of the repository, depending on what you plan on doing with the triggers. This way, you can test...

Linting workflows

In this recipe, we’ll add a linting action that will check the workflow and give feedback directly in the pull request.

Getting ready…

Open the workflow file in the branch that you have for the open pull request. Do not merge the changes yet.

How to do it…

  1. Go to the marketplace and search for the actionlint. The action we are looking for is from devops-actions. The action needs to access the workflow files, meaning you have to check out the repository using the checkout action first. Add the following two steps to the end of the job:
    - uses: actions/checkout@v4.1.0
    - uses: devops-actions/actionlint@v0.1.2
  2. As we want the action to annotate errors in pull requests, we have to give the workflow write access to pull requests. I’ll explain later how this works. For now, just add a section permissions to the job like this:
    jobs:
      job1:
        runs-on: ubuntu-latest
        permissions...

Writing messages to the log

What problem matchers do based on existing result files can also be achieved by writing individual warning or error events to the log by also using workflow commands. In this recipe, we will add some output to our workflow and annotate our workflow file.

Getting ready…

Make sure you still have your pull request from the previous recipe open. Just use VS Code to add additional changes, and pushing will automatically trigger the workflow.

How to do it…

  1. Open .github/workflows/DevelopInBranch.yml in the new-workflow branch in VS Code and add the following code snipped directly before the checkout action:
          - run: |
              echo "::debug::This is a debug message."
              echo "::notice::This is a notice message."
              echo...

Enabling debug logging

In the previous recipe, we saw that you can rerun failed jobs or all jobs with debug logging enabled. However, you can also enable or disable debug logging on a repository base.

How to do it…

We can enable or disable debug logging by adding a variable called ACTIONS_STEP_DEBUG to our repository and setting the value to true or false. This will add a very verbose output to our workflow logs and all debug messages, and this will be displayed from all actions.

You can configure the variable using the web, the GitHub CLI, or VS Code. To set the variable using the web, in the repository, navigate to Settings | Secrets and variables | Actions and pick the Variables tab (/settings/variables/actions). Click New repository variable (which will redirect you to /settings/variables/actions/new), enter ACTIONS_STEP_DEBUG as the name, true as the value, and click Add variable.

To set it using the CLI, just execute the following line:

$ gh variable set...

Running your workflows locally

Committing workflows every time and running them on the server can be a slow process, especially for complex workflows. In this recipe, we will learn how to run a workflow locally using act (https://github.com/nektos/act).

Getting ready…

Act depends on Docker to run workflows. Make sure you have Docker running.

You can install act using different package managers (see https://github.com/nektos/act#installation-through-package-managers). Just pick the one that fits your environment and follow the instructions.

When running act for the first time, it will ask you to choose a Docker image to be used as the default. It will save that information to ~/.actrc. There are different images available. There are small images available (node:16-buster-slim) that will only support NodeJS and nothing more. The big images are more than 18 GB in size. Keep that in mind. However, with today’s disk space and internet, you will get the best results...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Automate CI/CD workflows and deploy securely to cloud providers like Azure, AWS, or GCP using OpenID
  • Create your own custom actions with Docker, JavaScript programming, or shell scripts and share them with others
  • Discover ways to automate complex scenarios beyond the basic ones documented in GitHub

Description

Say goodbye to tedious tasks! GitHub Actions is a powerful workflow engine that automates everything in the GitHub ecosystem, letting you focus on what matters most. This book explains the GitHub Actions workflow syntax, the different kinds of actions, and how GitHub-hosted and self-hosted workflow runners work. You’ll get tips on how to author and debug GitHub Actions and workflows with Visual Studio Code (VS Code), run them locally, and leverage the power of GitHub Copilot. The book uses hands-on examples to walk you through real-world use cases that will help you automate the entire release process. You’ll cover everything, from automating the generation of release notes to building and testing your software and deploying securely to Azure, Amazon Web Services (AWS), or Google Cloud using OpenID Connect (OIDC), secrets, variables, environments, and approval checks. The book goes beyond CI/CD by demonstrating recipes to execute IssueOps and automate other repetitive tasks using the GitHub CLI, GitHub APIs and SDKs, and GitHub Token. You’ll learn how to build your own actions and reusable workflows to share building blocks with the community or within your organization. By the end of this GitHub book, you'll have gained the skills you need to automate tasks and work with remarkable efficiency and agility.

Who is this book for?

This book is for anyone looking for a practical approach to learning GitHub Actions, regardless of their experience level. Whether you're a software developer, a DevOps engineer, anyone who has already experimented with Actions, or someone completely new to CI/CD tools like Jenkins or Azure Pipelines, you’ll find expert insights in this book. Basic knowledge of using Git and command lines is a must.

What you will learn

  • Author and debug GitHub Actions workflows with VS Code and Copilot
  • Run your workflows on GitHub-provided VMs (Linux, Windows, and macOS) or host your own runners in your infrastructure
  • Understand how to secure your workflows with GitHub Actions
  • Boost your productivity by automating workflows using GitHub's powerful tools, such as the CLI, APIs, SDKs, and access tokens
  • Deploy to any cloud and platform in a secure and reliable way with staged or ring-based deployments

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2024
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781835468944
Vendor :
GitHub
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Apr 30, 2024
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781835468944
Vendor :
GitHub
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 101.97
DevOps Unleashed with Git and GitHub
€33.99
GitHub Actions Cookbook
€29.99
Mastering GitHub Actions
€37.99
Total 101.97 Stars icon

Table of Contents

9 Chapters
Chapter 1: GitHub Actions Workflows Chevron down icon Chevron up icon
Chapter 2: Authoring and Debugging Workflows Chevron down icon Chevron up icon
Chapter 3: Building GitHub Actions Chevron down icon Chevron up icon
Chapter 4: The Workflow Runtime Chevron down icon Chevron up icon
Chapter 5: Automate Tasks in GitHub with GitHub Actions Chevron down icon Chevron up icon
Chapter 6: Build and Validate Your Code Chevron down icon Chevron up icon
Chapter 7: Release Your Software with GitHub Actions Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(5 Ratings)
5 star 80%
4 star 20%
3 star 0%
2 star 0%
1 star 0%
Olena May 24, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Technical books can be tough without good examples, but this book does a great job of showing concepts visually. The clear explanations are supported by many screenshots, diagrams, images, and code snippets, which help a lot.Whether you're new to GitHub or have some experience, you'll find the instructions clear and helpful. The introductory chapters are especially good for beginners, providing a strong base before getting into GitHub Actions workflows."GitHub Actions Cookbook" is a great resource for developers wanting to improve their automation skills. Its detailed and visually supported content makes it a must-read for anyone looking to streamline their development process with GitHub Actions. I highly recommend it to both new and experienced developers.
Amazon Verified review Amazon
Amazon Customer May 23, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
GitHub Actions is a bit daunting to get started with - but it doesn't have to be. The book is excellent. I love how it first concisely shows you how to do things, then fills you in on some of the "whys" later if you want more of the theory or understanding.The examples are easy to understand and the GitHub repo provides great examples that make it easy to actually implement workflows.This will help me hugely in my job and I'm already recommending it to other development teams just starting out with GitHub Actions workflows.
Amazon Verified review Amazon
Wes MacDonald May 23, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is one of my favourite book formats, lots of examples (recipes) to get you really tuned into GitHub Actions and all of its possibilities. If you want to be productive (automate everything) or just want to explore the possible with GitHub Actions this book will more than deliver on that.
Amazon Verified review Amazon
Hossein Jan 05, 2025
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am not in a position to be fully qualified for rating this book, because this book seems to be suitable for devops engineerings, but I am a software developer. But even from my perspective, the book is very detailed and easy enough to get up and running on using GitHub Actions. My goal to reading this book was to run configuration, build and packaging steps of my projects, and finally create a release on my GitHub repositories. Well, I have done it but this book goes way more than that and can keep a devops engineer pretty busy for days. I have never studied another book on this topic so I cannot compare this book with another, but I feel confident enough now to start reading the official documentations on GitHub. In general, I recommend it, or at least I recommend you to read the parts of the book you need.
Subscriber review Packt
N. McA Oct 08, 2024
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The content and the style it has been written is great for me, very useful and I'm already learning things I didn't know from the first few pages.Misses a star for me though, the print quality of the book isn't really decent for £30. The back page says it's printed in Great Britain by Amazon, if this is a legit copy? The pages are photocopier paper, and screenshots are for the most part quite blurry. Not a great print
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.