Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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

eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Slovakia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Slovakia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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
Banner background image

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela