SlideShare uma empresa Scribd logo
1 de 65
Baixar para ler offline
techupskills.com | techskillstransformations.com
@techupskills
2
© 2023 Brent C. Laster &
Prerequisites
• Account at GitHub.com - free tier is fine
• Labs doc for workshop
§ In https://github.com/skilldocs/gh-actions (file is github-actions-
labs.pdf)
§ direct link:
» https://github.com/skilldocs/gh-actions/blob/main/github-
actions-labs.pdf
techupskills.com | techskillstransformations.com
@techupskills
3
© 2023 Brent C. Laster &
Tech Skills Transformations & Brent Laster
Introduction to GitHub Actions
techupskills.com | techskillstransformations.com
@techupskills
4
© 2023 Brent C. Laster &
About me
• R&D Director, DevOps
• Global trainer – training (Git,
Jenkins, Gradle, CI/CD,
pipelines, Kubernetes,
Helm, ArgoCD, operators)
• Author -
§ OpenSource.com
§ Professional Git book
§ Jenkins 2 – Up and
Running book
§ Continuous Integration
vs. Continuous Delivery
vs. Continuous
Deployment mini-book
on O'Reilly Learning
techskillstransformations.com
getskillsnow.com
https://www.linkedin.com/in/brentlaster
@BrentCLaster
GitHub: brentlaster
techupskills.com | techskillstransformations.com
@techupskills
5
© 2023 Brent C. Laster &
Book – Professional Git
• Extensive Git reference,
explanations, and examples
• First part for non-technical
• Beginner and advanced
reference
• Hands-on labs
techupskills.com | techskillstransformations.com
@techupskills
6
© 2023 Brent C. Laster &
Jenkins 2 Book
• Jenkins 2 – Up and Running
• “It’s an ideal book for those who are
new to CI/CD, as well as those who
have been using Jenkins for many
years. This book will help you discover
and rediscover Jenkins.” By Kohsuke
Kawaguchi, Creator of Jenkins
techupskills.com | techskillstransformations.com
@techupskills
7
© 2023 Brent C. Laster &
Learning GitHub Actions - Early Release
• Early release - Chapters 1-6 on learning.oreilly.com
techupskills.com | techskillstransformations.com
@techupskills
8
© 2023 Brent C. Laster &
O’Reilly Training
techupskills.com | techskillstransformations.com
@techupskills
9
© 2023 Brent C. Laster &
Other References
techupskills.com | techskillstransformations.com
@techupskills
10
© 2023 Brent C. Laster &
Agenda
• What are GitHub Actions?
• How do they work?
• The GitHub interface to actions
• About Actions Runners and Virtual Environments
• Using public actions
• Workflow runs
• Custom actions
• Manually running workflows
• Monitoring and Troubleshooting
• Creating secrets for actions
• Chaining workflows together
• Using GitHub API calls with actions
techupskills.com | techskillstransformations.com
@techupskills
11
© 2023 Brent C. Laster &
What are GitHub Actions?
• Way to create custom, automated workflows in GitHub
• Executed based on repository operations
• Building blocks - can be combined & shared
• Used for usual SDLC tasks
• Can be used for CI/CD as alternatives to other apps
techupskills.com | techskillstransformations.com
@techupskills
12
© 2023 Brent C. Laster &
Other use cases (starter workflows)
techupskills.com | techskillstransformations.com
@techupskills
13
© 2023 Brent C. Laster &
What's interesting about it?
• Direct integration with GitHub
techupskills.com | techskillstransformations.com
@techupskills
14
© 2023 Brent C. Laster &
What else is interesting about it?
• Lots of events can trigger an action workflow -
automate practically anything!
on: project
on: watch
on: repository_dispatch
on: delete
on: check_run
on: page_build
on: scheduled
on: pull_request
on: public
on: pull_request_review_comment
on: pull_push
on: fork
https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
techupskills.com | techskillstransformations.com
@techupskills
15
© 2023 Brent C. Laster &
Types of triggers for events
• single event - on: push
• list of events - on: [push, pull_request]
• event types with qualifiers, such as branches, tags, or files
on:
push:
branches:
- main
- 'rel/v*'
tags:
- v1.*
- beta
paths:
- '**.ts'
• scheduled events
on:
scheduled
- cron: '30 5,15 * * *'
• manual events - on: workflow-dispatch
on: repository-dispatch
• workflow reuse events - on: workflow-call
• activity types
techupskills.com | techskillstransformations.com
@techupskills
16
© 2023 Brent C. Laster &
How actions work (events)
• Events occur
§ Example: pull request
triggers build for
validation
§ Example: push for
commit
• Repository Dispatch
Events
§ Endpoint that can be
used to trigger webhook
event
§ Can be used for activity
that is not in GitHub
§ Can trigger a GitHub
Actions workflow or
GitHub App webhook
• ref
https://docs.github.com
/en/rest/reference/repo
s#create-a-repository-
dispatch-event
Event
techupskills.com | techskillstransformations.com
@techupskills
17
© 2023 Brent C. Laster &
How actions work (workflows)
• Events trigger workflows
workflow
Event
§ Procedure to run
automatically
§ Added to your repository
§ Composed of one+ jobs
§ Can be triggered/scheduled
by event
§ Useful for doing CI/CD
actions such as building,
testing, packaging, etc.
techupskills.com | techskillstransformations.com
@techupskills
18
© 2023 Brent C. Laster &
How actions work (jobs, steps, actions, shell cmds)
Workflows contain jobs
§ Set of steps
§ Workflow with multiple jobs runs them in parallel
Jobs contain steps
§ A task that can execute commands in a job
§ Can be either
» action
» shell command
workflow
Job 1
Job 2
Event
Step 1
Step 1
Step 2
action or
shell cmd
action
§ Independent
commands
§ Based off repository
in GitHub
§ Used in steps to
form a job
§ Smallest unit in a
workflow
§ Can be created or
pulled in from the
community
§ Only usable if
included as a step
action or
shell cmd
action or
shell cmd
techupskills.com | techskillstransformations.com
@techupskills
19
© 2023 Brent C. Laster &
How actions work (runner)
Runner
• A server with GitHub
Actions runner app
on it
• Can use runner
provided by/hosted
via GitHub or use
your own
• Runner listens for
available jobs
• Steps in a job execute
on the same runner
workflow
Job 1
Job 2
Event
Step 1
Step 1
Step 2
Runner 1
action or cmd
runs
Runner 2
action or cmd
runs
logs results
logs results
action or
shell cmd
action or
shell cmd
action or
shell cmd
techupskills.com | techskillstransformations.com
@techupskills
20
© 2023 Brent C. Laster &
How actions work
GitHub Repository
.github
workflows
workflow1.yml
Job 1
Step 1
Step 2
Job 2
Step 1
workflow2.yml
Job 1
Step 1
Job 2
Step 1
Step 2
Runner 1
Runner 2
Event
• Resides in
.github/workflows
• Can have multiple
workflows
action or
shell cmd
action or
shell cmd
action or
shell cmd
action or
shell cmd
action or
shell cmd
action or
shell cmd
action or cmd
runs
logs results
action or cmd
runs
logs results
techupskills.com | techskillstransformations.com
@techupskills
21
© 2023 Brent C. Laster &
Integration with GitHub Interface
techupskills.com | techskillstransformations.com
@techupskills
22
© 2023 Brent C. Laster &
Viewing Logs
techupskills.com | techskillstransformations.com
@techupskills
23
© 2023 Brent C. Laster &
Editing Workflows
techupskills.com | techskillstransformations.com
@techupskills
26
© 2023 Brent C. Laster &
|
Lab 1 – Creating a simple example
Purpose: In this lab, we’ll get a quick start learning about GitHub Actions by creating a simple project that uses
them. We’ll also see what a first run of a workflow with actions looks like.
techupskills.com | techskillstransformations.com
@techupskills
27
© 2023 Brent C. Laster &
Self-hosted Runners
• Useful when you need more configurability
and control
• Allows you to choose and customize
configuration, system resources, available
software, etc.
• Can be physical systems, VMs, containers, on-
prem or cloud
• Runner system connects to GitHub via GitHub
Actions self-hosted runner
• Automatically kicked off of GitHub if no
connection to GitHub Actions after 30 days
• Recommended to use only with private repos
§ Forks of repos could run dangerous code on self-
hosted runner machine (via PR that executes code
in workflow)
techupskills.com | techskillstransformations.com
@techupskills
28
© 2023 Brent C. Laster &
GitHub-hosted vs Self-hosted Runners
GitHub-hosted Self-hosted
Definition Hosted by GitHub Any system/configuration
you want to use
Prereqs Running GitHub actions
runner application
GitHub actions self-hosted
runner application
Platforms Windows, Linux, MacOS Any that can be made to
work
Advantages Quicker and simpler Highly configurable
Management/Ownership GitHub As defined
Clean instance For every job execution Optional
Cost Free minutes on GitHub
plan with cost for overages
Free to use with actions,
but owner is responsible
for any other cost
Automatic updates For OS, installed packages,
tools, and hosted runner
application
Only for self-hosted runner
application
Implementation Virtual Virtual or physical
techupskills.com | techskillstransformations.com
@techupskills
29
© 2023 Brent C. Laster &
Creating self-hosted runners
• Repo->Settings->Actions->Runners->New self-hosted runner
techupskills.com | techskillstransformations.com
@techupskills
30
© 2023 Brent C. Laster &
Configuring self hosted runners
techupskills.com | techskillstransformations.com
@techupskills
31
© 2023 Brent C. Laster &
GitHub Actions Runners
• Virtual
environments for
GitHub actions
hosted runners
• New VM for each
job run
• VM images of
Microsoft-hosted
agents used for
Azure Pipelines
• Updated
periodically by
GitHub
techupskills.com | techskillstransformations.com
@techupskills
32
© 2023 Brent C. Laster &
GitHub Actions Storage - Artifacts
• Actions allow you to persist data after job has completed - as artifacts
• Artifact - file or collection of files produced during workflow run
§ build and test output
§ log files
§ binary files
• Artifacts are uploaded during workflow run
§ can be shared between jobs in same workflow
§ visible in the UI
• Default retention period is 90 days
techupskills.com | techskillstransformations.com
@techupskills
33
© 2023 Brent C. Laster &
What are artifacts?
• An item that is either a deliverable (something used by the final product) or
included in a deliverable
• Examples:
§ executable file created by compiling source that links in several other libraries
§ compressed file such as a war or zip file that contains another set of files with it
• Artifacts get versioned, stored, and retrieved as needed for use in
§ assembly
§ testing
§ validation
techupskills.com | techskillstransformations.com
@techupskills
34
© 2023 Brent C. Laster &
Managing Artifacts with GitHub Actions
• Actions provides functionality
for managing artifacts
• As defined by Actions, artifacts
= files or collections of files
created as result of a workflow
run and persisted in GitHub
• Provides the ability to persist
artifacts created during a
workflow run
• Jobs in the same workflow can
access and use persisted
artifacts - like projects in a
pipeline
• Actions also provides ability to
cache content to speed up
future runs
• By default, GitHub keeps
artifacts (and build logs)
around for 90 days
• Artifacts must be uploaded to
be persisted
techupskills.com | techskillstransformations.com
@techupskills
35
© 2023 Brent C. Laster &
Searching for a Public Action
techupskills.com | techskillstransformations.com
@techupskills
36
© 2023 Brent C. Laster &
Actions use Workflows
techupskills.com | techskillstransformations.com
@techupskills
37
© 2023 Brent C. Laster &
Upload a Build Artifact Action Usage
• Note: "my-artifact" is a generic reference - not the
actual filename
techupskills.com | techskillstransformations.com
@techupskills
38
© 2023 Brent C. Laster &
Downloading artifact
• In workflow run,
click on artifact
name
• Download and
expand
techupskills.com | techskillstransformations.com
@techupskills
43
© 2023 Brent C. Laster &
|
Lab 2 – Learning more about Actions
Purpose: In this lab, we’ll see how to get more information about Actions and how to update our workflow to use
others.
techupskills.com | techskillstransformations.com
@techupskills
44
© 2023 Brent C. Laster &
Custom Actions
• Can be created by you
• Can result from customizing community actions
• Can be put on Marketplace and shared
• repository must be public
• Can integrate with any public API
• Can run directly on a machine or in Docker
container
• Can define inputs, outputs, and environment
variables
• Require metadata file
• defines inputs, outputs, and entrypoint
• must be named either action.yaml or
action.yml
• Should be tagged with a label and then pushed to
GitHub
• To use:
• In file in .github/workflows/main.yml
• In steps
• "uses: <github path to action>@<label>
$ <create GitHub repo>
$ <clone repo>
$ <create files>
$ git add action.yml <other files>
$ git commit -m "action files"
$ git tag -a -m "first release of action" v1
$ git push --follow-tags
on: [push]
jobs:
example_job:
runs on: ubuntu-latest
name: An example job
steps:
- name: Example step
id: example_step
uses: <repo name>/<action name>@<tag>
...
.github/workflows/example.yml
techupskills.com | techskillstransformations.com
@techupskills
45
© 2023 Brent C. Laster &
Custom Action Types
• Docker
• Packages env with actions code
• Env can include specific OS versions,
config, tools, etc.
• Well suited for specific env needs
• Runs only on Linux runners with
Docker installed
• Slower due to cost of building and
retrieving container
• GitHub builds image from Dockerfile
and runs comands in a new
container based on image
• Javascript
• Run directly on runner for any of
macOS, Linux, or Windows
• Separates action from env
• Fast than Docker
• Needs to be pure JavaScript (no
other binaries)
• Can use binaries already on runner
• Composite
• Combines multiple workflow steps
in one action
Runner
FROM <base> ....
COPY <entry script>
ENTRYPOINT <script>
Dockerfile
...
runs:
using: 'docker'
image: 'Dockerfile'
args:
....
action.yml
+ +
Runner
+ +
...
runs:
using: 'node12'
main: 'index.js'
action.yml
npm install @actions/core
npm install @actions/github
const core =
require('@actions/core');
const github =
require('@actions/github);
try{
...
} catch (error) {
...
}
index.js
Runner
...
runs:
using: 'composite'
- run: echo ...
- run: ${{ github.action.path
}}/shell-script.sh
action.yml
+
echo ...
...
shell-script.sh
techupskills.com | techskillstransformations.com
@techupskills
46
© 2023 Brent C. Laster &
Updating workflows with Pull Requests #1
techupskills.com | techskillstransformations.com
@techupskills
47
© 2023 Brent C. Laster &
Fixing errors
techupskills.com | techskillstransformations.com
@techupskills
48
© 2023 Brent C. Laster &
|
Lab 3 – Adding your own action
Purpose: In this lab, we’ll see how to create how to add and use a custom GitHub Action.
techupskills.com | techskillstransformations.com
@techupskills
49
© 2023 Brent C. Laster &
Filtering workflows
• Enter text in search bar
• Click on "x" at end to
clear
• Click on category in
"workflow run results"
bar
• Select from the list
techupskills.com | techskillstransformations.com
@techupskills
50
© 2023 Brent C. Laster &
Creating a status badge
• Adds status information displayed in README file
• Click on "..." at end of selected line in workflow
techupskills.com | techskillstransformations.com
@techupskills
51
© 2023 Brent C. Laster &
Drilling into logs
• Click on workflow in list
• Click on step
• Step log is shown
• Gear icon can be used for
options - such as timestamps
• Can also view raw logs
techupskills.com | techskillstransformations.com
@techupskills
52
© 2023 Brent C. Laster &
Running your workflow manually
• Add a "workflow dispatch event" trigger
• Merge changes
• Afterwards will have "Run workflow" button in
workflow list
techupskills.com | techskillstransformations.com
@techupskills
53
© 2023 Brent C. Laster &
|
Lab 4 – Exploring logs
Purpose: In this lab, we’ll take a closer look at the different options for getting information from logs.
techupskills.com | techskillstransformations.com
@techupskills
54
© 2023 Brent C. Laster &
Workflow commands
• Used to communicate with the runner machine to
§ Set environment variables
§ Set output values used by other actions
§ Add debug messages to logs
• Typically use "echo" command with certain format
• Also can be used to execute some commands in
Actions Toolkit
techupskills.com | techskillstransformations.com
@techupskills
55
© 2023 Brent C. Laster &
Actions Toolkit
• Provides packages for more
easily creating/working with
actions
• Functions in packages can be
run in code as in
core.setOutput('SELECTED_COLOR
', 'red');
or (in many cases)
• run as workflow commands
- name: Set selected color run:
echo '::set-output
name=SELECTED_COLOR::green'
techupskills.com | techskillstransformations.com
@techupskills
56
© 2023 Brent C. Laster &
Actions Toolkit packages
• Collections of
related
functions
• Can be
imported into
code for actions
techupskills.com | techskillstransformations.com
@techupskills
57
© 2023 Brent C. Laster &
Monitoring and Troubleshooting
• Use "default" information
§ Visualization graph of a workflow
§ Workflow run history
§ Workflow logs
§ Print debug messages in logs
§ can use core.debug or "echo "::debug::
<message>"
§ Display of debug messages can be via:
» Option on job rerun
» setting up repo secret OR variable
» name:
ACTIONS_STEP_DEBUG
» value:
true
techupskills.com | techskillstransformations.com
@techupskills
58
© 2023 Brent C. Laster &
Rerunning jobs
• Available after job has run
to completion
• Includes dependent jobs
• Option to show debug
messages on re-run
techupskills.com | techskillstransformations.com
@techupskills
59
© 2023 Brent C. Laster &
Creating repo variables
1
2
3
4
techupskills.com | techskillstransformations.com
@techupskills
60
© 2023 Brent C. Laster &
Defining repo variables
11
techupskills.com | techskillstransformations.com
@techupskills
61
© 2023 Brent C. Laster &
|
Lab 5 – Looking at debug info
Purpose: In this lab, we’ll look at some ways to get more debugging info from our workflows.
techupskills.com | techskillstransformations.com
@techupskills
62
© 2023 Brent C. Laster &
GitHub Personal Access Token
• Provides specific accesses
• Replaces passwords
• Can be done through https://github.com/settings/tokens
• Or can be setup via Settings->Profile->Developer Settings->Personal Access Tokens
• Generate new token and save it
techupskills.com | techskillstransformations.com
@techupskills
63
© 2023 Brent C. Laster &
Creating a repo secret
1
2
3
techupskills.com | techskillstransformations.com
@techupskills
64
© 2023 Brent C. Laster &
Workflows invoking GitHub
• Workflows can
invoke GitHub or
other
functionality via
techniques such
as curl
techupskills.com | techskillstransformations.com
@techupskills
65
© 2023 Brent C. Laster &
Chaining Workflows Together
• Can be done via GitHub API calls
• Requires API Token saved as a secret
• One workflow then invokes the other via API call
create-issue-on-failure:
runs-on: ubuntu-latest
needs: [test-run, count-args]
if: always() && failure()
steps:
- name: invoke workflow to create issue
run: >
curl -X POST
-H "authorization: Bearer ${{ secrets.WORKFLOW_USE }}"
-H "Accept: application/vnd.github.v3+json"
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/create-failure-issue.yml/dispatches"
-d '{"ref":"main",
"inputs":
{"title":"Automated workflow failure issue for commit ${{ github.sha }}",
"body":"This issue was automatically created by the GitHub Action workflow ** ${{ github.workflow }} **"}
}'
techupskills.com | techskillstransformations.com
@techupskills
66
© 2023 Brent C. Laster &
Reusable workflows
• Workflow able to be called from another workflow
• Avoids duplication/increases maintainability & reuse
• Workflow that uses another workflow is "caller"
• Reuse calls entire workflow, as if it were in caller
• Reusable workflow can be
§ {owner}/{repo}/.github/workflows/{filename}@{ref} for other
repos
» {ref} can be any valid identifier (SHA, tag, branch)
§ ./.github/workflows/{filename} if in same repo
» {filename} is actual yaml file name
• Reusable workflow is defined via workflow_call trigger
• Reusable workflow is invoked via job.<job id>.uses
techupskills.com | techskillstransformations.com
@techupskills
67
© 2023 Brent C. Laster &
Reusable workflow - callable
techupskills.com | techskillstransformations.com
@techupskills
68
© 2023 Brent C. Laster &
Reusable workflow example - caller
techupskills.com | techskillstransformations.com
@techupskills
69
© 2023 Brent C. Laster &
Expressions and Conditions
• Expression
§ Any combination of literal values,
references to a context (github, env, job,
runner, etc.), or functions.
§ Can combine using operators.
§ Can be used to set environment variables
§ Commonly used with "conditional" "if"
keyword
» Used to determine if step should run
» If conditional is true, step runs
• Requires special syntax for evaluation
§ ${{ <expression> }}
§ Without syntax, would just be treated as
string
§ Can omit special syntax with GtHub and "if"
techupskills.com | techskillstransformations.com
@techupskills
70
© 2023 Brent C. Laster &
Status check functions
• Set of functions that can be used as expressions in if
conditionals
• Used as part of steps
• format is if: ${{ expression() }}
• can be simplified to if: expression()
• examples:
if: success() - true if none of previous steps have failed or been
canceled
if: always() - step always executed and return true - even if
canceled
if: cancelled() - true if workflow is cancelled
if: failure() - true if any previous step failed or any job has failed
that this job is dependent upon
techupskills.com | techskillstransformations.com
@techupskills
71
© 2023 Brent C. Laster &
|
Lab 6 – Using reusable workflows
Purpose: In this lab, we’ll learn some alternative ways to driver workflows.
techupskills.com | techskillstransformations.com
@techupskills
99
© 2023 Brent C. Laster &
That’s all - thanks!
techskillstransformations.com
getskillsnow.com

Mais conteúdo relacionado

Semelhante a Introduction to GitHub Actions

Semelhante a Introduction to GitHub Actions (20)

DWX 2022 - DevSecOps mit GitHub
DWX 2022 - DevSecOps mit GitHubDWX 2022 - DevSecOps mit GitHub
DWX 2022 - DevSecOps mit GitHub
 
Increase the Velocity of Your Software Releases Using GitHub and DeployHub
Increase the Velocity of Your Software Releases Using GitHub and DeployHubIncrease the Velocity of Your Software Releases Using GitHub and DeployHub
Increase the Velocity of Your Software Releases Using GitHub and DeployHub
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
 
Agile Secure Cloud Application Development Management
Agile Secure Cloud Application Development ManagementAgile Secure Cloud Application Development Management
Agile Secure Cloud Application Development Management
 
GitHub for partners
GitHub for partnersGitHub for partners
GitHub for partners
 
Migrating To GitHub
Migrating To GitHub  Migrating To GitHub
Migrating To GitHub
 
GitHub Actions - using Free Oracle Cloud Infrastructure (OCI)
GitHub Actions - using Free Oracle Cloud Infrastructure (OCI)GitHub Actions - using Free Oracle Cloud Infrastructure (OCI)
GitHub Actions - using Free Oracle Cloud Infrastructure (OCI)
 
GitHub Actions 101
GitHub Actions 101GitHub Actions 101
GitHub Actions 101
 
Git & GitHub N00bs
Git & GitHub N00bsGit & GitHub N00bs
Git & GitHub N00bs
 
Introduction to GitHub Copilot
Introduction to GitHub CopilotIntroduction to GitHub Copilot
Introduction to GitHub Copilot
 
Introduction to GitHub Copilot
Introduction to GitHub CopilotIntroduction to GitHub Copilot
Introduction to GitHub Copilot
 
Windows containers on Kubernetes
Windows containers on KubernetesWindows containers on Kubernetes
Windows containers on Kubernetes
 
Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)
 
OSCONF - April 2021 - Run GitHub Actions Locally with nektos/act and Docker
OSCONF - April 2021 - Run GitHub Actions Locally with nektos/act and DockerOSCONF - April 2021 - Run GitHub Actions Locally with nektos/act and Docker
OSCONF - April 2021 - Run GitHub Actions Locally with nektos/act and Docker
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Elevate Your Builds: Next-Gen CI/CD with Azure Container Apps and KEDA
Elevate Your Builds: Next-Gen CI/CD with Azure Container Apps and KEDAElevate Your Builds: Next-Gen CI/CD with Azure Container Apps and KEDA
Elevate Your Builds: Next-Gen CI/CD with Azure Container Apps and KEDA
 
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS FargateBuilding a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
 
Gradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesGradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build times
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event Keynote
 
.Git for WordPress Developers
.Git for WordPress Developers.Git for WordPress Developers
.Git for WordPress Developers
 

Mais de All Things Open

Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
All Things Open
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
All Things Open
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
All Things Open
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
All Things Open
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
All Things Open
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
All Things Open
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
All Things Open
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
All Things Open
 

Mais de All Things Open (20)

Building Reliability - The Realities of Observability
Building Reliability - The Realities of ObservabilityBuilding Reliability - The Realities of Observability
Building Reliability - The Realities of Observability
 
