Skip to content

A quickstart and reference for GitHub Actions to help you get up and running fast.

License

Notifications You must be signed in to change notification settings

chingc/tutorial-github-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Actions

A collection of small GitHub Actions workflows demonstrating various capabilities and features to get you started.

basic.yml

A basic workflow to do the essentials for a Python project.


If you're unfamiliar with GitHub Actions this will help you get started quickly.

  • Runs when changes are pushed
  • Runs on a schedule
  • Can be run manually from the GitHub UI
  • Uses actions/checkout
  • Uses actions/setup-python with pip cache
  • Installs requirements.txt and runs a simple test
  • Includes dependabot.yml to automatically check for package updates

See the workflow.

basic_uv.yml

Same as basic.yml but uses the uv project manager.

See the workflow.

branch_name.yml

Getting the branch name.


This is a common CI operation. Surprisingly, there's no pre-defined way to get it in GitHub Actions.

This demo shows the simplest way without using 3rd party actions or other tools.

It works in most cases, but there are some quirks.

For example, if your commit is tagged this method will return the tag instead of the branch name. See SO link in the references for details.

You may also get an unexpected result depending on the event that triggered the workflow. This demo is set to trigger on pull_request and on push to illustrate this behavior.

  • Shows various github context properties that may or may not contain the branch name
  • Sets branch name to the top level env so it can be accessed by the entire workflow

See the workflow.

cache.yml

Data persistence by caching.


You can cache files, directories, or a combination of them. If you want to test for a cache hit, keep in mind that it only occurs if it matches the primary cache key. A partial match on restore-keys is still considered a cache miss.

  • Uses actions/cache

See the workflow.

context.yml

Accessing context information about workflow runs.


You can access various contexts about the workflow run, which can be helpful for debugging workflow errors or bugs. Be careful as it has the potential to output sensitive information.

See the workflow.

env_var_*.yml

Working with environment variables.


Environment variables and their scopes work as you'd expect in GitHub Actions.

They're also fairly self-contained, so any changes you make are isolated to the job you're in.

One quirk that can cause confusion is the fact that environment variables defined within a step aren't accessible until the next step.

See the workflows:

github_script.yml

Scripting in workflows.


Easily and quickly write JavaScript in your workflow that uses the GitHub API and the workflow run context. The action includes a pre-authenticated octokit/rest.js client and references to many other useful packages.

  • Uses actions/github-script

See the workflow.

homebrew.yml

Using homebrew in your workflow.


Leverage the convenience of homebrew to install applications on GitHub Actions runners.

  • Uses Homebrew/actions/setup-homebrew

See the workflow.

job_summary.yml

Custom output for the summary page of a workflow run.


You can set custom Markdown for each job so it will be displayed on the summary page of a workflow run. Job summaries support GitHub flavored Markdown, and you can add your Markdown content for a step to the GITHUB_STEP_SUMMARY environment file.

When a job finishes, the summaries for all steps in a job are grouped together into a single job summary and are shown on the workflow run summary page. If multiple jobs generate summaries, the job summaries are ordered by job completion time.

Job summaries are isolated between steps and each step is restricted to a maximum size of 1MB. A maximum of 20 job summaries from steps are displayed per job.

See the workflow.

log_annotation.yml

Create annotations in workflow logs.


You can create notice, warning, and error annotations in your workflow logs. Optionally, they can be associated with a file and even a position within the file. Annotations also show up on the job summary page.

See the workflow.

matrix.yml

Define a matrix of different job configurations.


The matrix strategy helps you easily target multiple operating systems and language versions.

  • Uses actions/setup-node

See the workflow.

mise.yml

Using mise in your workflow.


The polyglot tool version manager.

  • Uses jdx/mise-action

See the workflow.

parallel_*.yml

Parallel testing without any code changes or extra dependencies.


The matrix strategy can be used in a particular way to enable parallel testing for free. This means no code changes and no extra dependencies. The idea is to identify where your tests are and distrubute them across multiple GitHub Actions runners. If your testing framework supports parallel testing, you can use it in combination with this strategy to really go fast!

See the workflows:

workflow_input.yml

Adjust how a workflow will run with custom input.


When using the workflow_dispatch event, you can optionally specify inputs that are passed to the workflow.

This trigger only receives events when the workflow file is on the default branch. This means you have to merge your changes to main or master before you can test your inputs. It would be wise to try input changes in a totally separate workflow before merging them into critical workflows.

Also, if the event that triggers the workflow isn't workflow_dispatch the input values are empty/null. This is true even if you have default values defined.

See the workflow.

References

About

A quickstart and reference for GitHub Actions to help you get up and running fast.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages