Skip to content

Commit

Permalink
Refac/github_actions (#1)
Browse files Browse the repository at this point in the history
* feat(dev_requirements): Add pytest

* refac(workspace_settings): Specify python interpreter path

* refac(cicd): Combine actions in composition action and add unit tests.

* fix(cicd): Remove custom arg from pytest.

* fix(cicd): Add missing requirements for pytest

* feat(tasks): Add task to install all dependencies.

* feat(pytest_typehint): Add extension for pytest hints.

* feat(tests): Add initial test.

* ruff format

* fix(pytest): Set pythonpath

* fix(cicd): Pass python version to sub actions with input.

* fix(cicd): Add input for sub actions

* fix(cicd): Read python version from project file instead of env.

* fix(cicd): python version var assignment
  • Loading branch information
Noahnc authored Nov 24, 2023
1 parent 7e201ba commit e8aa063
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 195 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"evendead.help-me-add",
"charliermarsh.ruff",
"streetsidesoftware.code-spell-checker",
"njqdev.vscode-python-typehint"
"njqdev.vscode-python-typehint",
"Cameron.vscode-pytest"
]
}
}
Expand Down
117 changes: 55 additions & 62 deletions .github/workflows/action_integration_test.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
name: "GitHub Action integration test"

permissions:
contents: write
pull-requests: write

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
integration-test:
env:
report_json_file: InfraPatch_Statistics.json

name: "Run GitHub Action integration test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Run in report only mode
uses: ./
with:
report_only: true

- name: Run in update mode
id: update
uses: ./
with:
report_only: false
target_branch_name: "feat/infrapatch_test_${{ github.run_number }}"

- name: Check update result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( -not ( $report.resources_patched -gt 3 ) ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
- name: Delete created branch$
if: always()
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
branches: ${{ steps.update.outputs.target_branch }}
soft_fail: true






name: "GitHub Action integration test"

on:
workflow_call:

jobs:
integration-test:
env:
report_json_file: InfraPatch_Statistics.json

name: "Run GitHub Action integration test"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run in report only mode
uses: ./
with:
report_only: true

- name: Run in update mode
id: update
uses: ./
with:
report_only: false
target_branch_name: "feat/infrapatch_test_${{ github.run_number }}"

- name: Check update result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( -not ( $report.resources_patched -gt 3 ) ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
- name: Delete created branch$
if: always()
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
branches: ${{ steps.update.outputs.target_branch }}
soft_fail: true






28 changes: 18 additions & 10 deletions .github/workflows/check_format_and_lint.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
name: "Check Format and Lint Code"

on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches:
- main
workflow_call:

jobs:
check_code:
name: "Check Format and Lint Code"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get Python Version
id: get_python_verion
run: |
python_version=$(cat python_version.txt)
echo "Using Python version $python_version"
echo "::set-output name=python_version::$(echo $python_version)"
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: ${{ steps.get_python_verion.outputs.python_version }}

- name: Install Dependencies
run: |
Expand All @@ -31,4 +34,9 @@ jobs:

- name: Check code with ruff
run: ruff check .







Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
name: CLI Integration test

on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches:
- main

jobs:
test:
# only run if not closed or closed with merge
if: ${{ github.event.pull_request.merged == true || github.event.pull_request.state != 'closed' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report_json_file: InfraPatch_Statistics.json

strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
# - windows-latest Windows does currently not work because of pygohcl
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install InfraPatch CLI
run: |
python -m pip install .
shell: bash

- name: Run InfraPatch report
shell: bash
run: infrapatch --debug report --dump-json-statistics

- name: Check report result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( $report.resources_patched -ne 0 ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
- name: Run InfraPatch update
shell: bash
run: infrapatch --debug update --dump-json-statistics --confirm

- name: Check update result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( -not ( $report.resources_patched -gt 3 ) ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
name: CLI Integration test

on:
workflow_call:

jobs:
cli_integration_test:
name: CLI Integration test
# only run if not closed or closed with merge
if: ${{ github.event.pull_request.merged == true || github.event.pull_request.state != 'closed' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report_json_file: InfraPatch_Statistics.json

strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
# - windows-latest Windows does currently not work because of pygohcl
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get Python Version
id: get_python_verion
run: |
python_version=$(cat python_version.txt)
echo "Using Python version $python_version"
echo "::set-output name=python_version::$(echo $python_version)"
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ steps.get_python_verion.outputs.python_version }}

- name: Install InfraPatch CLI
run: |
python -m pip install .
shell: bash

- name: Run InfraPatch report
shell: bash
run: infrapatch --debug report --dump-json-statistics

- name: Check report result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( $report.resources_patched -ne 0 ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
- name: Run InfraPatch update
shell: bash
run: infrapatch --debug update --dump-json-statistics --confirm

- name: Check update result
shell: pwsh
run: |
$report = Get-Content $env:report_json_file -Raw | ConvertFrom-Json
if ( -not $report.total_resources -gt 0 ) {
throw "Failed to get resources"
}
if ( -not ( $report.resources_patched -gt 3 ) ) {
throw "No resources should be patched"
}
if ( $report.errors -gt 0 ) {
throw "Errors have been detected"
}
36 changes: 36 additions & 0 deletions .github/workflows/composition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: InfraPatch Checks

permissions:
contents: write
pull-requests: write

on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches:
- main

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:

check_code:
uses: ./.github/workflows/check_format_and_lint.yml

unit_tests:
needs: check_code
uses: ./.github/workflows/unit_tests.yml

cli_integration_test:
needs: unit_tests
uses: ./.github/workflows/cli_integration_test.yml

github_action_integration_test:
needs: unit_tests
uses: ./.github/workflows/action_integration_test.yml

Loading

0 comments on commit e8aa063

Please sign in to comment.