Skip to content

Commit

Permalink
Consolidate shared workflows (#89)
Browse files Browse the repository at this point in the history
## what
* Consolidate shared workflows

## why
* Reduce reusable workflows nested levels

## references
* DEV-400: Move shared workflows into .github repo with shared- prefix
  • Loading branch information
goruha authored May 16, 2024
1 parent aef3a53 commit 2fc1e34
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/shared-github-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "Shared github action workflow"

on:
workflow_call:
inputs:
organization:
description: "Repository owner organization (ex. acme for repo acme/example)"
required: false
default: ${{ github.event.repository.owner.login }}
type: string
repository:
description: "Repository name (ex. example for repo acme/example)"
required: false
default: ${{ github.event.repository.name }}
type: string
ref:
description: "The fully-formed ref of the branch or tag that triggered the workflow run"
required: false
default: ${{ github.ref }}
type: string
tests-prefix:
description: "Workflows file name prefix to run as tests"
required: false
type: string
default: 'test-*'
publish:
description: "Whether to publish a new release immediately"
required: false
default: "true"
type: string
runs-on:
description: "Overrides job runs-on setting (json-encoded list)"
type: string
required: false
default: '["ubuntu-latest"]'

permissions:
contents: write
actions: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
ci-readme:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-readme.yml@shared-workflows
name: "Readme"
if: ${{ github.event_name == 'push' }}
with:
runs-on: ${{ inputs.runs-on }}
secrets: inherit

ci-gha:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-github-action.yml@main
name: "CI"
with:
organization: ${{ inputs.organization }}
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
tests-prefix: ${{ inputs.tests-prefix }}

ci:
runs-on: ${{ fromJSON(inputs.runs-on) }}
if: ${{ always() }}
steps:
- run: |
echo '${{ toJSON(needs) }}' # easier debug
! ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
needs: [ ci-gha, ci-readme ]

release:
needs: [ ci ]
name: "Release"
if: ${{ github.event_name == 'push' }}
uses: cloudposse/.github/.github/workflows/shared-auto-release.yml@main
with:
publish: ${{ inputs.publish }}
secrets: inherit
26 changes: 26 additions & 0 deletions .github/workflows/shared-terraform-chatops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Shared Terraform ChatOps"

on:
workflow_call:
inputs:
runs-on:
description: "Overrides job runs-on setting (json-encoded list)"
type: string
required: false
default: '["ubuntu-latest"]'
secrets:
github_access_token:
description: "GitHub API token"
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
ci-terraform-chatops:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-terraform-chatops.yml@main
with:
runs-on: ${{ inputs.runs-on }}
secrets:
github_access_token: ${{ secrets.github_access_token }}
70 changes: 70 additions & 0 deletions .github/workflows/shared-terraform-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "Shared terraform module"
on:
workflow_call:
inputs:
runs-on:
description: "Overrides job runs-on setting (json-encoded list)"
type: string
required: false
default: '["ubuntu-latest"]'
secrets:
REPO_ACCESS_TOKEN:
description: "GitHub API token"
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
ci-terraform:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-terraform.yml@shared-workflows
name: "CI"
with:
# Workaround for https://github.com/community/community/discussions/9099
# We should switch to nofilter once it's fixed
filter-mode: ${{ github.event_name == 'pull_request' && 'diff_context' || 'nofilter' }}
suggestions: "${{ github.event_name == 'pull_request' }}"
runs-on: ${{ inputs.runs-on }}

ci-readme:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-readme.yml@shared-workflows
name: "Readme"
if: ${{ github.event_name == 'push' }}
with:
runs-on: ${{ inputs.runs-on }}
secrets: inherit

ci-codeowners:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-codeowners.yml@shared-workflows
name: "CI"
with:
is_fork: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
runs-on: ${{ inputs.runs-on }}
secrets:
github_access_token: ${{ secrets.REPO_ACCESS_TOKEN }}

ci-labels:
runs-on: ${{ fromJSON(inputs.runs-on) }}
name: "CI / Labels Validate"
steps:
- uses: cloudposse/github-action-release-label-validator@v1

ci:
runs-on: ${{ fromJSON(inputs.runs-on) }}
if: ${{ always() }}
steps:
- run: |
echo '${{ toJSON(needs) }}' # easier debug
! ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
needs: [ ci-terraform, ci-readme, ci-codeowners, ci-labels ]

auto-release:
name: "Release"
needs: [ci]
uses: cloudposse/.github/.github/workflows/shared-auto-release.yml@shared-workflows
if: ${{ github.event_name == 'push' }}
with:
runs-on: ${{ inputs.runs-on }}
publish: true
secrets: inherit
32 changes: 32 additions & 0 deletions .github/workflows/shared-terraform-scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Shared terraform scheduled"

on:
workflow_call:
inputs:
runs-on:
description: "Overrides job runs-on setting (json-encoded list)"
type: string
required: false
default: '["ubuntu-latest"]'
secrets:
REPO_ACCESS_TOKEN:
description: "GitHub API token"
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
context:
uses: cloudposse/github-actions-workflows/.github/workflows/scheduled-context.yml@main
with:
runs-on: ${{ inputs.runs-on }}
secrets:
github_access_token: ${{ secrets.REPO_ACCESS_TOKEN }}

readme:
uses: cloudposse/github-actions-workflows/.github/workflows/scheduled-readme.yml@main
with:
runs-on: ${{ inputs.runs-on }}
secrets: inherit

0 comments on commit 2fc1e34

Please sign in to comment.