Skip to content

Commit

Permalink
Refactor GHA (#189)
Browse files Browse the repository at this point in the history
## what
* Refactoring of the action
* Added tests
* Added `process-all` flag 
* Fix the action failure in case all affected stacks have not changed (artifact does not exist)
* Fix the bug when an issue has wrong metadata or no metadata at all
* Fix the bug when the summary size runs out of 1Mb limit

## why
* Improve code readability
* Gain insurance in the action stability
* Fix the bug when the action runs in the `apply` workflow to close issues created by the `drift detection` workflow.
* Fix apply and drift detection workflow when there is no stack with drift or error
* Avoid failing of `apply` and `drift detection` workflows because of wrong metadata in one issue
* Avoid errors because a summary is too big

## references
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#step-isolation-and-limits
* https://cloudposse.atlassian.net/browse/DEV-1562
* https://cloudposse.atlassian.net/browse/DEV-1561
* https://cloudposse.atlassian.net/browse/DEV-1560
* https://cloudposse.atlassian.net/browse/DEV-1555
* https://cloudposse.atlassian.net/browse/DEV-1559
* https://cloudposse.atlassian.net/browse/DEV-1135
  • Loading branch information
goruha authored Jan 11, 2024
1 parent 6f8486b commit cacbb69
Show file tree
Hide file tree
Showing 19 changed files with 801 additions and 388 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/test-max-opened-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: "Test - Max opened issues"

on:
# pull_request: {}
workflow_dispatch: {}

env:
AWS_REGION: us-east-2

# Permissions required for assuming AWS identity
permissions:
id-token: write
contents: read
issues: write

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

- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: metadata
path: ./tests/fixtures/metadata
retention-days: 1

test:
runs-on: ubuntu-latest
continue-on-error: true
needs: [setup]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Plan Atmos Component
id: current
uses: ./
with:
max-opened-issues: '3'
labels: "test-max-opened-issues"
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}

outputs:
result: ${{ steps.current.outcome }}

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: 'success'
actual: "${{ needs.test.outputs.result }}"

- name: Find all issues
id: issues
uses: lee-dohm/select-matching-issues@v1
with:
query: 'label:test-max-opened-issues is:open'
token: ${{ github.token }}

- name: Close found issues
id: test
run: |
cat ${{ steps.issues.outputs.path }}
echo "count=$(cat ${{ steps.issues.outputs.path }} | xargs -I {} -d '\n' echo "{}" | wc -l )" >> $GITHUB_OUTPUT
- uses: nick-fields/assert-action@v1
with:
expected: '3'
actual: "${{ steps.test.outputs.count }}"

teardown:
runs-on: ubuntu-latest
needs: [assert]
if: ${{ always() }}
steps:
- name: Tear down
run: echo "Do Tear down"

- name: Find all issues
id: issues
uses: lee-dohm/select-matching-issues@v1
with:
query: 'label:test-max-opened-issues is:open'
token: ${{ github.token }}

- name: Close found issues
run: cat ${{ steps.issues.outputs.path }} | xargs -I {} -d '\n' gh issue close {}
env:
GH_TOKEN: ${{ github.token }}
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: "Comma-separated list of additional labels to assign issues to."
required: false
default: ""
process-all:
description: "Process all issues or only the ones that relates to affected stacks. Default: false"
required: false
default: "false"
token:
description:
Used to pull node distributions for Atmos from Cloud Posse's GitHub repository. Since there's a default, this is typically
Expand Down
Loading

0 comments on commit cacbb69

Please sign in to comment.