|
1 | | -name: OpenTofu Tests, Plan & Apply |
| 1 | +name: OpenTofu |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
8 | 8 | branches: |
9 | 9 | - main |
10 | 10 |
|
11 | | -permissions: |
12 | | - contents: read |
13 | | - pull-requests: write |
14 | | - |
15 | | -env: |
16 | | - SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }} |
17 | | - |
18 | 11 | jobs: |
19 | | - test: |
20 | | - name: Pre-commit Tests |
21 | | - runs-on: ubuntu-latest |
22 | | - container: |
23 | | - image: ghcr.io/makeitworkcloud/runner:latest |
24 | | - steps: |
25 | | - - name: Checkout |
26 | | - uses: actions/checkout@v4 |
27 | | - with: |
28 | | - fetch-depth: 0 |
29 | | - |
30 | | - - name: Initialize OpenTofu |
31 | | - run: tofu init -backend=false |
32 | | - |
33 | | - - name: Run tests |
34 | | - run: make test |
35 | | - |
36 | | - - name: Show README.md changes after pre-commit |
37 | | - run: | |
38 | | - echo "=== Git status after pre-commit ===" |
39 | | - git status --porcelain |
40 | | - echo "=== Git diff after pre-commit ===" |
41 | | - git diff HEAD |
42 | | - echo "=== README.md content after pre-commit ===" |
43 | | - cat README.md | head -50 |
44 | | -
|
45 | | - plan: |
46 | | - name: OpenTofu Plan |
47 | | - runs-on: ubuntu-latest |
48 | | - container: |
49 | | - image: ghcr.io/makeitworkcloud/runner:latest |
50 | | - if: github.event_name == 'pull_request' |
51 | | - needs: [test] |
52 | | - steps: |
53 | | - - name: Checkout |
54 | | - uses: actions/checkout@v4 |
55 | | - |
56 | | - - name: OpenTofu Plan |
57 | | - id: plan |
58 | | - run: | |
59 | | - # Run make plan - Makefile will handle writing plan to file |
60 | | - make plan || true |
61 | | -
|
62 | | - # Extract only the plan summary - what will actually change |
63 | | - # Start from "OpenTofu will perform" and take everything after |
64 | | - sed -n '/OpenTofu will perform the following actions:/,$p' plan-output.txt > plan-filtered.txt |
65 | | -
|
66 | | - # If no changes, look for "No changes" message |
67 | | - if [ ! -s plan-filtered.txt ]; then |
68 | | - grep -A 2 "No changes" plan-output.txt > plan-filtered.txt || echo "No plan output found" > plan-filtered.txt |
69 | | - fi |
70 | | -
|
71 | | - # Limit output to last 1000 lines to prevent "Argument list too long" error |
72 | | - # The plan summary with actual changes is at the end, that's what matters |
73 | | - tail -n 1000 plan-filtered.txt > plan-filtered-truncated.txt |
74 | | - mv plan-filtered-truncated.txt plan-filtered.txt |
75 | | -
|
76 | | - - name: Comment PR with Plan |
77 | | - uses: actions/github-script@v7 |
78 | | - if: github.event_name == 'pull_request' |
79 | | - with: |
80 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
81 | | - script: | |
82 | | - const fs = require('fs'); |
83 | | - const planOutput = fs.readFileSync('plan-filtered.txt', 'utf8'); |
84 | | -
|
85 | | - const output = `#### OpenTofu Plan 📋 |
86 | | - \`\`\` |
87 | | - ${planOutput} |
88 | | - \`\`\` |
89 | | - `; |
90 | | - github.rest.issues.createComment({ |
91 | | - issue_number: context.issue.number, |
92 | | - owner: context.repo.owner, |
93 | | - repo: context.repo.repo, |
94 | | - body: output |
95 | | - }); |
96 | | -
|
97 | | - apply: |
98 | | - name: OpenTofu Apply |
99 | | - runs-on: ubuntu-latest |
100 | | - container: |
101 | | - image: ghcr.io/makeitworkcloud/runner:latest |
102 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
103 | | - needs: [test] |
104 | | - environment: production |
105 | | - steps: |
106 | | - - name: Checkout |
107 | | - uses: actions/checkout@v4 |
108 | | - |
109 | | - - name: OpenTofu Apply |
110 | | - run: make apply |
| 12 | + opentofu: |
| 13 | + uses: makeitworkcloud/shared-workflows/.github/workflows/opentofu.yml@main |
| 14 | + secrets: |
| 15 | + SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }} |
0 commit comments