-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
109 lines (92 loc) · 3.48 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: 'Solarboat CLI Action'
description: 'Run Solarboat CLI commands in your GitHub Actions workflow'
branding:
icon: 'anchor'
color: 'blue'
inputs:
command:
description: 'Command to run (scan, plan, or apply)'
required: true
plan_output_dir:
description: 'Directory to save Terraform plan files'
default: 'terraform-plans'
required: false
apply_dry_run:
description: 'Run apply in dry-run mode (enabled by default for safety)'
default: 'true'
required: false
ignore_workspaces:
description: 'Comma-separated list of workspaces to ignore'
required: false
default: ''
github_token:
description: 'GitHub token for PR comments'
required: true
runs:
using: 'composite'
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.4"
- name: Install Solarboat CLI
shell: bash
run: |
# Install Solarboat CLI using cargo
cargo install solarboat
# Verify installation
solarboat --version || (echo "Installation failed" && exit 1)
- name: Run Solarboat CLI
shell: bash
run: |
echo "🚀 Running Solarboat CLI"
# Build the ignore workspaces argument if provided
IGNORE_WORKSPACES_ARG=""
if [ ! -z "${{ inputs.ignore_workspaces }}" ]; then
IGNORE_WORKSPACES_ARG="--ignore-workspaces ${{ inputs.ignore_workspaces }}"
fi
if [[ "${{ inputs.command }}" == "scan" ]]; then
solarboat scan
elif [[ "${{ inputs.command }}" == "plan" ]]; then
solarboat plan --output-dir ${{ inputs.plan_output_dir }} $IGNORE_WORKSPACES_ARG
elif [[ "${{ inputs.command }}" == "apply" ]]; then
solarboat apply --dry-run=${{ inputs.apply_dry_run }} $IGNORE_WORKSPACES_ARG
else
echo "❌ Invalid command: ${{ inputs.command }}"
exit 1
fi
- name: Upload Terraform Plans
if: inputs.command == 'plan'
uses: actions/upload-artifact@v4
with:
name: terraform-plans
path: ${{ inputs.plan_output_dir }}/
retention-days: 5
- name: Comment on PR
if: github.event_name == 'pull_request' && inputs.command == 'plan'
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github_token }}
script: |
const artifactUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/artifacts`;
const comment = `## 🚀 Solarboat CLI Results
Solarboat has analyzed your Terraform changes and generated plans.
### 📋 Summary
- ✨ Plans have been generated and uploaded as artifacts
- 🔍 Review the plans before merging
- ⏱️ Plans will be retained for 5 days
### 🔗 Links
- [View Plan Artifacts](${artifactUrl})
### ℹ️ Next Steps
1. Download and review the plan artifacts
2. Address any issues found in the plans
3. Merge the PR when ready
> Note: Check the action logs for detailed module processing information.`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});