GitHub Actions

From Christoph's Personal Wiki
Revision as of 23:08, 26 September 2022 by Christoph (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

GitHub Actions is a service provided by GitHub that allows building continuous integration and continuous deployment (CI/CD) pipelines for testing, releasing, and deploying software without the use of third-party websites/platforms.

Introduction

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository or deploy merged pull requests to production.

There are different components of GitHub Actions:

Workflows 
A workflow is a configurable automated process that will run one or more jobs.
Events 
An event is a specific activity in a repository that triggers a workflow run. For example, activity can originate from GitHub when someone creates a pull request, opens an issue, or pushes a commit to a repository.
Jobs 
A job is a set of steps in a workflow
Actions 
Performs frequently repeated task. An action can for example pull your git repository from GitHub,
Runners 
A runner is a server that runs your workflows when they’re triggered.

Examples

Basic

$ cat .github/workflows/basic.yaml

name: Shell Commands 

on: [push]

jobs:
  run-shell-commands:
    runs-on: ubuntu-latest
    steps: 
      - name: echo a string
        run: echo "Hello, World!"
      - name: multiline script 
        run: |
          node -v 
          npm -v
      - name: python command 
        run: |
          import platform 
          print
          (platform.processor())
        shell: python
  • Using the GitHub CLI:
$ gh workflow view
? Select a workflow Shell Commands (simple.yaml)
Shell Commands - simple.yaml
ID: 13613098

Total runs 1
Recent runs
✓  initial commit of .github/workflows/simple.yaml  Shell Commands  master  push  1280462255

To see more runs for this workflow, try: gh run list --workflow simple.yaml
To see the YAML for this workflow, try: gh workflow view simple.yaml --yaml

$ gh workflow view simple.yaml --yaml
Shell Commands - simple.yaml
ID: 13613098

name: Shell Commands 

on: [push]

jobs:
  run-shell-command:
    runs-on: ubuntu-latest
    steps: 
      - name: echo a string
        run: echo "Hello World"
      - name: multiline script 
        run: |
           node -v 
           npm -v           
      - name: python Command 
        run: |
          import platform 
          print
          (platform.processor())          
        shell: python


$ gh run list --workflow simple.yaml
STATUS  NAME                                             WORKFLOW        BRANCH  EVENT  ID          ELAPSED  AGE
✓       initial commit of .github/workflows/simple.yaml  Shell Commands  master  push   1280462255  15s      15d

For details on a run, try: gh run view <run-id>

$ gh run view 1280462255

✓ master Shell Commands · 1280462255
Triggered via push about 16 days ago

JOBS
✓ run-shell-command in 1s (ID 3726651254)

For more information about a job, try: gh run view --job=<job-id>
View this run on GitHub: https://github.com/christophchamp/github-actions/actions/runs/1280462255

External links

GitHub CLI