|
| 1 | +--- |
| 2 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 3 | +name: "Flux Local" |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + pre-job: |
| 15 | + name: Flux Local Pre-Job |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + any_changed: ${{ steps.changed-files.outputs.any_changed }} |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Get Changed Files |
| 24 | + id: changed-files |
| 25 | + uses: tj-actions/changed-files@v45 |
| 26 | + with: |
| 27 | + files: kubernetes/** |
| 28 | + |
| 29 | + test: |
| 30 | + name: Flux Local Test |
| 31 | + needs: pre-job |
| 32 | + runs-on: ubuntu-latest |
| 33 | + if: ${{ needs.pre-job.outputs.any_changed == 'true' }} |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Run flux-local test |
| 39 | + uses: docker://ghcr.io/allenporter/flux-local:v7.2.1 |
| 40 | + with: |
| 41 | + args: test --enable-helm --all-namespaces --path /github/workspace/kubernetes/flux/cluster -v |
| 42 | + |
| 43 | + diff: |
| 44 | + name: Flux Local Diff |
| 45 | + needs: pre-job |
| 46 | + runs-on: ubuntu-latest |
| 47 | + permissions: |
| 48 | + pull-requests: write |
| 49 | + strategy: |
| 50 | + matrix: |
| 51 | + resources: ["helmrelease", "kustomization"] |
| 52 | + max-parallel: 4 |
| 53 | + fail-fast: false |
| 54 | + if: ${{ needs.pre-job.outputs.any_changed == 'true' }} |
| 55 | + steps: |
| 56 | + - name: Checkout Pull Request Branch |
| 57 | + uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + path: pull |
| 60 | + |
| 61 | + - name: Checkout Default Branch |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + ref: "${{ github.event.repository.default_branch }}" |
| 65 | + path: default |
| 66 | + |
| 67 | + - name: Run flux-local diff |
| 68 | + uses: docker://ghcr.io/allenporter/flux-local:v7.2.1 |
| 69 | + with: |
| 70 | + args: >- |
| 71 | + diff ${{ matrix.resources }} |
| 72 | + --unified 6 |
| 73 | + --path /github/workspace/pull/kubernetes/flux/cluster |
| 74 | + --path-orig /github/workspace/default/kubernetes/flux/cluster |
| 75 | + --strip-attrs "helm.sh/chart,checksum/config,app.kubernetes.io/version,chart" |
| 76 | + --limit-bytes 10000 |
| 77 | + --all-namespaces |
| 78 | + --sources "flux-system" |
| 79 | + --output-file diff.patch |
| 80 | +
|
| 81 | + - name: Generate Diff |
| 82 | + id: diff |
| 83 | + run: | |
| 84 | + cat diff.patch; |
| 85 | + { |
| 86 | + echo 'diff<<EOF' |
| 87 | + cat diff.patch |
| 88 | + echo EOF |
| 89 | + } >> "$GITHUB_OUTPUT"; |
| 90 | + { |
| 91 | + echo "### Diff" |
| 92 | + echo '```diff' |
| 93 | + cat diff.patch |
| 94 | + echo '```' |
| 95 | + } >> "$GITHUB_STEP_SUMMARY" |
| 96 | +
|
| 97 | + - name: Add Comment |
| 98 | + if: ${{ steps.diff.outputs.diff != '' }} |
| 99 | + continue-on-error: true |
| 100 | + uses: mshick/add-pr-comment@v2 |
| 101 | + with: |
| 102 | + message-id: "${{ github.event.pull_request.number }}/kubernetes/${{ matrix.resources }}" |
| 103 | + message-failure: Diff was not successful |
| 104 | + message: | |
| 105 | + ```diff |
| 106 | + ${{ steps.diff.outputs.diff }} |
| 107 | + ``` |
| 108 | +
|
| 109 | + flux-local-status: |
| 110 | + name: Flux Local Success |
| 111 | + needs: ["test", "diff"] |
| 112 | + runs-on: ubuntu-latest |
| 113 | + if: ${{ always() }} |
| 114 | + steps: |
| 115 | + - name: Any jobs failed? |
| 116 | + if: ${{ contains(needs.*.result, 'failure') }} |
| 117 | + run: exit 1 |
| 118 | + |
| 119 | + - name: All jobs passed or skipped? |
| 120 | + if: ${{ !(contains(needs.*.result, 'failure')) }} |
| 121 | + run: echo "All jobs passed or skipped" && echo "${{ toJSON(needs.*.result) }}" |
0 commit comments