diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml
index 44b1140..7ebd292 100644
--- a/.github/workflows/feature-branch.yml
+++ b/.github/workflows/feature-branch.yml
@@ -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/github-action-setup-atmos@v1.0.0
- with:
- atmos-version: "latest"
-
- - uses: dcarbone/install-jq-action@v1.0.1
- 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 }}"
\ No newline at end of file
diff --git a/.github/workflows/main-branch.yaml b/.github/workflows/main-branch.yaml
new file mode 100644
index 0000000..96e3a91
--- /dev/null
+++ b/.github/workflows/main-branch.yaml
@@ -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 }}"
diff --git a/.github/workflows/test-matrix-2-levels.yml b/.github/workflows/test-matrix-2-levels.yml
new file mode 100644
index 0000000..9bb65c2
--- /dev/null
+++ b/.github/workflows/test-matrix-2-levels.yml
@@ -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 }}"
diff --git a/.github/workflows/test-matrix-3-levels.yml b/.github/workflows/test-matrix-3-levels.yml
new file mode 100644
index 0000000..43626e5
--- /dev/null
+++ b/.github/workflows/test-matrix-3-levels.yml
@@ -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 }}"
diff --git a/.github/workflows/test-positive.yml b/.github/workflows/test-positive.yml
new file mode 100644
index 0000000..2c7f5d3
--- /dev/null
+++ b/.github/workflows/test-positive.yml
@@ -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 }}"
diff --git a/README.md b/README.md
index 28e6ce6..e3a8bf1 100644
--- a/README.md
+++ b/README.md
@@ -35,14 +35,6 @@ GitHub Action that outputs list of Atmos components by jq query
---
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
-[][share_email]
-[][share_googleplus]
-[][share_facebook]
-[][share_reddit]
-[][share_linkedin]
-[][share_twitter]
-
-
It's 100% Open Source and licensed under the [APACHE2](LICENSE).
@@ -65,7 +57,7 @@ GitHub Action that outputs list of Atmos components by jq query.
For example following query will fetch components that have in settings set `github.actions_enabled: true`:
```
-to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")
+.value.settings.github.actions_enabled // false
```
Output of this action is a list of basic component information. For example:
@@ -83,11 +75,32 @@ Output of this action is a list of basic component information. For example:
+## Usage
-## Usage
+### 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("-")
+```
+
+> [!IMPORTANT]
+> **Please note!** the `terraform-state-*` parameters refer to the S3 Bucket and corresponding meta storage DynamoDB table used to store the Terraform Plan files, and not the "Terraform State". These parameters will be renamed in a subsequent release.
### GitHub Actions Workflow Example
@@ -122,20 +135,48 @@ In following GitHub workflow example first job will filter components that have
echo "${{ matrix.stack_slug }}"
```
+### Migrating from `v0` to `v1`
+
+1. `v1` replaces the `jq-query` input parameter with a new parameter called `selected-filter` to simplify the query for end-users.
+ Now you need to specify only the part used inside of the `select(...)` function of the `jq-query`.
+2.`v1` moves most of the `inputs` to the Atmos GitOps config path `./.github/config/atmos-gitops.yaml`. Simply create this file, transfer your settings to it, then remove the corresponding arguments from your invocations of the `cloudposse/github-action-atmos-terraform-select-components` action.
+| name |
+|--------------------------|
+| `atmos-version` |
+| `atmos-config-path` |
+If you want the same behavior in `v2` as in `v1` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v0` 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'
+```
+
+Which would produce the same behavior as in `v2`, doing this:
+
+```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(",")'
+```
+
+Please note that the `atmos-gitops-config-path` is not the same file as the `atmos-config-path`.
-## Share the Love
-Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/github-action-atmos-terraform-select-components)! (it helps us **a lot**)
-Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
@@ -155,81 +196,70 @@ For additional context, refer to some of these links.
- [example-github-action-release-workflow](https://github.com/cloudposse/example-github-action-release-workflow) - Example application with complicated release workflow
-## Help
-
-**Got a question?** We got answers.
+## ✨ Contributing
-File a GitHub [issue](https://github.com/cloudposse/github-action-atmos-terraform-select-components/issues), send us an [email][email] or join our [Slack Community][slack].
+This project is under active development, and we encourage contributions from our community.
+Many thanks to our outstanding contributors:
-[![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link]
+
+
+
-## DevOps Accelerator for Startups
+### 🐛 Bug Reports & Feature Requests
+Please use the [issue tracker](https://github.com/cloudposse/github-action-atmos-terraform-select-components/issues) to report any bugs or file feature requests.
-We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
+### 💻 Developing
-[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
+If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email].
-Work directly with our team of DevOps experts via email, slack, and video conferencing.
+In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
-We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.
+ 1. **Fork** the repo on GitHub
+ 2. **Clone** the project to your own machine
+ 3. **Commit** changes to your own branch
+ 4. **Push** your work back up to your fork
+ 5. Submit a **Pull Request** so that we can review your changes
-- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
-- **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments.
-- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
-- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
-- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
-- **Training.** You'll receive hands-on training so your team can operate what we build.
-- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
-- **Troubleshooting.** You'll get help to triage when things aren't working.
-- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
-- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
+**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
-## Slack Community
+### 🌎 Slack Community
Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
-## Discourse Forums
-
-Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.
-
-## Newsletter
+### 📰 Newsletter
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
-## Office Hours
+### 📆 Office Hours
[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
-[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]
-
-## Contributing
-
-### Bug Reports & Feature Requests
+## About
-Please use the [issue tracker](https://github.com/cloudposse/github-action-atmos-terraform-select-components/issues) to report any bugs or file feature requests.
-
-### Developing
-
-If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email].
-
-In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
-
- 1. **Fork** the repo on GitHub
- 2. **Clone** the project to your own machine
- 3. **Commit** changes to your own branch
- 4. **Push** your work back up to your fork
- 5. Submit a **Pull Request** so that we can review your changes
-
-**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
+This project is maintained and funded by [Cloud Posse, LLC][website].
+
+We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
-## Copyright
+[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
-Copyright © 2017-2023 [Cloud Posse, LLC](https://cpco.io/copyright)
+Work directly with our team of DevOps experts via email, slack, and video conferencing.
+We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.
+- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
+- **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments.
+- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
+- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
+- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
+- **Training.** You'll receive hands-on training so your team can operate what we build.
+- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
+- **Troubleshooting.** You'll get help to triage when things aren't working.
+- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
+- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
+[![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link]
## License
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -255,46 +285,11 @@ specific language governing permissions and limitations
under the License.
```
-
-
-
-
-
-
-
-
## Trademarks
All other trademarks referenced herein are the property of their respective owners.
-
-## About
-
-This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know by [leaving a testimonial][testimonial]!
-
-[![Cloud Posse][logo]][website]
-
-We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source].
-
-We offer [paid support][commercial_support] on all of our projects.
-
-Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.
-
-
-
-### Contributors
-
-
-| [![Zinovii Dmytriv][zdmytriv_avatar]][zdmytriv_homepage]
[Zinovii Dmytriv][zdmytriv_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Daniel Miller][milldr_avatar]][milldr_homepage]
[Daniel Miller][milldr_homepage] |
-|---|---|---|
-
-
- [zdmytriv_homepage]: https://github.com/zdmytriv
- [zdmytriv_avatar]: https://img.cloudposse.com/150x150/https://github.com/zdmytriv.png
- [osterman_homepage]: https://github.com/osterman
- [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
-
+---
+Copyright © 2017-2023 [Cloud Posse, LLC](https://cpco.io/copyright)
[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
@@ -305,12 +300,9 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=jobs
[hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=hire
[slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=slack
- [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=linkedin
[twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=twitter
- [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=testimonial
[office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=office_hours
[newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=newsletter
- [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=discourse
[email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=email
[commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=commercial_support
[we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=we_love_open_source
@@ -321,11 +313,5 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=readme_footer_link
[readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img
[readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=readme_commercial_support_link
- [share_twitter]: https://twitter.com/intent/tweet/?text=github-action-atmos-terraform-select-components&url=https://github.com/cloudposse/github-action-atmos-terraform-select-components
- [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=github-action-atmos-terraform-select-components&url=https://github.com/cloudposse/github-action-atmos-terraform-select-components
- [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/github-action-atmos-terraform-select-components
- [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/github-action-atmos-terraform-select-components
- [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/github-action-atmos-terraform-select-components
- [share_email]: mailto:?subject=github-action-atmos-terraform-select-components&body=https://github.com/cloudposse/github-action-atmos-terraform-select-components
[beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/github-action-atmos-terraform-select-components?pixel&cs=github&cm=readme&an=github-action-atmos-terraform-select-components
diff --git a/README.yaml b/README.yaml
index ba25f53..d3f7c78 100644
--- a/README.yaml
+++ b/README.yaml
@@ -33,7 +33,7 @@ introduction: |-
For example following query will fetch components that have in settings set `github.actions_enabled: true`:
```
- to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")
+ .value.settings.github.actions_enabled // false
```
Output of this action is a list of basic component information. For example:
@@ -64,6 +64,29 @@ 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`.
+ 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("-")
+ ```
+
+ > [!IMPORTANT]
+ > **Please note!** the `terraform-state-*` parameters refer to the S3 Bucket and corresponding meta storage DynamoDB table used to store the Terraform Plan files, and not the "Terraform State". These parameters will be renamed in a subsequent release.
+
### 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.
@@ -97,6 +120,44 @@ usage: |
echo "${{ matrix.stack_slug }}"
```
+ ### Migrating from `v0` to `v1`
+
+ 1. `v1` replaces the `jq-query` input parameter with a new parameter called `selected-filter` to simplify the query for end-users.
+ Now you need to specify only the part used inside of the `select(...)` function of the `jq-query`.
+
+ 2.`v1` moves most of the `inputs` to the Atmos GitOps config path `./.github/config/atmos-gitops.yaml`. Simply create this file, transfer your settings to it, then remove the corresponding arguments from your invocations of the `cloudposse/github-action-atmos-terraform-select-components` action.
+
+ | name |
+ |--------------------------|
+ | `atmos-version` |
+ | `atmos-config-path` |
+
+
+ If you want the same behavior in `v2` as in `v1` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v0` 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'
+ ```
+
+ Which would produce the same behavior as in `v2`, doing this:
+
+ ```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(",")'
+ ```
+
+ Please note that the `atmos-gitops-config-path` is not the same file as the `atmos-config-path`.
+
+
include:
contributors:
@@ -105,4 +166,6 @@ contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "Daniel Miller"
- github: "milldr"
\ No newline at end of file
+ github: "milldr"
+ - name: "Igor Rodionov"
+ github: "goruha"
diff --git a/action.yml b/action.yml
index 1c8bb53..3b205d0 100644
--- a/action.yml
+++ b/action.yml
@@ -5,25 +5,18 @@ branding:
icon: "file"
color: "white"
inputs:
- jq-query:
+ select-filter:
description: jq query that will be used to select atmos components
- required: true
- default-branch:
- description: The default branch to use for the base ref.
required: false
- default: ${{ github.event.repository.default_branch }}
- atmos-version:
- description: The version of atmos to install if install-atmos is true
+ default: '.'
+ head-ref:
+ description: The head ref to checkout. If not provided, the head default branch is used.
required: false
- default: "latest"
- atmos-config-path:
- description: The path to the atmos.yaml file
+ default: ${{ github.sha }}
+ atmos-gitops-config-path:
+ description: The path to the atmos-gitops.yaml file
required: false
- default: atmos.yaml
- terraform-version:
- description: The version of terraform to install if install-terraform is true
- required: false
- default: "latest"
+ default: ./.github/config/atmos-gitops.yaml
jq-version:
description: The version of jq to install if install-jq is true
required: false
@@ -32,24 +25,42 @@ inputs:
description: "Enable action debug mode. Default: 'false'"
default: 'false'
required: false
+ nested-matrices-count:
+ required: false
+ description: 'Number of nested matrices that should be returned as the output (from 1 to 3)'
+ default: "2"
outputs:
selected-components:
description: Selected GitOps components
value: ${{ steps.selected-components.outputs.components }}
- matrix:
- description: Matrix for Selected GitOps components
- value: ${{ steps.matrix.outputs.matrix }}
has-selected-components:
description: Whether there are selected components
value: ${{ steps.selected-components.outputs.components != '[]' }}
+ matrix:
+ description: The selected components as matrix structure suitable for extending matrix size workaround (see README)
+ value: ${{ steps.matrix.outputs.matrix }}
runs:
using: "composite"
steps:
+ - uses: actions/checkout@v3
+ with:
+ ref: ${{ inputs.head-ref }}
+
+ - name: Read Atmos GitOps config
+ ## We have to reference cloudposse fork of https://github.com/blablacar/action-config-levels
+ ## before https://github.com/blablacar/action-config-levels/pull/16 would be merged
+ uses: cloudposse/github-action-config-levels@nodejs20
+ id: config
+ with:
+ output_properties: true
+ patterns: |
+ - ${{ inputs.atmos-gitops-config-path }}
+
- name: Install Terraform
uses: hashicorp/setup-terraform@v2
with:
- terraform_version: ${{ inputs.terraform-version }}
+ terraform_version: ${{ steps.config.outputs.terraform-version }}
terraform_wrapper: false
- name: Install Atmos
@@ -57,7 +68,7 @@ runs:
env:
ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}}
with:
- atmos-version: ${{ inputs.atmos-version }}
+ atmos-version: ${{ steps.config.outputs.atmos-version }}
install-wrapper: false
- name: Install JQ
@@ -65,26 +76,35 @@ runs:
with:
version: ${{ inputs.jq-version }}
- - name: Checkout
- uses: actions/checkout@v3
- with:
- ref: ${{ inputs.default-branch }}
-
- name: Filter Components
id: selected-components
shell: bash
env:
- ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}}
+ ATMOS_CLI_CONFIG_PATH: ${{ steps.config.outputs.atmos-config-path }}
+ JQUERY: |
+ with_entries(.value |= (.components.terraform)) | ## Deal with components type of terraform
+ map_values(map_values(select(${{ inputs.select-filter }}))) | ## Filter components by enabled github actions
+ map_values(select(. != {})) | ## Skip stacks that have 0 selected components
+ map_values(. | keys) | ## Reduce to component names
+ with_entries( ## Construct component object
+ .key as $stack |
+ .value |= map({
+ "component": .,
+ "stack": $stack,
+ "stack_slug": [$stack, .] | join("-")
+ })
+ ) | map(.) | flatten ## Reduce to flat array
run: |
- JQ_QUERY='${{ inputs.jq-query }}' DEBUG="${{ inputs.debug }}" ${{ github.action_path }}/src/filter.sh
+ atmos describe stacks --format json | jq -ce "${JQUERY}" > components.json
components=$(cat components.json)
echo "Selected components: $components"
printf "%s" "components=$components" >> $GITHUB_OUTPUT
- - name: Build Matrix
+ - uses: cloudposse/github-action-matrix-extended@v0
id: matrix
- shell: bash
- run: |
- matrix=$(jq -c '{include:[.[]]}' < components.json)
- echo "matrix=$matrix" >> $GITHUB_OUTPUT
+ with:
+ matrix: components.json
+ sort-by: ${{ steps.config.outputs.sort-by }}
+ group-by: ${{ steps.config.outputs.group-by }}
+ nested-matrices-count: ${{ inputs.nested-matrices-count }}
diff --git a/docs/github-action.md b/docs/github-action.md
index 5db4999..78f65a0 100644
--- a/docs/github-action.md
+++ b/docs/github-action.md
@@ -4,13 +4,12 @@
| Name | Description | Default | Required |
|------|-------------|---------|----------|
-| atmos-config-path | The path to the atmos.yaml file | atmos.yaml | false |
-| atmos-version | The version of atmos to install if install-atmos is true | latest | false |
+| atmos-gitops-config-path | The path to the atmos-gitops.yaml file | ./.github/config/atmos-gitops.yaml | false |
| debug | Enable action debug mode. Default: 'false' | false | false |
-| default-branch | The default branch to use for the base ref. | ${{ github.event.repository.default\_branch }} | false |
-| jq-query | jq query that will be used to select atmos components | N/A | true |
+| head-ref | The head ref to checkout. If not provided, the head default branch is used. | ${{ github.sha }} | false |
| jq-version | The version of jq to install if install-jq is true | 1.6 | false |
-| terraform-version | The version of terraform to install if install-terraform is true | latest | false |
+| nested-matrices-count | Number of nested matrices that should be returned as the output (from 1 to 3) | 2 | false |
+| select-filter | jq query that will be used to select atmos components | . | false |
## Outputs
@@ -18,6 +17,6 @@
| Name | Description |
|------|-------------|
| has-selected-components | Whether there are selected components |
-| matrix | Matrix for Selected GitOps components |
+| matrix | The selected components as matrix structure suitable for extending matrix size workaround (see README) |
| selected-components | Selected GitOps components |
diff --git a/src/filter.sh b/src/filter.sh
deleted file mode 100755
index cacf33b..0000000
--- a/src/filter.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-
-JQ_QUERY=${JQ_QUERY:-'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'}
-
-atmos describe stacks --format json --file stacks.json
-[ "$DEBUG" == "true" ] && cat stacks.json
-
-jq -r "$JQ_QUERY" stacks.json > components.csv
-[ "$DEBUG" == "true" ] && cat components.csv
-
-echo -n "" > enriched_components.csv
-while IFS=',' read -r stack component
-do
- component_path=$(atmos describe component $component -s $stack --format json | jq -rc '.. | select(.component_info)? | .component_info.component_path')
- echo "$stack,$component,$component_path" >> enriched_components.csv
-done < components.csv
-
-[ "$DEBUG" == "true" ] && cat enriched_components.csv
-
-echo -n '[' > components.json
-while IFS=',' read -r stack component component_path; do
- stack_slug="$stack-$component"
- printf '{"stack": "%s", "component": "%s", "stack_slug": "%s", "component_path": "%s"},' "$stack" "$component" "$stack_slug" "$component_path" >> components.json
-done < enriched_components.csv
-sed -i.bak '$ s/,$//' components.json # Removing the last comma and appending closing brackets
-echo -n ']' >> components.json
-
-[ "$DEBUG" == "true" ] && cat components.json
-
-components=$(jq -c < components.json)
-echo -n "$components" > components.json
diff --git a/test/run.sh b/test/run.sh
deleted file mode 100755
index 8b16140..0000000
--- a/test/run.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-./src/filter.sh
-
-expected_content='[{"stack":"core-ue2-auto","component":"test-2","stack_slug":"core-ue2-auto-test-2","component_path":""},{"stack":"plat-ue2-dev","component":"test-4","stack_slug":"plat-ue2-dev-test-4","component_path":""},{"stack":"plat-ue2-sandbox","component":"test-5","stack_slug":"plat-ue2-sandbox-test-5","component_path":""}]'
-file_content=$(