-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (87 loc) · 3.07 KB
/
flux-diff.yaml
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
name: "Flux Diff"
on:
pull_request:
branches: [main]
paths: [kubernetes/**]
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
jobs:
flux-diff:
name: Flux Diff
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
strategy:
fail-fast: false
matrix:
resource: [HelmRelease, Kustomization]
cluster: [gabernetes, tennant]
sources: [home-ops]
steps:
- name: Setup Flux CLI
uses: fluxcd/flux2/[email protected]
- id: resource
env:
RESOURCE: ${{ matrix.resource }}
run: echo "resource=${RESOURCE@L}" >> $GITHUB_OUTPUT
- uses: allenporter/flux-local/action/[email protected]
with:
path: kubernetes/${{ matrix.cluster }}
resource: ${{ steps.resource.outputs.resource }}
strip-attrs: helm.sh/chart,checksum/config,app.kubernetes.io/version,chart
sources: ${{ matrix.sources }}
live-branch: ${{ github.event.pull_request.base.sha }}
- name: Generate Diff
id: diff
run: |
cat diff.patch
echo "diff<<EOF" >> $GITHUB_OUTPUT
cat diff.patch >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "added=$(grep -c '^+[^+]' diff.patch)" >> $GITHUB_OUTPUT
echo "removed=$(grep -c '^-[^-]' diff.patch)" >> $GITHUB_OUTPUT
- if: ${{ steps.diff.outputs.diff != '' || failure() }}
name: Add comment
uses: mshick/add-pr-comment@v2
with:
message-id: ${{ github.event.pull_request.number }}/${{ matrix.cluster }}/${{ steps.resource.outputs.resource }}
message-failure: |
## ${{ matrix.resource }} Diff
<table>
<tr>
<td><b>Cluster</b></td>
<td><code>${{ matrix.cluster }}</code></td>
</tr>
</table>
> [!CAUTION]
> Failed to create diff. [View log.](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
message: |
## ${{ matrix.resource }} Diff
<table>
<tr>
<td><b>Cluster</b></td>
<td><code>${{ matrix.cluster }}</code></td>
</tr>
<tr>
<td><b>Changes</b></td>
<td>${\tt\large\color{green}+${{ steps.diff.outputs.added }}\enspace\color{red}-\negthinspace${{ steps.diff.outputs.removed }}}$</td>
</tr>
</table>
<details>
<summary>Click to expand</summary>
```diff
${{ steps.diff.outputs.diff }}
```
</details>
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
flux-diff-success:
name: Flux Diff Successful
runs-on: ubuntu-24.04
needs: [flux-diff]
if: ${{ always() }}
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
name: Check matrix status
run: exit 1