Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GitOps Configuration File #15

Merged
merged 32 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8a1920b
Incupsulate configs
goruha Dec 7, 2023
3f438b0
Incupsulate configs
goruha Dec 7, 2023
5c84dc8
Incupsulate configs
goruha Dec 7, 2023
7b990e9
Incupsulate configs
goruha Dec 7, 2023
8b6fc68
Incupsulate configs
goruha Dec 7, 2023
a8dace2
Incupsulate configs
goruha Dec 7, 2023
9d9b1b7
Incupsulate configs
goruha Dec 7, 2023
0983bd0
Incupsulate configs
goruha Dec 7, 2023
1a4eb7b
Incupsulate configs
goruha Dec 7, 2023
3cbcb63
Incupsulate configs
goruha Dec 7, 2023
b845864
Incupsulate configs
goruha Dec 7, 2023
b6bb80d
Incupsulate configs
goruha Dec 7, 2023
7f36807
Incupsulate configs
goruha Dec 7, 2023
97736d0
Incupsulate configs
goruha Dec 7, 2023
9a98c48
Incupsulate configs
goruha Dec 7, 2023
c0ca40f
Incupsulate configs
goruha Dec 7, 2023
a44b896
Incupsulate configs
goruha Dec 7, 2023
a0f6fe1
Use cloudposse action config
goruha Dec 7, 2023
2cac00d
Use extended matrix GHA
goruha Dec 8, 2023
8a1573f
Update README
goruha Dec 9, 2023
cc9475a
Update README
goruha Dec 9, 2023
ab834c0
Apply suggestions from code review
goruha Dec 12, 2023
4e47d34
Update README
goruha Dec 12, 2023
f9ca38a
Update action.yml
goruha Dec 13, 2023
a98b44e
Update README
goruha Dec 13, 2023
fa50260
Update README
goruha Dec 13, 2023
18e0fd7
Apply suggestions from code review
goruha Dec 14, 2023
bc4ddfe
Update README.yaml
goruha Dec 14, 2023
5188782
Update README.yaml
goruha Dec 14, 2023
9b7acb9
Update README
goruha Dec 14, 2023
5996298
Fix README
goruha Dec 15, 2023
9620610
Added README
goruha Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}"
61 changes: 59 additions & 2 deletions README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebuild with latest build-harness. this is using an older README template

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milldr done

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ Output of this action is a list of basic component information. For example:



### Config

The action expects the atmos gitops configuration file to be present in the repository in `./.github/config/atmos-gitops.yaml`.
The config should have the following structure:

```yaml
atmos-version: 1.45.3
atmos-config-path: ./rootfs/usr/local/etc/atmos/
terraform-state-bucket: cptest-core-ue2-auto-gitops
terraform-state-table: cptest-core-ue2-auto-gitops
terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-version: 1.5.2
aws-region: us-east-2
enable-infracost: false
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
```

### GitHub Actions Workflow Example

In following GitHub workflow example first job will filter components that have settings `github.actions_enabled: true` and then in following job `stack_slug` will be printed to stdout.
Expand Down Expand Up @@ -122,6 +142,41 @@ In following GitHub workflow example first job will filter components that have
echo "${{ matrix.stack_slug }}"
```

### Migrating from `v0` to `v1`

`v1` replace `jq-query` input with `selected-filter` variable and simplify the query.
Now you need to specify only part used in select function of `jq-query`.

`v1` moved variables from `inputs` to atmos gitops config path `./.github/config/atmos-gitops.yaml`

| name |
|--------------------------|
| `atmos-version` |
| `atmos-config-path` |


If you want the same behavior in `v1` as in`v0` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v1` inputs.

```yaml
- name: Selected Components
id: components
uses: cloudposse/github-action-atmos-terraform-select-components@v1
with:
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
select-filter: '.settings.github.actions_enabled // false'
```

same behaviour as

```yaml
- name: Selected Components
id: components
uses: cloudposse/github-action-atmos-terraform-select-components@v0
with:
atmos-config-path: "${{ github.workspace }}/rootfs/usr/local/etc/atmos/"
jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'
```




