Coder Social home page Coder Social logo

sombriks / gh-actions-playground Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 300 KB

small examples of interesting github actions combinations

Home Page: https://sombriks.com/blog/0061-github-actions-recipes/

License: MIT License

cicd examples ghactions pipelines workflows

gh-actions-playground's Introduction

My gh-actions playground

Small examples of interesting GitHub actions combinations.

How to run this playground

Most workflows where intentionally left with workflow_dispatch so they don't run by accident on every commit. Not as if it was a big issue, since they do mostly nothing by design.

But you can also run them using the act command line tool, which emulates the GitHub actions environment in a quite near the real thing way.

So, the three big ways to run a workflow:

  • Visit the actions page and run them by hand
  • Use the GitHub CLI: gh workflow run .github/workflow/00-hello-world.yml
  • Use act: act -W .github/workflows/00-hello-world.yml

Overview

GitHub Actions is what happens when yaml and bash decide to have a child.

The workflow files are used to common integration routines: run tests, check the quality of code, perform any chore that can be automatized, scripted.

Workflow file syntax

Each workflow file must define:

  • name (unique across all workflows)
  • on (event)
  • jobs (actual work)

Events

What could possibly trigger an workflow?

  • You hit a button
  • A git push or something
  • Another workflow

More possibilities here.

Jobs

  • Give cool names to your jobs, not just build
  • One workflow can house several jobs
  • Jobs will run in parallel unless you do something about it
    • make jobs needs other jobs

More details here.

image-manual-dispatch.png

image-on-push.png

  • Remember, runs in parallel!
  • Pretty much like two distinct workflows, but sharing rent of a workflow file

two-jobs.png

  • Make sure the second needs the first

job-needs.png

use-another-workflow.png

  • Both workflow_call and workflow_dispatch can receive inputs
  • Use inputs inside the steps inside jobs

job-input.png

  • You can define outputs values so other jobs can check on
  • For dynamic outputs check the $GITHUB_OUTPUT variable usage

job-output.png

  • The repository itself can contribute with custom variables
  • Use GitHub CLI to list, set or remove repository variables
  • If using act, create a .vars file to define variables
  • With act there is also a .env file but we talk about it later
# ~/github/gh-actions-playground/.vars
X="some value from vars"

repository-variables.png

08 - secrets

  • Very useful to interact with the world outside the repo
  • Define secrets via web console settings
  • Or use GitHub CLI to create them, pretty handy!
  • With act, just put it inside a .secrets file!
  • Note: secret values are not echoed on logs
# ~/github/gh-actions-playground/.secrets
X=10
MY_SECRET="not telling you!"
[sombriks@thanatos gh-actions-playground](main)$ gh secret set X
? Paste your secret **

โœ“ Set Actions secret X for sombriks/gh-actions-playground

09 - steps

  • Simplest step is a run command
  • Complex ones uses external actions from marketplace
  • Give proper names for your steps

More details of what is possible here

10 / 11 - define outputs for reusable workflows

More info here and here.

12 - create a commit

13 - create comments

Noteworthy 3rd party actions

There's much, much more!

Writing good CI/CD pipelines

  • Run tests
  • Publish packages or images
  • For GitOps, update desired state on IaC manifests files

Conclusion

This playground is intended to be simple, educational.

It's up to you combine the techniques sampled here to build real things.

gh-actions-playground's People

Watchers

 avatar  avatar

gh-actions-playground's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.