Skip to content

Commit ef21d01

Browse files
ishaankalraunni-facetsRoguedBear
authored
Supporting publishable and validate directory (#7)
* skip_terraform_validation * use ftf * cache checkcov with python gha * Revert "cache checkcov with python gha" (#5) * Ensure requirements.txt is present to prevent setup-python failure (#6) * Update action.yml * added publishable flag * added support for validate * removed true from check only --------- Co-authored-by: unni-facets <krishnanunni.menon@facets.cloud> Co-authored-by: Jayant <jayant.sharma@facets.cloud> Co-authored-by: Jayant <39442192+RoguedBear@users.noreply.github.com>
1 parent 5a1fd3d commit ef21d01

2 files changed

Lines changed: 56 additions & 50 deletions

File tree

module-preview-action/action.yml

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ inputs:
2020
description: "Run the action for all modules in repo"
2121
required: false
2222
default: "false"
23+
skip-terraform-validation:
24+
description: "Skip the Terraform Validate step"
25+
required: false
26+
default: "false"
27+
auto-create-intent:
28+
description: "Automatically create intent if not exists"
29+
required: false
30+
default: "false"
31+
publish:
32+
description: "Publish the module"
33+
required: false
34+
default: "false"
35+
publishable:
36+
description: "Whether the modules registered in preview mode are publishable or not. This is not required if publish is set to true."
37+
required: false
38+
default: "false"
2339

2440
runs:
2541
using: "composite"
@@ -29,18 +45,28 @@ runs:
2945
with:
3046
fetch-depth: 0
3147

48+
# This step is needed since setup-python fails if it doesnt detect either of these two files
49+
- if: hashFiles('**/requirements.txt', '**/pyproject.toml') == ''
50+
shell: bash
51+
run: |
52+
touch ./requirements.txt
53+
54+
- uses: actions/setup-python@v5
55+
with:
56+
python-version: "3.12"
57+
cache: "pip"
3258

3359
- name: Install Dependencies (Facets, Terraform, Checkov)
3460
shell: bash
3561
run: |
3662
sudo apt-get install -y python3 python3-pip curl unzip jq git
3763
curl -fsSL https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip -o terraform.zip
3864
unzip terraform.zip && mv terraform /usr/local/bin/ && rm terraform.zip
39-
pip install checkov
65+
pip install git+https://github.com/Facets-cloud/module-development-cli.git
4066
4167
- name: Identify All Facets Modules (All Modules)
4268
if: inputs.all-modules == 'true'
43-
id: dry_run_dirs
69+
id: all_dirs
4470
shell: bash
4571
run: |
4672
echo "🚀 Step: Identify All Facets Modules (All Modules)"
@@ -101,36 +127,6 @@ runs:
101127
echo "dirs=$FACETS_DIRS" >> "$GITHUB_ENV"
102128
echo "✅ Step complete."
103129
104-
105-
106-
- name: Run Terraform Formatting Check (Fail on Incorrect Formatting)
107-
if: env.dirs != ''
108-
shell: bash
109-
run: |
110-
for dir in $dirs; do
111-
echo "🔍 Checking Terraform formatting in $dir"
112-
terraform fmt -recursive -check "$dir" || (echo "❌ Terraform formatting issues found in $dir. Run 'terraform fmt' locally." && exit 1)
113-
done
114-
115-
- name: Run Terraform Validate
116-
if: env.dirs != ''
117-
shell: bash
118-
run: |
119-
for dir in $dirs; do
120-
echo "✅ Validating Terraform in $dir"
121-
terraform -chdir="$dir" init -backend=false
122-
terraform -chdir="$dir" validate
123-
done
124-
125-
- name: Run Checkov Security Scan
126-
if: env.dirs != ''
127-
shell: bash
128-
run: |
129-
for dir in $dirs; do
130-
echo "🔍 Running Checkov security scan in $dir"
131-
checkov -d "$dir" --quiet --hard-fail-on HIGH,CRITICAL --framework terraform,kubernetes --output cli
132-
done
133-
134130
- name: Get Git Info
135131
if: env.dirs != '' && inputs.dry-run != 'true'
136132
id: git_info
@@ -148,19 +144,33 @@ runs:
148144
echo "🔍 Git Commit ID: $COMMIT_ID"
149145
echo "🔍 Git URL: $GIT_URL"
150146
151-
- name: Preview Facets Module
147+
- name: FTF Login
148+
if: env.dirs != '' && inputs.dry-run != 'true'
149+
shell: bash
150+
run: |
151+
echo "✅ Login to CP using ftf"
152+
ftf login -c "${{ inputs.control_plane_url }}" -u "${{ inputs.username }}" -t "${{ inputs.token }}" -p default
153+
154+
- name: FTF Validate Directory
155+
if: env.dirs != '' && inputs.dry-run == 'true'
156+
shell: bash
157+
run: |
158+
for dir in $dirs; do
159+
if [[ -f "$dir/facets.yaml" ]]; then
160+
echo "⏳ Validating Facets Module in directory $dir"
161+
ftf validate-directory $dir --check-only --skip-terraform-validation "${{ inputs.skip-terraform-validation }}"
162+
echo "✔️ Facets Module in directory $dir validated successfully."
163+
fi
164+
done
165+
166+
167+
- name: Register Facets Module
152168
if: env.dirs != '' && inputs.dry-run != 'true'
153169
shell: bash
154170
run: |
155171
for dir in $dirs; do
156172
if [[ -f "$dir/facets.yaml" ]]; then
157-
echo "🔍 Registering Facets module for preview in $dir..."
158-
curl -s https://facets-cloud.github.io/facets-schemas/scripts/module_register.sh | bash -s -- \
159-
-c "${{ inputs.control_plane_url }}" \
160-
-u "${{ inputs.username }}" \
161-
-t "${{ inputs.token }}" \
162-
-p "$dir" -a \
163-
-g "${{ env.git_url }}" \
164-
-r "${{ env.commit_id }}"
173+
echo "🔍 Registering Facets module for $([ \"${{ inputs.publish }}\" = \"true\" ] && echo publishing || echo preview) in $dir..."
174+
ftf preview-module $dir -a "${{ inputs.auto-create-intent }}" -r "${{ env.commit_id }}" -g "${{ env.git_url }}" --publish "${{ inputs.publish }}" --publishable "${{ inputs.publishable }}" --profile default --skip-terraform-validation "${{ inputs.skip-terraform-validation }}"
165175
fi
166176
done

module-preview-action/test/ecs_service/facets.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ intent: ecs_service
22
flavor: rohit-ecs-service
33
clouds:
44
- aws
5-
6-
version: 1.0
7-
5+
description : "test"
6+
version: "1.0"
87
spec:
98
type: object
109
properties:
1110
image:
1211
type: string
1312
description: "The Docker image to use for the ECS service."
1413
required: ["image"]
15-
1614
inputs:
1715
ecs_cluster_details:
18-
type: "@output/ecs_cluster_details"
16+
type: "@outputs/ecs_cluster_details"
1917
aws_vpc_details:
20-
type: "@output/aws_vpc_details"
21-
18+
type: "@outputs/aws_vpc_details"
2219
outputs:
2320
default:
24-
type: "@output/ecs_service_details"
25-
21+
type: "@outputs/ecs_service_details"
2622
sample:
2723
kind: ecs_service
2824
flavor: rohit-ecs-service

0 commit comments

Comments
 (0)