Skip to content

Commit

Permalink
Use GitOps Configuration File (#15)
Browse files Browse the repository at this point in the history
## what
* Use a configuration file instead of passing all parameters as inputs

## why 
* Makes it easier in reusable workflows to reuse actions without needing to edit workflows themselves
* Separate business logic from configuration
  • Loading branch information
goruha authored Dec 15, 2023
1 parent 8be5c43 commit 385c6e8
Show file tree
Hide file tree
Showing 20 changed files with 480 additions and 213 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/feature-branch.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
name: Feature branch
on:
workflow_dispatch:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 1

- uses: cloudposse/[email protected]
with:
atmos-version: "latest"

- uses: dcarbone/[email protected]
with:
version: "1.6"

- name: Run Tests
run: ./test/run.sh
perform:
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/feature-branch.yml@main
with:
organization: "${{ github.event.repository.owner.login }}"
repository: "${{ github.event.repository.name }}"
ref: "${{ github.event.pull_request.head.ref }}"
secrets:
github-private-actions-pat: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"
16 changes: 16 additions & 0 deletions .github/workflows/main-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Main branch
on:
push:
branches: [ main ]

permissions:
contents: write

jobs:
perform:
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/main-branch.yml@main
with:
organization: "${{ github.event.repository.owner.login }}"
repository: "${{ github.event.repository.name }}"
secrets:
github-private-actions-pat: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"
53 changes: 53 additions & 0 deletions .github/workflows/test-matrix-2-levels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test select components with 2 levels of nested matrices
on:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch: {}

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"

test:
runs-on: ubuntu-latest
needs: [setup]
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./
id: current
with:
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
select-filter: '.settings.github.actions_enabled // false'
nested-matrices-count: '2'

outputs:
selected-components: "${{ steps.current.outputs.selected-components }}"
matrix: "${{ steps.current.outputs.matrix }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: '[{"component":"test-2","stack":"core-ue2-auto","stack_slug":"core-ue2-auto-test-2"},{"component":"test-4","stack":"plat-ue2-dev","stack_slug":"plat-ue2-dev-test-4"},{"component":"test-5","stack":"plat-ue2-sandbox","stack_slug":"plat-ue2-sandbox-test-5"}]'
actual: "${{ needs.test.outputs.selected-components }}"

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":['
actual: "${{ needs.test.outputs.matrix }}"
comparison: contains

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":[{"name":"core-auto","items":"{\"include\":[{\"component\":\"test-2\",\"stack\":\"core-ue2-auto\",\"stack_slug\":\"core-ue2-auto-test-2\"}]}"},{"name":"plat-dev","items":"{\"include\":[{\"component\":\"test-4\",\"stack\":\"plat-ue2-dev\",\"stack_slug\":\"plat-ue2-dev-test-4\"}]}"},{"name":"plat-sandbox","items":"{\"include\":[{\"component\":\"test-5\",\"stack\":\"plat-ue2-sandbox\",\"stack_slug\":\"plat-ue2-sandbox-test-5\"}]}"}]}'
actual: "${{ needs.test.outputs.matrix }}"
54 changes: 54 additions & 0 deletions .github/workflows/test-matrix-3-levels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test select components with 3 levels of nested matrices
on:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch: {}

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"

test:
runs-on: ubuntu-latest
needs: [setup]
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: ./
id: current
with:
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
select-filter: '.settings.github.actions_enabled // false'
nested-matrices-count: '3'

outputs:
selected-components: "${{ steps.current.outputs.selected-components }}"
matrix: "${{ steps.current.outputs.matrix }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: '[{"component":"test-2","stack":"core-ue2-auto","stack_slug":"core-ue2-auto-test-2"},{"component":"test-4","stack":"plat-ue2-dev","stack_slug":"plat-ue2-dev-test-4"},{"component":"test-5","stack":"plat-ue2-sandbox","stack_slug":"plat-ue2-sandbox-test-5"}]'
actual: "${{ needs.test.outputs.selected-components }}"

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":['
actual: "${{ needs.test.outputs.matrix }}"
comparison: contains

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":[{"name":"core-auto","items":"{\"include\":[{\"name\":\"core-ue2-auto-test-2 - core-ue2-auto-test-2\",\"items\":\"{\\\"include\\\":[{\\\"component\\\":\\\"test-2\\\",\\\"stack\\\":\\\"core-ue2-auto\\\",\\\"stack_slug\\\":\\\"core-ue2-auto-test-2\\\"}]}\"}]}"},{"name":"plat-dev","items":"{\"include\":[{\"name\":\"plat-ue2-dev-test-4 - plat-ue2-dev-test-4\",\"items\":\"{\\\"include\\\":[{\\\"component\\\":\\\"test-4\\\",\\\"stack\\\":\\\"plat-ue2-dev\\\",\\\"stack_slug\\\":\\\"plat-ue2-dev-test-4\\\"}]}\"}]}"},{"name":"plat-sandbox","items":"{\"include\":[{\"name\":\"plat-ue2-sandbox-test-5 - plat-ue2-sandbox-test-5\",\"items\":\"{\\\"include\\\":[{\\\"component\\\":\\\"test-5\\\",\\\"stack\\\":\\\"plat-ue2-sandbox\\\",\\\"stack_slug\\\":\\\"plat-ue2-sandbox-test-5\\\"}]}\"}]}"}]}'
actual: "${{ needs.test.outputs.matrix }}"
52 changes: 52 additions & 0 deletions .github/workflows/test-positive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test select components
on:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch: {}

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"

test:
runs-on: ubuntu-latest
needs: [setup]
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: ./
id: current
with:
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"

outputs:
selected-components: "${{ steps.current.outputs.selected-components }}"
matrix: "${{ steps.current.outputs.matrix }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: '[{"component":"test-1","stack":"core-ue2-auto","stack_slug":"core-ue2-auto-test-1"},{"component":"test-2","stack":"core-ue2-auto","stack_slug":"core-ue2-auto-test-2"},{"component":"test-3","stack":"plat-ue2-dev","stack_slug":"plat-ue2-dev-test-3"},{"component":"test-4","stack":"plat-ue2-dev","stack_slug":"plat-ue2-dev-test-4"},{"component":"test-5","stack":"plat-ue2-sandbox","stack_slug":"plat-ue2-sandbox-test-5"}]'
actual: "${{ needs.test.outputs.selected-components }}"

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":['
actual: "${{ needs.test.outputs.matrix }}"
comparison: contains

- uses: nick-fields/assert-action@v1
with:
expected: '{"include":[{"name":"core-auto","items":"{\"include\":[{\"component\":\"test-1\",\"stack\":\"core-ue2-auto\",\"stack_slug\":\"core-ue2-auto-test-1\"},{\"component\":\"test-2\",\"stack\":\"core-ue2-auto\",\"stack_slug\":\"core-ue2-auto-test-2\"}]}"},{"name":"plat-dev","items":"{\"include\":[{\"component\":\"test-3\",\"stack\":\"plat-ue2-dev\",\"stack_slug\":\"plat-ue2-dev-test-3\"},{\"component\":\"test-4\",\"stack\":\"plat-ue2-dev\",\"stack_slug\":\"plat-ue2-dev-test-4\"}]}"},{"name":"plat-sandbox","items":"{\"include\":[{\"component\":\"test-5\",\"stack\":\"plat-ue2-sandbox\",\"stack_slug\":\"plat-ue2-sandbox-test-5\"}]}"}]}'
actual: "${{ needs.test.outputs.matrix }}"
Loading

0 comments on commit 385c6e8

Please sign in to comment.