Coder Social home page Coder Social logo

terramate-github-actions-example's Introduction

terramate-github-actions-example

this repository is for showcasing how do i generate github actions workflow files via terramate. there are always tradeoffs but for me it is more readable and configurable than a simple yaml :-) take what you need and could help on your journey!

structure

.
├── imports                        # importing workflow generation logic from here
│   ├── called.tm.hcl
│   ├── main.tm.hcl
│   └── workflow_dispatch.tm.hcl
├── stacks                         # dummy environments for showcasing
│   ├── dev
│   │   ├── file
│   │   └── stack.tm.hcl
│   ├── prod
│   │   ├── file
│   │   └── stack.tm.hcl
│   └── staging
│       ├── file
│       └── stack.tm.hcl
├── workflows                     # generated workflow files
│   ├── called.yaml
│   ├── main.yaml
│   └── workflow_dispatch.yaml
├── LICENSE
├── README.md
├── globals.tm.hcl                # configuration
└── terramate.tm.hcl

config

globals "workflows" {
  # default runner image
  runs-on = ["ubuntu-latest"]

  # pin actions by commit hashes instead of tags: https://blog.rafaelgss.dev/why-you-should-pin-actions-by-commit-hash
  versions = {
    checkout   = "b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 https://github.com/actions/checkout
    alls-green = "05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe" # v1.2.2 https://github.com/re-actors/alls-green
  }
}

globals "repository" {
  # which environments to manage
  environments = ["dev", "staging", "prod"]
  # run workflows on all environments regardless of change
  # reducing the number of jobs based on changes optimises github actions runtime
  always_run = false
  # toggle chaotic good example for workflow generation (json > yaml)
  chaotic_good = false
}

workflows

workflow dispatch

a simple workflow triggered by the workflow_dispatch event. it has only one step greeting the world!

main

this workflow optionally (global.repository.always_run) checks whether there are changes accross the managed environments (global.repository.environments) and generates the input of the matrix job which calls the reusable workflow called.yaml, then waits for all jobs to be finished to give a green light at the end. all-passed job can be set as required status check to keep the dynamic matrix at bay.

called

this workflow aims to showcase how to do specific tasks on specific environments as a matrix.

example pull requests

  • change outside of environments #1
  • always run #2
  • change on dev and staging #3
  • unmanage prod #4
  • fail dev #5
  • fail staging && always run #6
  • chaotic good #7

terramate

for more cool stuff, check out terramate-io

terramate-github-actions-example's People

Contributors

waxb avatar

Watchers

 avatar

terramate-github-actions-example'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.