GitHub Actions Cheatsheet - Standard structure and a List of most useful actions

A bit about on common GitHub Actions and their structure.

Page content

GitHub Actions is an automation and CI/CD platform within GitHub, used to build, test, and deploy your code based on events like pushes, pull requests, or on a schedule.

In addition to standard GitHub you can use GitHub Actions in a self-hosted Gitea server.

github actions flow

This summary covers the GitHub actions structure, short description and the most common actions used across open source and commercial workflows. Actions span official, community, and third-party tools, supporting automation from builds and tests to deployment, release management, QA, and notifications.

Basic Configuration Structure

GitHub Actions Workflows are defined in YAML files located in the .github/workflows directory within the repository.

name: Workflow Name
on:
  push:
    branches: [ main ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Run tests
        run: npm test
  • The on block specifies trigger events.
  • Each job runs on its own runner.
  • steps can run shell commands or call re-usable actions.

Core Workflow Components

Component Description
Workflow Automated process (YAML) triggered by an event
Event Activity that triggers workflow (push, pull_request, etc.)
Job Series of steps executed on a runner, can run sequentially or in parallel
Step Each command or action in a job
Runner VM or container where jobs are executed
Action Reusable extension/add-on encapsulating a task

Trigger Events

  • push
  • pull_request
  • schedule (using cron syntax)
  • workflow_dispatch (manual trigger, allows input parameters)
  • release, issue, etc.

Example:

on:
  push:
    branches: [ main ]
  workflow_dispatch:
    inputs:
      environment:
        description: 'Deployment Environment'
        required: true
        default: 'production'
        type: string

Useful Built-in Actions

Action Purpose Common Parameters
actions/checkout Check out repository code ref, token, submodules, persist-credentials
actions/setup-node Set up Node.js environment node-version, cache, architecture, check-latest
actions/setup-python Set up Python python-version, architecture
actions/cache Cache dependencies path, key, restore-keys
docker/build-push-action Build & push Docker images context, file, platforms, tags, push, build-args
actions/upload-artifact Upload build artifacts name, path, if-no-files-found
actions/download-artifact Download artifacts name, path
github/email-actions Send email notifications to, subject, content, attachments
peter-evans/create-pull-request Create PRs via workflow branch, title, body, labels, base
actions/github-script Run arbitrary JavaScript in your workflow script, github-token

Action Parameters

General Parameters for Any Action Call:

- name: Some Action or Step
  uses: owner/repo@ref
  with:
    param1: value
    param2: value
  env:
    ENV_VAR: value
  if: ${{ condition }}
  run: command_to_run
  shell: bash|pwsh|python|sh
  continue-on-error: true|false
  • with: arguments passed to the action (see action’s docs for all options)
  • env: environment variables for the step
  • if: conditional execution
  • run: shell commands (if not using an action)
  • shell: shell used to run the step
  • continue-on-error: proceed even if the step fails

Defining Custom Action Inputs

In your action metadata (action.yml):

inputs:
  example-input:
    description: 'An example input'
    required: false
    default: 'default-value'

When used in a workflow:

- uses: my/action@v1
  with:
    example-input: 'custom-value'

Accessed as environment variable INPUT_EXAMPLE_INPUT when the action runs.

Example: Workflow with Manual Parameters

name: Deploy
on:
  workflow_dispatch:
    inputs:
      environment:
        description: 'Deployment Environment'
        required: true
        default: 'production'
        type: string
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Deploy to environment
        run: echo "Deploying to ${{ github.event.inputs.environment }}"

Action Marketplace

  • Thousands of reusable actions are available in the GitHub Marketplace.
  • Categories include: cloud deployments, notification tools, test frameworks, code analysis, and more.
  • Explore: actions/checkout, actions/setup-node, docker/build-push-action, actions/cache, actions/upload-artifact, and many others.

Quick Tips

  • Place workflow files in .github/workflows.
  • Use workflow_dispatch with inputs for manual and parameterized runs.
  • Use cache action to speed up dependency installs.
  • Use job matrix to test multiple OS/runtime versions.
  • Use secrets for sensitive data, referenced as ${{ secrets.SECRET_NAME }}.

This cheatsheet covers the essentials of using, configuring, and extending GitHub Actions for automation, CI/CD, and more. For more details and updates, always check the official GitHub documentation and action repositories.

Common GitHub Actions

Here’s a practical list of frequently used GitHub Actions that help automate CI/CD, testing, building, deployment, and workflow tasks:

Core Official Actions

Action Purpose Key Example Parameters
actions/checkout Checks out repository code ref, submodules
actions/setup-node Set up Node.js environment node-version, cache
actions/setup-python Set up Python environment python-version
actions/setup-java Set up Java JDK distribution, java-version
actions/cache Caches dependencies and build outputs path, key, restore-keys
actions/upload-artifact Uploads build artifacts name, path
actions/download-artifact Downloads artifacts from workflow name, path
actions/github-script Run JavaScript using GitHub context and API script
actions/create-release Create a GitHub release tag_name, release_name
actions/upload-release-asset Upload assets to a release upload_url, asset_path
actions/labeler Automatically applies labels to issues/PRs repo-token, configuration-path
Action Purpose
docker/build-push-action Build and push Docker images
actions/setup-go Set up Go environment
super-linter/super-linter Universal automated code linting
trufflesecurity/trufflehog Scan for secrets and credentials
peaceiris/actions-gh-pages Deploy static sites to GitHub Pages
JamesIves/github-pages-deploy-action Deploy projects to GitHub Pages
peter-evans/create-pull-request Create pull requests automatically
softprops/action-gh-release Create and upload GitHub Releases
ad-m/github-push-action Push changes back to GitHub repository
actions/setup-dotnet Set up .NET SDK
azure/login Authenticate to Azure
google-github-actions/auth Authenticate to Google Cloud

Testing, QA, and Reporting Actions

Action Purpose
actions/setup-ruby Set up Ruby environment
codecov/codecov-action Upload code coverage reports to Codecov
coverallsapp/github-action Upload coverage results to Coveralls
dorny/test-reporter Attach test results to GitHub Checks
stefanzweifel/git-auto-commit-action Auto-commit and push file changes

Deployment & Notification Actions

Action Purpose
appleboy/scp-action Upload files using SCP
SamKirkland/FTP-Deploy-Action Deploy files through FTP/FTPS
cypress-io/github-action Run Cypress end-to-end tests
slackapi/slack-github-action Send messages to Slack
dawidd6/action-send-mail Send emails during workflow runs

Utility & Workflow Management

Action Purpose
peter-evans/repository-dispatch Triggers external repository workflows
fregante/setup-git-user Set Git user credentials for commits
andymckay/labeler Labels issues and PRs based on paths
actions/configure-pages Configure publishing to GitHub Pages
EndBug/add-and-commit Add & commit files within a workflow
dangoslen/changelog-enforcer Checks if a changelog was updated for PRs

How to Find More

There is a lot of GurHub Actions that enable workflow automation such as automated testing, deployment to production, notifications, and integrations with other services. The GitHub Marketplace lists thousands of actions across categories like testing, security, deployment, notifications, code quality, and integrations. Curated lists such as “Awesome Actions” are also great for inspiration and discovery.