Modern Database Best Practices
Modern Database Best PracticesModern Database Best Practices
Modern Database Best Practices
 
Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
 
The State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil NashThe State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil Nash
 
Total ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScriptTotal ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScript
 
What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 
DEI Challenges and Success
DEI Challenges and SuccessDEI Challenges and Success
DEI Challenges and Success
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssembly
 
Using SQL to Find Needles in Haystacks
Using SQL to Find Needles in HaystacksUsing SQL to Find Needles in Haystacks
Using SQL to Find Needles in Haystacks
 
Configuration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit InterceptConfiguration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit Intercept
 
Scaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship ProgramScaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship Program
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
 
Deploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache BeamDeploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache Beam
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

Introduction to GitHub Actions

  • 1. techupskills.com | techskillstransformations.com @techupskills 2 © 2023 Brent C. Laster & Prerequisites • Account at GitHub.com - free tier is fine • Labs doc for workshop § In https://github.com/skilldocs/gh-actions (file is github-actions- labs.pdf) § direct link: » https://github.com/skilldocs/gh-actions/blob/main/github- actions-labs.pdf
  • 2. techupskills.com | techskillstransformations.com @techupskills 3 © 2023 Brent C. Laster & Tech Skills Transformations & Brent Laster Introduction to GitHub Actions
  • 3. techupskills.com | techskillstransformations.com @techupskills 4 © 2023 Brent C. Laster & About me • R&D Director, DevOps • Global trainer – training (Git, Jenkins, Gradle, CI/CD, pipelines, Kubernetes, Helm, ArgoCD, operators) • Author - § OpenSource.com § Professional Git book § Jenkins 2 – Up and Running book § Continuous Integration vs. Continuous Delivery vs. Continuous Deployment mini-book on O'Reilly Learning techskillstransformations.com getskillsnow.com https://www.linkedin.com/in/brentlaster @BrentCLaster GitHub: brentlaster
  • 4. techupskills.com | techskillstransformations.com @techupskills 5 © 2023 Brent C. Laster & Book – Professional Git • Extensive Git reference, explanations, and examples • First part for non-technical • Beginner and advanced reference • Hands-on labs
  • 5. techupskills.com | techskillstransformations.com @techupskills 6 © 2023 Brent C. Laster & Jenkins 2 Book • Jenkins 2 – Up and Running • “It’s an ideal book for those who are new to CI/CD, as well as those who have been using Jenkins for many years. This book will help you discover and rediscover Jenkins.” By Kohsuke Kawaguchi, Creator of Jenkins
  • 6. techupskills.com | techskillstransformations.com @techupskills 7 © 2023 Brent C. Laster & Learning GitHub Actions - Early Release • Early release - Chapters 1-6 on learning.oreilly.com
  • 7. techupskills.com | techskillstransformations.com @techupskills 8 © 2023 Brent C. Laster & O’Reilly Training
  • 9. techupskills.com | techskillstransformations.com @techupskills 10 © 2023 Brent C. Laster & Agenda • What are GitHub Actions? • How do they work? • The GitHub interface to actions • About Actions Runners and Virtual Environments • Using public actions • Workflow runs • Custom actions • Manually running workflows • Monitoring and Troubleshooting • Creating secrets for actions • Chaining workflows together • Using GitHub API calls with actions
  • 10. techupskills.com | techskillstransformations.com @techupskills 11 © 2023 Brent C. Laster & What are GitHub Actions? • Way to create custom, automated workflows in GitHub • Executed based on repository operations • Building blocks - can be combined & shared • Used for usual SDLC tasks • Can be used for CI/CD as alternatives to other apps
  • 11. techupskills.com | techskillstransformations.com @techupskills 12 © 2023 Brent C. Laster & Other use cases (starter workflows)
  • 12. techupskills.com | techskillstransformations.com @techupskills 13 © 2023 Brent C. Laster & What's interesting about it? • Direct integration with GitHub
  • 13. techupskills.com | techskillstransformations.com @techupskills 14 © 2023 Brent C. Laster & What else is interesting about it? • Lots of events can trigger an action workflow - automate practically anything! on: project on: watch on: repository_dispatch on: delete on: check_run on: page_build on: scheduled on: pull_request on: public on: pull_request_review_comment on: pull_push on: fork https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
  • 14. techupskills.com | techskillstransformations.com @techupskills 15 © 2023 Brent C. Laster & Types of triggers for events • single event - on: push • list of events - on: [push, pull_request] • event types with qualifiers, such as branches, tags, or files on: push: branches: - main - 'rel/v*' tags: - v1.* - beta paths: - '**.ts' • scheduled events on: scheduled - cron: '30 5,15 * * *' • manual events - on: workflow-dispatch on: repository-dispatch • workflow reuse events - on: workflow-call • activity types
  • 15. techupskills.com | techskillstransformations.com @techupskills 16 © 2023 Brent C. Laster & How actions work (events) • Events occur § Example: pull request triggers build for validation § Example: push for commit • Repository Dispatch Events § Endpoint that can be used to trigger webhook event § Can be used for activity that is not in GitHub § Can trigger a GitHub Actions workflow or GitHub App webhook • ref https://docs.github.com /en/rest/reference/repo s#create-a-repository- dispatch-event Event
  • 16. techupskills.com | techskillstransformations.com @techupskills 17 © 2023 Brent C. Laster & How actions work (workflows) • Events trigger workflows workflow Event § Procedure to run automatically § Added to your repository § Composed of one+ jobs § Can be triggered/scheduled by event § Useful for doing CI/CD actions such as building, testing, packaging, etc.
  • 17. techupskills.com | techskillstransformations.com @techupskills 18 © 2023 Brent C. Laster & How actions work (jobs, steps, actions, shell cmds) Workflows contain jobs § Set of steps § Workflow with multiple jobs runs them in parallel Jobs contain steps § A task that can execute commands in a job § Can be either » action » shell command workflow Job 1 Job 2 Event Step 1 Step 1 Step 2 action or shell cmd action § Independent commands § Based off repository in GitHub § Used in steps to form a job § Smallest unit in a workflow § Can be created or pulled in from the community § Only usable if included as a step action or shell cmd action or shell cmd
  • 18. techupskills.com | techskillstransformations.com @techupskills 19 © 2023 Brent C. Laster & How actions work (runner) Runner • A server with GitHub Actions runner app on it • Can use runner provided by/hosted via GitHub or use your own • Runner listens for available jobs • Steps in a job execute on the same runner workflow Job 1 Job 2 Event Step 1 Step 1 Step 2 Runner 1 action or cmd runs Runner 2 action or cmd runs logs results logs results action or shell cmd action or shell cmd action or shell cmd
  • 19. techupskills.com | techskillstransformations.com @techupskills 20 © 2023 Brent C. Laster & How actions work GitHub Repository .github workflows workflow1.yml Job 1 Step 1 Step 2 Job 2 Step 1 workflow2.yml Job 1 Step 1 Job 2 Step 1 Step 2 Runner 1 Runner 2 Event • Resides in .github/workflows • Can have multiple workflows action or shell cmd action or shell cmd action or shell cmd action or shell cmd action or shell cmd action or shell cmd action or cmd runs logs results action or cmd runs logs results
  • 20. techupskills.com | techskillstransformations.com @techupskills 21 © 2023 Brent C. Laster & Integration with GitHub Interface
  • 23. techupskills.com | techskillstransformations.com @techupskills 26 © 2023 Brent C. Laster & | Lab 1 – Creating a simple example Purpose: In this lab, we’ll get a quick start learning about GitHub Actions by creating a simple project that uses them. We’ll also see what a first run of a workflow with actions looks like.
  • 24. techupskills.com | techskillstransformations.com @techupskills 27 © 2023 Brent C. Laster & Self-hosted Runners • Useful when you need more configurability and control • Allows you to choose and customize configuration, system resources, available software, etc. • Can be physical systems, VMs, containers, on- prem or cloud • Runner system connects to GitHub via GitHub Actions self-hosted runner • Automatically kicked off of GitHub if no connection to GitHub Actions after 30 days • Recommended to use only with private repos § Forks of repos could run dangerous code on self- hosted runner machine (via PR that executes code in workflow)
  • 25. techupskills.com | techskillstransformations.com @techupskills 28 © 2023 Brent C. Laster & GitHub-hosted vs Self-hosted Runners GitHub-hosted Self-hosted Definition Hosted by GitHub Any system/configuration you want to use Prereqs Running GitHub actions runner application GitHub actions self-hosted runner application Platforms Windows, Linux, MacOS Any that can be made to work Advantages Quicker and simpler Highly configurable Management/Ownership GitHub As defined Clean instance For every job execution Optional Cost Free minutes on GitHub plan with cost for overages Free to use with actions, but owner is responsible for any other cost Automatic updates For OS, installed packages, tools, and hosted runner application Only for self-hosted runner application Implementation Virtual Virtual or physical
  • 26. techupskills.com | techskillstransformations.com @techupskills 29 © 2023 Brent C. Laster & Creating self-hosted runners • Repo->Settings->Actions->Runners->New self-hosted runner
  • 27. techupskills.com | techskillstransformations.com @techupskills 30 © 2023 Brent C. Laster & Configuring self hosted runners
  • 28. techupskills.com | techskillstransformations.com @techupskills 31 © 2023 Brent C. Laster & GitHub Actions Runners • Virtual environments for GitHub actions hosted runners • New VM for each job run • VM images of Microsoft-hosted agents used for Azure Pipelines • Updated periodically by GitHub
  • 29. techupskills.com | techskillstransformations.com @techupskills 32 © 2023 Brent C. Laster & GitHub Actions Storage - Artifacts • Actions allow you to persist data after job has completed - as artifacts • Artifact - file or collection of files produced during workflow run § build and test output § log files § binary files • Artifacts are uploaded during workflow run § can be shared between jobs in same workflow § visible in the UI • Default retention period is 90 days
  • 30. techupskills.com | techskillstransformations.com @techupskills 33 © 2023 Brent C. Laster & What are artifacts? • An item that is either a deliverable (something used by the final product) or included in a deliverable • Examples: § executable file created by compiling source that links in several other libraries § compressed file such as a war or zip file that contains another set of files with it • Artifacts get versioned, stored, and retrieved as needed for use in § assembly § testing § validation
  • 31. techupskills.com | techskillstransformations.com @techupskills 34 © 2023 Brent C. Laster & Managing Artifacts with GitHub Actions • Actions provides functionality for managing artifacts • As defined by Actions, artifacts = files or collections of files created as result of a workflow run and persisted in GitHub • Provides the ability to persist artifacts created during a workflow run • Jobs in the same workflow can access and use persisted artifacts - like projects in a pipeline • Actions also provides ability to cache content to speed up future runs • By default, GitHub keeps artifacts (and build logs) around for 90 days • Artifacts must be uploaded to be persisted
  • 32. techupskills.com | techskillstransformations.com @techupskills 35 © 2023 Brent C. Laster & Searching for a Public Action
  • 33. techupskills.com | techskillstransformations.com @techupskills 36 © 2023 Brent C. Laster & Actions use Workflows
  • 34. techupskills.com | techskillstransformations.com @techupskills 37 © 2023 Brent C. Laster & Upload a Build Artifact Action Usage • Note: "my-artifact" is a generic reference - not the actual filename
  • 35. techupskills.com | techskillstransformations.com @techupskills 38 © 2023 Brent C. Laster & Downloading artifact • In workflow run, click on artifact name • Download and expand
  • 36. techupskills.com | techskillstransformations.com @techupskills 43 © 2023 Brent C. Laster & | Lab 2 – Learning more about Actions Purpose: In this lab, we’ll see how to get more information about Actions and how to update our workflow to use others.
  • 37. techupskills.com | techskillstransformations.com @techupskills 44 © 2023 Brent C. Laster & Custom Actions • Can be created by you • Can result from customizing community actions • Can be put on Marketplace and shared • repository must be public • Can integrate with any public API • Can run directly on a machine or in Docker container • Can define inputs, outputs, and environment variables • Require metadata file • defines inputs, outputs, and entrypoint • must be named either action.yaml or action.yml • Should be tagged with a label and then pushed to GitHub • To use: • In file in .github/workflows/main.yml • In steps • "uses: <github path to action>@<label> $ <create GitHub repo> $ <clone repo> $ <create files> $ git add action.yml <other files> $ git commit -m "action files" $ git tag -a -m "first release of action" v1 $ git push --follow-tags on: [push] jobs: example_job: runs on: ubuntu-latest name: An example job steps: - name: Example step id: example_step uses: <repo name>/<action name>@<tag> ... .github/workflows/example.yml
  • 38. techupskills.com | techskillstransformations.com @techupskills 45 © 2023 Brent C. Laster & Custom Action Types • Docker • Packages env with actions code • Env can include specific OS versions, config, tools, etc. • Well suited for specific env needs • Runs only on Linux runners with Docker installed • Slower due to cost of building and retrieving container • GitHub builds image from Dockerfile and runs comands in a new container based on image • Javascript • Run directly on runner for any of macOS, Linux, or Windows • Separates action from env • Fast than Docker • Needs to be pure JavaScript (no other binaries) • Can use binaries already on runner • Composite • Combines multiple workflow steps in one action Runner FROM <base> .... COPY <entry script> ENTRYPOINT <script> Dockerfile ... runs: using: 'docker' image: 'Dockerfile' args: .... action.yml + + Runner + + ... runs: using: 'node12' main: 'index.js' action.yml npm install @actions/core npm install @actions/github const core = require('@actions/core'); const github = require('@actions/github); try{ ... } catch (error) { ... } index.js Runner ... runs: using: 'composite' - run: echo ... - run: ${{ github.action.path }}/shell-script.sh action.yml + echo ... ... shell-script.sh
  • 39. techupskills.com | techskillstransformations.com @techupskills 46 © 2023 Brent C. Laster & Updating workflows with Pull Requests #1
  • 41. techupskills.com | techskillstransformations.com @techupskills 48 © 2023 Brent C. Laster & | Lab 3 – Adding your own action Purpose: In this lab, we’ll see how to create how to add and use a custom GitHub Action.
  • 42. techupskills.com | techskillstransformations.com @techupskills 49 © 2023 Brent C. Laster & Filtering workflows • Enter text in search bar • Click on "x" at end to clear • Click on category in "workflow run results" bar • Select from the list
  • 43. techupskills.com | techskillstransformations.com @techupskills 50 © 2023 Brent C. Laster & Creating a status badge • Adds status information displayed in README file • Click on "..." at end of selected line in workflow
  • 44. techupskills.com | techskillstransformations.com @techupskills 51 © 2023 Brent C. Laster & Drilling into logs • Click on workflow in list • Click on step • Step log is shown • Gear icon can be used for options - such as timestamps • Can also view raw logs
  • 45. techupskills.com | techskillstransformations.com @techupskills 52 © 2023 Brent C. Laster & Running your workflow manually • Add a "workflow dispatch event" trigger • Merge changes • Afterwards will have "Run workflow" button in workflow list
  • 46. techupskills.com | techskillstransformations.com @techupskills 53 © 2023 Brent C. Laster & | Lab 4 – Exploring logs Purpose: In this lab, we’ll take a closer look at the different options for getting information from logs.
  • 47. techupskills.com | techskillstransformations.com @techupskills 54 © 2023 Brent C. Laster & Workflow commands • Used to communicate with the runner machine to § Set environment variables § Set output values used by other actions § Add debug messages to logs • Typically use "echo" command with certain format • Also can be used to execute some commands in Actions Toolkit
  • 48. techupskills.com | techskillstransformations.com @techupskills 55 © 2023 Brent C. Laster & Actions Toolkit • Provides packages for more easily creating/working with actions • Functions in packages can be run in code as in core.setOutput('SELECTED_COLOR ', 'red'); or (in many cases) • run as workflow commands - name: Set selected color run: echo '::set-output name=SELECTED_COLOR::green'
  • 49. techupskills.com | techskillstransformations.com @techupskills 56 © 2023 Brent C. Laster & Actions Toolkit packages • Collections of related functions • Can be imported into code for actions
  • 50. techupskills.com | techskillstransformations.com @techupskills 57 © 2023 Brent C. Laster & Monitoring and Troubleshooting • Use "default" information § Visualization graph of a workflow § Workflow run history § Workflow logs § Print debug messages in logs § can use core.debug or "echo "::debug:: <message>" § Display of debug messages can be via: » Option on job rerun » setting up repo secret OR variable » name: ACTIONS_STEP_DEBUG » value: true
  • 51. techupskills.com | techskillstransformations.com @techupskills 58 © 2023 Brent C. Laster & Rerunning jobs • Available after job has run to completion • Includes dependent jobs • Option to show debug messages on re-run
  • 52. techupskills.com | techskillstransformations.com @techupskills 59 © 2023 Brent C. Laster & Creating repo variables 1 2 3 4
  • 53. techupskills.com | techskillstransformations.com @techupskills 60 © 2023 Brent C. Laster & Defining repo variables 11
  • 54. techupskills.com | techskillstransformations.com @techupskills 61 © 2023 Brent C. Laster & | Lab 5 – Looking at debug info Purpose: In this lab, we’ll look at some ways to get more debugging info from our workflows.
  • 55. techupskills.com | techskillstransformations.com @techupskills 62 © 2023 Brent C. Laster & GitHub Personal Access Token • Provides specific accesses • Replaces passwords • Can be done through https://github.com/settings/tokens • Or can be setup via Settings->Profile->Developer Settings->Personal Access Tokens • Generate new token and save it
  • 56. techupskills.com | techskillstransformations.com @techupskills 63 © 2023 Brent C. Laster & Creating a repo secret 1 2 3
  • 57. techupskills.com | techskillstransformations.com @techupskills 64 © 2023 Brent C. Laster & Workflows invoking GitHub • Workflows can invoke GitHub or other functionality via techniques such as curl
  • 58. techupskills.com | techskillstransformations.com @techupskills 65 © 2023 Brent C. Laster & Chaining Workflows Together • Can be done via GitHub API calls • Requires API Token saved as a secret • One workflow then invokes the other via API call create-issue-on-failure: runs-on: ubuntu-latest needs: [test-run, count-args] if: always() && failure() steps: - name: invoke workflow to create issue run: > curl -X POST -H "authorization: Bearer ${{ secrets.WORKFLOW_USE }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/actions/workflows/create-failure-issue.yml/dispatches" -d '{"ref":"main", "inputs": {"title":"Automated workflow failure issue for commit ${{ github.sha }}", "body":"This issue was automatically created by the GitHub Action workflow ** ${{ github.workflow }} **"} }'
  • 59. techupskills.com | techskillstransformations.com @techupskills 66 © 2023 Brent C. Laster & Reusable workflows • Workflow able to be called from another workflow • Avoids duplication/increases maintainability & reuse • Workflow that uses another workflow is "caller" • Reuse calls entire workflow, as if it were in caller • Reusable workflow can be § {owner}/{repo}/.github/workflows/{filename}@{ref} for other repos » {ref} can be any valid identifier (SHA, tag, branch) § ./.github/workflows/{filename} if in same repo » {filename} is actual yaml file name • Reusable workflow is defined via workflow_call trigger • Reusable workflow is invoked via job.<job id>.uses
  • 60. techupskills.com | techskillstransformations.com @techupskills 67 © 2023 Brent C. Laster & Reusable workflow - callable
  • 61. techupskills.com | techskillstransformations.com @techupskills 68 © 2023 Brent C. Laster & Reusable workflow example - caller
  • 62. techupskills.com | techskillstransformations.com @techupskills 69 © 2023 Brent C. Laster & Expressions and Conditions • Expression § Any combination of literal values, references to a context (github, env, job, runner, etc.), or functions. § Can combine using operators. § Can be used to set environment variables § Commonly used with "conditional" "if" keyword » Used to determine if step should run » If conditional is true, step runs • Requires special syntax for evaluation § ${{ <expression> }} § Without syntax, would just be treated as string § Can omit special syntax with GtHub and "if"
  • 63. techupskills.com | techskillstransformations.com @techupskills 70 © 2023 Brent C. Laster & Status check functions • Set of functions that can be used as expressions in if conditionals • Used as part of steps • format is if: ${{ expression() }} • can be simplified to if: expression() • examples: if: success() - true if none of previous steps have failed or been canceled if: always() - step always executed and return true - even if canceled if: cancelled() - true if workflow is cancelled if: failure() - true if any previous step failed or any job has failed that this job is dependent upon
  • 64. techupskills.com | techskillstransformations.com @techupskills 71 © 2023 Brent C. Laster & | Lab 6 – Using reusable workflows Purpose: In this lab, we’ll learn some alternative ways to driver workflows.
  • 65. techupskills.com | techskillstransformations.com @techupskills 99 © 2023 Brent C. Laster & That’s all - thanks! techskillstransformations.com getskillsnow.com