Skip to content

Instantly share code, notes, and snippets.

@dgk
Last active September 15, 2023 11:04
Show Gist options
  • Save dgk/c9bd9ec3c07ee808fdea2cfc7000caa5 to your computer and use it in GitHub Desktop.
Save dgk/c9bd9ec3c07ee808fdea2cfc7000caa5 to your computer and use it in GitHub Desktop.
env matrix for digger
projects:
- name: dev
dir: envs/dev
workflow: dev
include_patterns:
- ../../modules/**
- name: stage
dir: envs/stage
workflow: stage
include_patterns:
- ../../modules/**
- name: prod
dir: envs/prod
workflow: prod
include_patterns:
- ../../modules/**
workflows:
dev:
env_vars:
state:
- name: GCP_CREDENTIALS
value_from: DEV_GCP_CREDENTIALS
commands:
- name: GCP_CREDENTIALS
value_from: DEV_GCP_CREDENTIALS
stage:
env_vars:
state:
- name: GCP_CREDENTIALS
value_from: STAGE_GCP_CREDENTIALS
commands:
- name: GCP_CREDENTIALS
value_from: STAGE_GCP_CREDENTIALS
prod:
env_vars:
state:
- name: GCP_CREDENTIALS
value_from: PROD_GCP_CREDENTIALS
commands:
- name: GCP_CREDENTIALS
value_from: PROD_GCP_CREDENTIALS
name: Digger
on:
workflow_call:
inputs:
env:
required: true
type: string
secrets:
GCP_CREDENTIALS:
required: true
jobs:
digger:
name: Digger run on ${{ inputs.env }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: ubuntu-latest
environment: ${{ inputs.env }}
steps:
- uses: actions/checkout@v3
with:
clean: false
ref: ${{ fromJSON(format('[null, "refs/pull/{0}/merge"]', github.event.issue.number))[github.event_name == 'issue_comment'] }}
- name: Get diff
uses: technote-space/get-diff-action@v6
id: diff
with:
SET_ENV_NAME: ''
SET_ENV_NAME_FILTERED_DIFF: ''
SET_ENV_NAME_MATCHED_FILES: ''
DIFF_FILTER: 'AMRCD'
MINIMATCH_OPTION_DOT: true
PATTERNS: |
modules/**
envs/${{ inputs.env }}/**
- name: digger run on ${{ inputs.env }}
if: ${{ steps.diff.outputs.count > 0 }}
uses: diggerhq/digger@v0.1.31
with:
configure-checkout: false
setup-terraform: true
terraform-version: v1.2.4
setup-google-cloud: true
google-auth-credentials: ${{ secrets.GCP_CREDENTIALS }}
env:
LOCK_PROVIDER: gcp
GITHUB_CONTEXT: ${{ toJson(github) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOOGLE_STORAGE_BUCKET: devops-expirements-lock
name: Matrix
on:
pull_request:
branches:
- master
types:
- closed
- opened
- reopened
- synchronize
issue_comment:
types:
- created
if: contains(github.event.comment.body, 'digger')
workflow_dispatch:
jobs:
env:
strategy:
max-parallel: 1
matrix:
env:
- dev
- stage
- prod
uses: ./.github/workflows/digger.yml
with:
env: ${{ matrix.env }}
secrets:
GCP_CREDENTIALS: ${{ secrets[format('{0}_GCP_CREDENTIALS', matrix.env)] }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment