|
| 1 | +--- |
| 2 | +name: unittest |
| 3 | +on: # yamllint disable-line rule:truthy |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + go: |
| 13 | + name: go |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + pull-requests: write |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - uses: actions/setup-go@v5 |
| 21 | + with: |
| 22 | + go-version: '1.21' |
| 23 | + - name: Install dependencies |
| 24 | + run: | |
| 25 | + go get . |
| 26 | + - name: Build |
| 27 | + run: make build |
| 28 | + - name: Run Go tests |
| 29 | + run: make test |
| 30 | + - name: Code Coverage Report |
| 31 | + |
| 32 | + with: |
| 33 | + filename: coverage.xml |
| 34 | + badge: true |
| 35 | + fail_below_min: true |
| 36 | + format: markdown |
| 37 | + hide_branch_rate: false |
| 38 | + hide_complexity: true |
| 39 | + indicators: true |
| 40 | + output: both |
| 41 | + thresholds: '60 80' |
| 42 | + - uses: jwalton/gh-find-current-pr@v1 |
| 43 | + id: finder |
| 44 | + - name: Add Coverage PR Comment |
| 45 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 46 | + with: |
| 47 | + number: ${{ steps.finder.outputs.pr }} |
| 48 | + path: code-coverage-results.md |
| 49 | + recreate: true |
| 50 | + - name: Upload artifact |
| 51 | + uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: binary |
| 54 | + path: postgresql-partition-manager |
| 55 | + if-no-files-found: error |
| 56 | + retention-days: 1 |
| 57 | + |
| 58 | + e2e: |
| 59 | + name: End-to-end |
| 60 | + needs: go |
| 61 | + strategy: |
| 62 | + matrix: |
| 63 | + postgres: |
| 64 | + - postgres:14 |
| 65 | + - postgres:15 |
| 66 | + - postgres:16 |
| 67 | + runs-on: ubuntu-latest |
| 68 | + env: |
| 69 | + BATS_LIB_PATH: "${{ github.workspace }}/test/bats/lib/" |
| 70 | + PGHOST: localhost |
| 71 | + PGUSER: postgres |
| 72 | + PGPASSWORD: hackme |
| 73 | + PGDATABASE: unittest |
| 74 | + services: |
| 75 | + postgres: |
| 76 | + image: ${{ matrix.postgres }} |
| 77 | + options: >- |
| 78 | + --health-cmd pg_isready |
| 79 | + --health-interval 10s |
| 80 | + --health-timeout 5s |
| 81 | + --health-retries 5 |
| 82 | + --hostname postgres |
| 83 | + env: |
| 84 | + POSTGRES_PASSWORD: hackme |
| 85 | + ports: |
| 86 | + - 5432:5432 |
| 87 | + |
| 88 | + steps: |
| 89 | + - uses: actions/checkout@v4 |
| 90 | + |
| 91 | + - name: Setup Bats and bats libs |
| 92 | + |
| 93 | + with: |
| 94 | + support-path: ${{ github.workspace }}/test/bats/lib/bats-support |
| 95 | + assert-path: ${{ github.workspace }}/test/bats/lib/bats-assert |
| 96 | + file-install: false # Unused |
| 97 | + detik-install: false # Unused |
| 98 | + |
| 99 | + - name: Download artifact |
| 100 | + uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + name: binary |
| 103 | + |
| 104 | + # File permissions are not maintained during artifact upload/download |
| 105 | + - name: Move binary to local executable |
| 106 | + run: mv postgresql-partition-manager /usr/local/bin && chmod +x /usr/local/bin/postgresql-partition-manager |
| 107 | + |
| 108 | + - name: Run bats |
| 109 | + run: make bats-test |
| 110 | + |
| 111 | + helm: |
| 112 | + name: helm |
| 113 | + runs-on: ubuntu-latest |
| 114 | + env: |
| 115 | + HELM_UNITTEST_VERSION: v0.3.5 |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + - name: Install helm-unittest |
| 119 | + run: helm plugin install --version $HELM_UNITTEST_VERSION https://github.com/helm-unittest/helm-unittest.git |
| 120 | + - name: Run Helm test |
| 121 | + run: make helm-test |
| 122 | + |
| 123 | + kubeconform: |
| 124 | + name: kubeconform |
| 125 | + runs-on: ubuntu-latest |
| 126 | + env: |
| 127 | + KUBECONFORM_VERSION: 0.6.2 |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v4 |
| 130 | + - name: Install kubeconform |
| 131 | + run: | |
| 132 | + curl -sSLo /tmp/kubeconform.tar.gz "https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz" \ |
| 133 | + && tar -C /usr/local/bin/ -xzvf /tmp/kubeconform.tar.gz |
| 134 | + - name: Run Kubeconform test |
| 135 | + run: make kubeconform-test |
| 136 | + |
| 137 | + debian: |
| 138 | + runs-on: ubuntu-latest |
| 139 | + steps: |
| 140 | + - name: Checkout repository |
| 141 | + uses: actions/checkout@v4 |
| 142 | + with: |
| 143 | + fetch-depth: 0 |
| 144 | + - uses: actions/setup-go@v5 |
| 145 | + with: |
| 146 | + go-version: stable |
| 147 | + - name: Set up QEMU for ARM64 build |
| 148 | + uses: docker/setup-qemu-action@v3 |
| 149 | + - uses: goreleaser/goreleaser-action@v5 |
| 150 | + with: |
| 151 | + distribution: goreleaser |
| 152 | + version: latest |
| 153 | + args: release --clean --skip=publish --skip=docker --snapshot |
| 154 | + env: |
| 155 | + GORELEASER_CURRENT_TAG: 0.0.0 |
| 156 | + - name: Run Debian package tests |
| 157 | + run: make debian-test-ci |
| 158 | + |
| 159 | +# checkcov: |
| 160 | +# permissions: |
| 161 | +# security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
| 162 | +# actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status |
| 163 | +# runs-on: ubuntu-latest |
| 164 | +# steps: |
| 165 | +# - uses: actions/checkout@v4 |
| 166 | +# - name: Checkov GitHub Action |
| 167 | +# uses: bridgecrewio/checkov-action@v12 |
| 168 | +# with: |
| 169 | +# # This will add both a CLI output to the console and create a results.sarif file |
| 170 | +# output_format: cli,sarif |
| 171 | +# output_file_path: console,results.sarif |
| 172 | +# - name: Upload SARIF file |
| 173 | +# uses: github/codeql-action/upload-sarif@v3 |
| 174 | +# # Results are generated only on a success or failure |
| 175 | +# # this is required since GitHub by default won't run the next step |
| 176 | +# # when the previous one has failed. Security checks that do not pass will 'fail'. |
| 177 | +# # An alternative is to add `continue-on-error: true` to the previous step |
| 178 | +# # Or 'soft_fail: true' to checkov. |
| 179 | +# if: success() || failure() |
| 180 | +# with: |
| 181 | +# sarif_file: results.sarif |
0 commit comments