Skip to content

Commit f118544

Browse files
committed
updated static analysis
1 parent 7ccc37b commit f118544

File tree

2 files changed

+106
-12
lines changed

2 files changed

+106
-12
lines changed
Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Static Analysis
1+
name: 🔍 Static Analysis MA
22

33
on:
44
push:
@@ -7,10 +7,92 @@ on:
77

88
jobs:
99
static_analysis:
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-latest
11+
env:
12+
TF_PLUGIN_CACHE_DIR: /tmp/.terraform.d/plugin-cache
1113

1214
steps:
13-
- name: Static Analysis
14-
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@59c12b7a846423d62c27c9905686a7a1fd71c003 # v1.7.0
15+
- name: ⚡ Checkout code
16+
uses: actions/checkout@v4.1.1
17+
18+
- name: 📖 Read Terraform version
19+
run: |
20+
echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> $GITHUB_ENV
21+
22+
- name: 🔨 Setup Terraform
23+
uses: hashicorp/setup-terraform@v3.1.0
24+
with:
25+
terraform_version: "${{ env.TERRAFORM_VERSION }}"
26+
27+
- name: 💾 Cache Terraform plugins
28+
uses: actions/cache@v4
1529
with:
16-
precommit_version: 'v1.99.0@sha256:73239e93f97c005ed16189f3ca523f78d666af0902f3621a1eff8db22b7bb18c'
30+
path: $TF_PLUGIN_CACHE_DIR
31+
key: ${{ runner.os }}-terraform-${{ env.TERRAFORM_VERSION }}-${{ hashFiles('**/.terraform.lock.hcl') }}
32+
restore-keys: |
33+
${{ runner.os }}-terraform-${{ env.TERRAFORM_VERSION }}-
34+
${{ runner.os }}-terraform-
35+
36+
- name: 🔧 Setup Terraform plugin cache
37+
run: |
38+
mkdir -p $TF_PLUGIN_CACHE_DIR
39+
echo 'plugin_cache_dir = "/tmp/.terraform.d/plugin-cache"' > ~/.terraformrc
40+
41+
- name: 🏁 Init Terraform folders
42+
shell: bash
43+
run: |
44+
echo "📢 Show space"
45+
df -h
46+
47+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-"
48+
echo "+ 🏁 INIT TERRAFORM FOLDERS 🏁 +"
49+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n"
50+
51+
# Generate a unique list of folders containing `.tf` files, excluding the 90_aws folder
52+
FOLDERS=$(find . -type f -name "*.tf" ! -path "*/.terraform/*" ! -path "*/90_aws/*" -exec dirname {} \; | sort -u)
53+
echo "FOLDERS=${FOLDERS}"
54+
55+
for f in $FOLDERS; do
56+
echo -e "\n📂 Processing: ${f}"
57+
(
58+
cd "${f}" || exit
59+
# Check for any necessary changes to backend configurations
60+
if [[ -f "99_main.tf" ]]; then
61+
sed -i -e 's/ backend "azurerm" {}//g' 99_main.tf || true
62+
fi
63+
# Initialize Terraform and lock providers for all platforms
64+
terraform init -upgrade -lockfile=true &&
65+
terraform providers lock \
66+
-platform=darwin_arm64 \
67+
-platform=darwin_amd64 \
68+
-platform=linux_amd64 \
69+
-platform=linux_arm64
70+
) || echo "⚠️ Initialization failed for ${f}"
71+
done
72+
73+
- name: Show precommit version
74+
shell: bash
75+
run: |
76+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
77+
echo "+ 1️⃣ SHOW PRECOMMIT VERSION 1️⃣ +"
78+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
79+
80+
TAG=v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758
81+
docker run --rm --entrypoint cat ghcr.io/antonbabenko/pre-commit-terraform:$TAG /usr/bin/tools_versions_info
82+
83+
- name: 🚨 Run precommit
84+
shell: bash
85+
run: |
86+
echo -e "\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
87+
echo "+- 🚨 PRECOMMIT TERRAFORM 🚨 -+"
88+
echo -e "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
89+
90+
TARGET_FILES=$(find . -type f -name "*.tf" ! -path "*/.terraform/*" ! -path "./src/90_aws/*")
91+
92+
TAG=v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758
93+
docker run \
94+
-v "$(pwd)":/lint \
95+
-v /tmp/.terraform.d/plugin-cache:/tmp/.terraform.d/plugin-cache \
96+
-w /lint \
97+
ghcr.io/antonbabenko/pre-commit-terraform:$TAG \
98+
run --files $TARGET_FILES --show-diff-on-failure
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Static Analysis PR
1+
name: 🛃 Static Analysis PR
22

33
on:
44
push:
@@ -7,19 +7,31 @@ on:
77

88
jobs:
99
static_analysis:
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-latest
1111

1212
steps:
13+
- run: |
14+
rm -rf *
15+
1316
- name: 🔨 Get Modified Paths
1417
id: get-paths
15-
uses: pagopa/eng-github-actions-iac-template/global/get-modifed-folders@6cc78fc1c578c0fdfc8ba739bef634b21e8e35b4 # v1.19.0
18+
uses: pagopa/eng-github-actions-iac-template/global/get-modifed-folders@f10814b649ecd6e5d97c489084d2a107e2f1b2ee #v1.22.3
1619
with:
20+
ignore_patterns: ".github,.devops,.vscode,.terraform-version,90_aws"
1721
start_folder: "src"
18-
default_end_folder_depth: 3
19-
include_patterns: "src,domains"
22+
include_folders: "tag_config"
23+
include_patterns: "src"
24+
stopper_folders: "env,tests,api,api_product,helm,argocd,secrets"
25+
26+
- name: 👀 See folders downloaded
27+
if: env.dir_changes_detected == 'true'
28+
id: see
29+
shell: bash
30+
run: |
31+
tree -R -d -a .
2032
2133
- name: Static Analysis
2234
if: env.dir_changes_detected == 'true'
23-
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@6b8192a09750c44dde5a9a8d9ed72648547071c5 # v1.14.1
35+
uses: pagopa/eng-github-actions-iac-template/azure/terraform-static-analysis@159289e1e23d0783533d1dd83e1b7cf0a5a565d9 #v1.24.0
2436
with:
25-
precommit_version: 'v1.99.0@sha256:73239e93f97c005ed16189f3ca523f78d666af0902f3621a1eff8db22b7bb18c'
37+
precommit_version: 'v1.99.2@sha256:34f6cef8b944d571ea22be316a960d8353fcc0571adea35302cbd9ab80bf2758'

0 commit comments

Comments
 (0)