-
-
Notifications
You must be signed in to change notification settings - Fork 44
107 lines (95 loc) · 2.87 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
101
102
103
104
105
106
107
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Flux Diff"
on:
pull_request:
branches:
- main
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
changed-files:
name: Get Changed Files
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: kubernetes/**
dir_names: true
dir_names_max_depth: 2
json: true
quotepath: false
escape_json: false
- name: List all changed files
run: echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
flux-diff:
name: Flux Diff
runs-on: ubuntu-latest
needs:
- changed-files
permissions:
pull-requests: write
if: ${{ needs.changed-files.outputs.matrix != '[]' }}
strategy:
matrix:
paths: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
resources:
- helmrelease
- kustomization
steps:
- name: Generate Token
uses: actions/create-github-app-token@v1
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
id: app-token
with:
app-id: ${{ secrets.BJWS_APP_ID }}
private-key: ${{ secrets.BJWS_APP_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
- name: Install Flux
uses: fluxcd/flux2/action@main
with:
version: "latest"
- name: Setup yq
uses: frenck/action-setup-yq@v1
- name: Diff Resources
uses: allenporter/flux-local/action/[email protected]
id: diff
with:
sources: home-ops-kubernetes
path: "${{ matrix.paths }}"
resource: "${{ matrix.resources }}"
- name: Add comment
if: ${{ steps.diff.outputs.diff != '' && github.event.pull_request.head.repo.full_name == github.repository }}
uses: mshick/[email protected]
with:
repo-token: "${{ steps.app-token.outputs.token }}"
message-id: "${{ github.event.pull_request.number }}/${{ matrix.paths }}/${{ matrix.resources }}"
message-failure: Diff was not successful
message: |
```diff
${{ steps.diff.outputs.diff }}
```
flux-diff-success:
needs:
- flux-diff
if: ${{ always() }}
name: Flux Diff successful
runs-on: ubuntu-latest
steps:
- name: Check matrix status
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
}}
run: exit 1