Skip to content

Commit

Permalink
Simplify workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudlh committed Jun 3, 2024
1 parent 9027a9e commit 5707eec
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 630 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License.
#

name: PR Dispatch Workflow
name: PR Tflint

on:
pull_request:
Expand All @@ -12,6 +12,7 @@ on:
env:
TF_VERSION: "1.8.4"
TF_LINT_VERSION: "v0.50.3"

jobs:
linting:
name: Format and Lint Checks
Expand All @@ -35,30 +36,10 @@ jobs:
with:
tflint_version: ${{ env.TF_LINT_VERSION }}


- name: Run TFLint with reviewdog
uses: reviewdog/action-tflint@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
level: info
tflint_init: true

dispatch:
runs-on: ubuntu-latest
strategy:
matrix:
scenario:
- standalone-scenarios-azuread.json
- standalone-scenarios.json
- standalone-compute.json
- standalone-networking.json
- standalone-scenarios-longrunners.json

steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: pr-${{ matrix.scenario }}
client-payload: '{"scenario": "${{ (matrix.scenario) }}", "sha": "${{ github.event.pull_request.head.sha }}"}'
tflint_init: true
95 changes: 95 additions & 0 deletions .github/workflows/pr_tests-azuread.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#

name: PR azuread-tests

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'azuread*'
- 'modules/azuread/**'
- 'examples/azuread/**'
- '.github/workflows/*azuread.*'

env:
scenario: standalone-azuread.json
TF_VERSION: "1.8.4"
TF_LINT_VERSION: "v0.50.3"

jobs:
load_scenarios:
name: Load Test Scenarios Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load_scenarios.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- id: load_scenarios
run: |
cases=$(cat ./.github/workflows/${{ env.SCENARIO }} | jq -c .)
echo "matrix=${cases}" >> $GITHUB_OUTPUT
mock_plan_scenarios:
name: ${{ matrix.config_files }}
runs-on: ubuntu-latest
needs: load_scenarios

strategy:
fail-fast: false
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create environment variables
run: |
cd ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }}
FILE_NAME=$(echo ${{ matrix.config_files }} | sed 's./..g' | xargs)
echo STATE_FILE=${HOME}/tfstates/${FILE_NAME}.tfstate >> $GITHUB_ENV
echo PLAN_FILE=${HOME}/tfstates/${FILE_NAME}.plan >> $GITHUB_ENV
echo CURRENT_FOLDER=${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} >> $GITHUB_ENV
echo PARAMETER_FILES=$(find ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} | grep .tfvars | sed 's/.*/-var-file=&/' | xargs) >> $GITHUB_ENV
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Configure Terraform plugin cache
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Cache Terraform
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugin-cache
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Terraform Init example
id: tf_init
run: |
terraform -chdir=examples \
init
- name: Terraform Test example
id: tf_test
run: |
terraform -chdir=examples \
test \
-test-directory=./tests/mock \
${{ env.PARAMETER_FILES }} \
-verbose
95 changes: 95 additions & 0 deletions .github/workflows/pr_tests-compute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#

name: PR compute-tests

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'compute_*'
- 'modules/compute/**'
- 'examples/compute/**'
- '.github/workflows/*compute.*'

env:
scenario: standalone-compute.json
TF_VERSION: "1.8.4"
TF_LINT_VERSION: "v0.50.3"

jobs:
load_scenarios:
name: Load Test Scenarios Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load_scenarios.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- id: load_scenarios
run: |
cases=$(cat ./.github/workflows/${{ env.SCENARIO }} | jq -c .)
echo "matrix=${cases}" >> $GITHUB_OUTPUT
mock_plan_scenarios:
name: ${{ matrix.config_files }}
runs-on: ubuntu-latest
needs: load_scenarios

strategy:
fail-fast: false
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create environment variables
run: |
cd ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }}
FILE_NAME=$(echo ${{ matrix.config_files }} | sed 's./..g' | xargs)
echo STATE_FILE=${HOME}/tfstates/${FILE_NAME}.tfstate >> $GITHUB_ENV
echo PLAN_FILE=${HOME}/tfstates/${FILE_NAME}.plan >> $GITHUB_ENV
echo CURRENT_FOLDER=${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} >> $GITHUB_ENV
echo PARAMETER_FILES=$(find ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} | grep .tfvars | sed 's/.*/-var-file=&/' | xargs) >> $GITHUB_ENV
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Configure Terraform plugin cache
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Cache Terraform
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugin-cache
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Terraform Init example
id: tf_init
run: |
terraform -chdir=examples \
init
- name: Terraform Test example
id: tf_test
run: |
terraform -chdir=examples \
test \
-test-directory=./tests/mock \
${{ env.PARAMETER_FILES }} \
-verbose
101 changes: 101 additions & 0 deletions .github/workflows/pr_tests-dataplat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#

name: PR dataplat-tests

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'mssql*'
- 'modules/analytics/**'
- 'modules/databases/**'
- 'modules/data_factory/**'
- 'modules/purview/**'
- 'examples/analytics/**'
- 'examples/databases/**'
- 'examples/data_factory/**'
- 'examples/purview/**'
- '.github/workflows/*dataplat.*'

env:
scenario: standalone-dataplat.json
TF_VERSION: "1.8.4"
TF_LINT_VERSION: "v0.50.3"

jobs:
load_scenarios:
name: Load Test Scenarios Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load_scenarios.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- id: load_scenarios
run: |
cases=$(cat ./.github/workflows/${{ env.SCENARIO }} | jq -c .)
echo "matrix=${cases}" >> $GITHUB_OUTPUT
mock_plan_scenarios:
name: ${{ matrix.config_files }}
runs-on: ubuntu-latest
needs: load_scenarios

strategy:
fail-fast: false
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create environment variables
run: |
cd ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }}
FILE_NAME=$(echo ${{ matrix.config_files }} | sed 's./..g' | xargs)
echo STATE_FILE=${HOME}/tfstates/${FILE_NAME}.tfstate >> $GITHUB_ENV
echo PLAN_FILE=${HOME}/tfstates/${FILE_NAME}.plan >> $GITHUB_ENV
echo CURRENT_FOLDER=${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} >> $GITHUB_ENV
echo PARAMETER_FILES=$(find ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} | grep .tfvars | sed 's/.*/-var-file=&/' | xargs) >> $GITHUB_ENV
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Configure Terraform plugin cache
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Cache Terraform
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugin-cache
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Terraform Init example
id: tf_init
run: |
terraform -chdir=examples \
init
- name: Terraform Test example
id: tf_test
run: |
terraform -chdir=examples \
test \
-test-directory=./tests/mock \
${{ env.PARAMETER_FILES }} \
-verbose
Loading

0 comments on commit 5707eec

Please sign in to comment.