Skip to content

Commit 385c6e8

Browse files
authored
Use GitOps Configuration File (#15)
## 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
1 parent 8be5c43 commit 385c6e8

File tree

20 files changed

+480
-213
lines changed

20 files changed

+480
-213
lines changed

.github/workflows/feature-branch.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1+
name: Feature branch
12
on:
2-
workflow_dispatch:
33
pull_request:
44
branches: [ main ]
55
types: [opened, synchronize, reopened]
66

77
jobs:
8-
build:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
with:
13-
ref: ${{ github.ref }}
14-
fetch-depth: 1
15-
16-
- uses: cloudposse/[email protected]
17-
with:
18-
atmos-version: "latest"
19-
20-
- uses: dcarbone/[email protected]
21-
with:
22-
version: "1.6"
23-
24-
- name: Run Tests
25-
run: ./test/run.sh
8+
perform:
9+
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/feature-branch.yml@main
10+
with:
11+
organization: "${{ github.event.repository.owner.login }}"
12+
repository: "${{ github.event.repository.name }}"
13+
ref: "${{ github.event.pull_request.head.ref }}"
14+
secrets:
15+
github-private-actions-pat: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"

.github/workflows/main-branch.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Main branch
2+
on:
3+
push:
4+
branches: [ main ]
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
perform:
11+
uses: cloudposse/github-actions-workflows-github-action-composite/.github/workflows/main-branch.yml@main
12+
with:
13+
organization: "${{ github.event.repository.owner.login }}"
14+
repository: "${{ github.event.repository.name }}"
15+
secrets:
16+
github-private-actions-pat: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Test select components with 2 levels of nested matrices
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup
15+
run: echo "Do setup"
16+
17+
test:
18+
runs-on: ubuntu-latest
19+
needs: [setup]
20+
continue-on-error: true
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
- uses: ./
25+
id: current
26+
with:
27+
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
28+
select-filter: '.settings.github.actions_enabled // false'
29+
nested-matrices-count: '2'
30+
31+
outputs:
32+
selected-components: "${{ steps.current.outputs.selected-components }}"
33+
matrix: "${{ steps.current.outputs.matrix }}"
34+
35+
assert:
36+
runs-on: ubuntu-latest
37+
needs: [test]
38+
steps:
39+
- uses: nick-fields/assert-action@v1
40+
with:
41+
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"}]'
42+
actual: "${{ needs.test.outputs.selected-components }}"
43+
44+
- uses: nick-fields/assert-action@v1
45+
with:
46+
expected: '{"include":['
47+
actual: "${{ needs.test.outputs.matrix }}"
48+
comparison: contains
49+
50+
- uses: nick-fields/assert-action@v1
51+
with:
52+
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\"}]}"}]}'
53+
actual: "${{ needs.test.outputs.matrix }}"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test select components with 3 levels of nested matrices
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup
15+
run: echo "Do setup"
16+
17+
test:
18+
runs-on: ubuntu-latest
19+
needs: [setup]
20+
continue-on-error: true
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- uses: ./
26+
id: current
27+
with:
28+
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
29+
select-filter: '.settings.github.actions_enabled // false'
30+
nested-matrices-count: '3'
31+
32+
outputs:
33+
selected-components: "${{ steps.current.outputs.selected-components }}"
34+
matrix: "${{ steps.current.outputs.matrix }}"
35+
36+
assert:
37+
runs-on: ubuntu-latest
38+
needs: [test]
39+
steps:
40+
- uses: nick-fields/assert-action@v1
41+
with:
42+
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"}]'
43+
actual: "${{ needs.test.outputs.selected-components }}"
44+
45+
- uses: nick-fields/assert-action@v1
46+
with:
47+
expected: '{"include":['
48+
actual: "${{ needs.test.outputs.matrix }}"
49+
comparison: contains
50+
51+
- uses: nick-fields/assert-action@v1
52+
with:
53+
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\\\"}]}\"}]}"}]}'
54+
actual: "${{ needs.test.outputs.matrix }}"

.github/workflows/test-positive.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Test select components
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup
15+
run: echo "Do setup"
16+
17+
test:
18+
runs-on: ubuntu-latest
19+
needs: [setup]
20+
continue-on-error: true
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- uses: ./
26+
id: current
27+
with:
28+
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
29+
30+
outputs:
31+
selected-components: "${{ steps.current.outputs.selected-components }}"
32+
matrix: "${{ steps.current.outputs.matrix }}"
33+
34+
assert:
35+
runs-on: ubuntu-latest
36+
needs: [test]
37+
steps:
38+
- uses: nick-fields/assert-action@v1
39+
with:
40+
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"}]'
41+
actual: "${{ needs.test.outputs.selected-components }}"
42+
43+
- uses: nick-fields/assert-action@v1
44+
with:
45+
expected: '{"include":['
46+
actual: "${{ needs.test.outputs.matrix }}"
47+
comparison: contains
48+
49+
- uses: nick-fields/assert-action@v1
50+
with:
51+
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\"}]}"}]}'
52+
actual: "${{ needs.test.outputs.matrix }}"

0 commit comments

Comments
 (0)