Expand Down Expand Up @@ -284,8 +339,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
### Contributors

<!-- markdownlint-disable -->
| [![Zinovii Dmytriv][zdmytriv_avatar]][zdmytriv_homepage]<br/>[Zinovii Dmytriv][zdmytriv_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Daniel Miller][milldr_avatar]][milldr_homepage]<br/>[Daniel Miller][milldr_homepage] |
|---|---|---|
| [![Zinovii Dmytriv][zdmytriv_avatar]][zdmytriv_homepage]<br/>[Zinovii Dmytriv][zdmytriv_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Daniel Miller][milldr_avatar]][milldr_homepage]<br/>[Daniel Miller][milldr_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] |
|---|---|---|---|
<!-- markdownlint-restore -->

[zdmytriv_homepage]: https://github.com/zdmytriv
Expand All @@ -294,6 +349,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
[milldr_homepage]: https://github.com/milldr
[milldr_avatar]: https://img.cloudposse.com/150x150/https://github.com/milldr.png
[goruha_homepage]: https://github.com/goruha
[goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png

[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
Expand Down
60 changes: 59 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ references:
url: "https://github.com/cloudposse/example-github-action-release-workflow"

usage: |
### Config

The action expects the atmos gitops configuration file to be present in the repository in `./.github/config/atmos-gitops.yaml`.
goruha marked this conversation as resolved.
Show resolved Hide resolved
The config should have the following structure:
goruha marked this conversation as resolved.
Show resolved Hide resolved

```yaml
atmos-version: 1.45.3
atmos-config-path: ./rootfs/usr/local/etc/atmos/
terraform-state-bucket: cptest-core-ue2-auto-gitops
terraform-state-table: cptest-core-ue2-auto-gitops
terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-version: 1.5.2
aws-region: us-east-2
enable-infracost: false
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
```

goruha marked this conversation as resolved.
Show resolved Hide resolved
### GitHub Actions Workflow Example

In following GitHub workflow example first job will filter components that have settings `github.actions_enabled: true` and then in following job `stack_slug` will be printed to stdout.
Expand Down Expand Up @@ -97,6 +117,42 @@ usage: |
echo "${{ matrix.stack_slug }}"
```

### Migrating from `v0` to `v1`

goruha marked this conversation as resolved.
Show resolved Hide resolved
`v1` replace `jq-query` input with `selected-filter` variable and simplify the query.
goruha marked this conversation as resolved.
Show resolved Hide resolved
Now you need to specify only part used in select function of `jq-query`.

`v1` moved variables from `inputs` to atmos gitops config path `./.github/config/atmos-gitops.yaml`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`v1` replace `jq-query` input with `selected-filter` variable and simplify the query.
Now you need to specify only part used in select function of `jq-query`.
`v1` moved variables from `inputs` to atmos gitops config path `./.github/config/atmos-gitops.yaml`
- `v1` replace `jq-query` input with `selected-filter` variable and simplify the query.
Now you need to specify only the part used inside of the `select(...)` function of the `jq-query`.
-`v1` moved parameters from the `inputs` to the Atmos GitOps config file, which defaults to `./.github/config/atmos-gitops.yaml`

goruha marked this conversation as resolved.
Show resolved Hide resolved

| name |
|--------------------------|
| `atmos-version` |
| `atmos-config-path` |


If you want the same behavior in `v1` as in`v0` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v1` inputs.
goruha marked this conversation as resolved.
Show resolved Hide resolved

```yaml
- name: Selected Components
id: components
uses: cloudposse/github-action-atmos-terraform-select-components@v1
with:
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
select-filter: '.settings.github.actions_enabled // false'
```

same behaviour as

```yaml
- name: Selected Components
id: components
uses: cloudposse/github-action-atmos-terraform-select-components@v0
with:
atmos-config-path: "${{ github.workspace }}/rootfs/usr/local/etc/atmos/"
jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'
```


include:

contributors:
Expand All @@ -105,4 +161,6 @@ contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "Daniel Miller"
github: "milldr"
github: "milldr"
- name: "Igor Rodionov"
github: "goruha"
Loading
Loading