NUS Hackers Wiki
NUS Hackers Wiki
  • NUS Hackers Wiki
  • Hackerschool
    • Virtual Machines and Linux
    • Beginners' Guide to the Terminal
      • Introduction to the Terminal
      • Modern Shell Tools
      • Shell Scripting
      • Real World Scripting
      • Resources
    • Self-Hosting: Three Easy Pieces
      • 1. Setting up your server
      • 2. Running Services
      • 3. Monitoring your server
    • Vim
    • Introduction to Zig
      • Language Basics
      • Error Handling
      • Memory Management
      • Working with C
      • Exploring comptime
    • CI/CD with Github Actions
      • Background
      • Basics of Github Actions
        • Target workflow
        • Running unit tests
        • Linting code
        • Deploying to Github Pages
      • Advanced use cases
        • Pollers
        • Github script
        • Executing third-party scripts
        • Reusable workflows
      • Cookbook
    • Lightning Git
      • Git Concepts
      • Getting Started with Git
      • Making your first commit
      • Branching
      • Merge Conflicts
      • Integrating remote repositories
      • Collaborative Workflows
      • Commit Manipulation and Reflog
      • Interactive rebasing
      • filter-repo
  • Orbital
    • JavaScript
      • Browser Developer Tools
      • Getting Started
      • Datatypes
      • Operators and Operations
      • Loops and Conditions
      • Functions
      • Strings
      • Arrays
      • HTML
        • Getting Started
        • Tag Attributes
        • HTML Forms
        • Browser Inspector
      • CSS
        • Selectors
        • Colors in CSS
        • Measurements in CSS
        • The Box Model
        • Adding Styles - Part 1
        • Adding Styles - Part 2
      • Working with the DOM
        • Querying the DOM - Selectors
        • Querying the DOM - Element Attributes
        • Querying the DOM - Element Styles
        • Events with JS and HTML
        • Exercise: Click Counter
        • Editing the DOM
        • Fetch Requests
        • Exercise: The NUSMods API
    • React
      • Setup
      • State
    • React Native
      • Setup
      • Intro to JSX
      • Basic Syntax
      • Handling UI
      • Props
      • State Management
    • Git
      • Setup
      • Command Glossary
      • Fundamental Concepts
        • Getting Started
        • Integrating Remote Repositories
        • Branching
        • Merge Conflicts
      • Collaborative Workflows
        • Fork and PR Workflow
        • Branch and PR Workflow
      • Advanced Concepts
        • Ignoring Files
        • Commit Message Conventions
        • Github Collaborators
        • CI/CD with Github Actions
        • Advanced Git Commands
      • FAQ
    • Telegram Bot
      • Creating a TeleBot
      • API Calls
      • Telebot Basics
      • Integrating API's
    • Relational Database
      • Database Overview
      • Database Design
      • Entity Relationship Diagram
      • SQL Basics & PostgreSQL
    • TypeScript
      • Types and Interfaces
      • Utility Types
      • Typing Component Props, Events, and Hooks
      • Why You Should Avoid Using any (and What to Do Instead)
      • TypeScript Tricks You’ll Use All the Time in React
Powered by GitBook
On this page
  • Debugging Github Actions
  • Conditional steps
  • Adding environment variables
  • Matrix strategies
Edit on GitHub
Export as PDF
  1. Hackerschool
  2. CI/CD with Github Actions

Cookbook

PreviousReusable workflowsNextLightning Git

Last updated 2 months ago

These are some additional recipes you can implement in Github Actions!

Debugging Github Actions

Given that steps in a job can be a script, you can actually perform logging as steps in a job:

- name: Logging
  run: |
    echo ${{ github.repository }}
    echo 'Hello!'

These will add a step to the job that logs these echos.

Conditional steps

You can also run steps based on certain conditions (using ). This is particularly useful when you want to only run a step when certain conditions are met.

- name: Only run on Windows
  if: ${{ runner.os == 'windows' }}
  run: |
    Write-Output "test output"

The above step only runs when the runner OS is Windows.

It is very important to note that there are several limitations to what expressions might work in the if key. These are dependent on what contexts are available to each part of a step. More information about contexts can be found and the contexts available to if are: github, needs, vars, inputs

Adding environment variables

Given that virtual machine runners run an OS, you will have access to environment variables from within the job through the env context. To add to the env context, you can use a step:

- name: Export environment variables
  run: |
    echo "START=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV

The above exports a new environment variable START into env . This can be then accessed via ${{ env.START }}.

Matrix strategies

Suppose that you want to verify that a set of changes are not susceptible to backward compatibility issues in a Node.js environment (version 20), while ensuring that the latest Node.js version is supported as well (version 23).

You can actually use matrix strategies to verify this information by running the same job across different parameters.

jobs:
  example_matrix:
    strategy:
      matrix:
        version: [20, 23]
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.version }}

So using the above, we are able to then run the same job example_matrix twice with two different node versions: 20 and 23.

expressions
here