Skip to content

Commit

Permalink
Backed up calculated jobs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Oct 3, 2024
1 parent bea4f7e commit 0171d92
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 188 deletions.
91 changes: 91 additions & 0 deletions .github/actions/templates/avm-getCalculatedJobControls/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#########################################################
## 'Get Workflow Controls' Composite Action ##
#########################################################
##
## This composite action contains the logic to calcuate the actions the workflow should run (e.g. only static, static + deployment, etc.) based on the type of trigger & the files changed.
##
#########################################################
##
##-------------------------------------------##
## ACTION PARAMETERS ##
##-------------------------------------------##
##
## |========================================================================================================================================================================|
## | Parameter | Required | Default | Description | Example |
## |--------------|----------|---------|----------------------------------------------------------------------------------|-------------------------------------------------|
## | workflowPath | true | '' | The path to the workflow file used to retrieve default workflow input parameters | '.github/workflows/avm.res.key-vault.vault.yml' |
## | modulePath | true | '' | The path to the module handled by this pipeline | 'avm/res/key-vault/vault' |
## |========================================================================================================================================================================|
##
#########################################################
##
##----------------------------------------##
## ACTION OUTPUTS ##
##----------------------------------------##
##
## |==============================================================================================|
## | Output | Description |
## |-------------------|--------------------------------------------------------------------------|
## | calculatedJobControls | An estimated pipeline action caluclated by evaluation changed files. |
## |==============================================================================================|
##
##---------------------------------------------##

name: "Get Workflow Controls"
description: "Get Workflow Controls"

inputs:
workflowPath:
description: "The path to the workflow file used to retrieve default workflow input parameters."
required: true
modulePath:
description: "The path to the module's folder"
required: true

outputs:
calculatedJobControls:
description: "The calculated actions to be executed, based on which files changed & inputs configured."
value: ${{ steps.get-workflow-controls.outputs.calculatedJobControls }}

runs:
using: "composite"
steps:
- name: Get (calculated) workflow controls
id: get-workflow-controls
run: |
# Grouping task logs
Write-Output '::group::Investigate GitHub event'
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'pipelines' 'workflows' 'Get-CalculatedJobControlObject.ps1')
if(Test-Path $env:GITHUB_EVENT_PATH) {
# $content = Get-Content $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
$functionInput = @{
# Commit = $content.after
ModulePath = '${{ inputs.modulePath }}'
GitHubEvent = '${{ github.event_name }}'
WorkflowPath = '${{ inputs.workflowPath }}'
RepoRoot = $env:GITHUB_WORKSPACE
}
if('${{ github.event_name }}' -eq 'workflow_dispatch') {
$functionInput['WorkflowParameters'] = ('${{ toJSON(github.event.inputs) }}' | ConvertFrom-Json -AsHashTable)
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
$result = Get-CalculatedJobControlObject @functionInput
# Output values to be accessed by next jobs
$calculatedJobControls = @{}
foreach($parameterName in $result.Keys) {
Write-Verbose ('Passing output [{0}] with value [{1}]' -f $parameterName, $result[$parameterName]) -Verbose
$calculatedJobControls[$parameterName] = $result[$parameterName].toString()
}
Write-Output ('{0}={1}' -f 'calculatedJobControls', ($calculatedJobControls | ConvertTo-Json -Compress)) >> $env:GITHUB_OUTPUT
}
Write-Output '::endgroup::'
shell: pwsh
108 changes: 0 additions & 108 deletions .github/actions/templates/avm-getWorkflowInput/action.yml

This file was deleted.

24 changes: 18 additions & 6 deletions .github/workflows/avm.res.key-vault.vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ on:
required: false
push:
branches:
- main
# - main
- users/alsehr/bu_calculatedPipelineStages
paths:
- ".github/actions/templates/avm-**"
- ".github/workflows/avm.template.module.yml"
- ".github/workflows/avm.res.key-vault.vault.yml"
- "avm/res/key-vault/vault/**"
- "avm/utilities/pipelines/**"

pull_request:
branches:
# - main
- users/alsehr/bu_calculatedPipelineStages
paths:
- ".github/actions/templates/avm-**"
- ".github/workflows/avm.template.module.yml"
Expand Down Expand Up @@ -53,9 +65,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Set input parameters to output variables"
id: get-workflow-param
uses: ./.github/actions/templates/avm-getWorkflowInput
- name: "Get calculated job controls"
id: get-calculated-job-controls
uses: ./.github/actions/templates/avm-getCalculatedJobControls
with:
workflowPath: "${{ env.workflowPath}}"
- name: "Get module test file paths"
Expand All @@ -64,8 +76,8 @@ jobs:
with:
modulePath: "${{ env.modulePath }}"
outputs:
workflowInput: ${{ steps.get-workflow-param.outputs.workflowInput }}
moduleTestFilePaths: ${{ steps.get-module-test-file-paths.outputs.moduleTestFilePaths }}
calculatedJobControls : ${{ steps.get-calculated-job-controls.outputs.calculatedJobControls }}
psRuleModuleTestFilePaths: ${{ steps.get-module-test-file-paths.outputs.psRuleModuleTestFilePaths }}
modulePath: "${{ env.modulePath }}"

Expand All @@ -81,8 +93,8 @@ jobs:
- job_initialize_pipeline
uses: ./.github/workflows/avm.template.module.yml
with:
workflowInput: "${{ needs.job_initialize_pipeline.outputs.workflowInput }}"
moduleTestFilePaths: "${{ needs.job_initialize_pipeline.outputs.moduleTestFilePaths }}"
calculatedJobControls : "${{ needs.job_initialize_pipeline.outputs.calculatedJobControls }}"
psRuleModuleTestFilePaths: "${{ needs.job_initialize_pipeline.outputs.psRuleModuleTestFilePaths }}"
modulePath: "${{ needs.job_initialize_pipeline.outputs.modulePath}}"
secrets: inherit
Loading

0 comments on commit 0171d92

Please sign in to comment.