|
| 1 | +name: Build, Test, Publish Image & Manifest |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # branch 'github-actions' is added for fast feedback; will delete after migration work is done |
| 6 | + branches: [ "main", "github-actions" ] |
| 7 | + paths-ignore: |
| 8 | + - 'docs/**' |
| 9 | + - '*.md' |
| 10 | + - 'LICENSE.txt' |
| 11 | + - 'PROJECT' |
| 12 | + - 'hack/**' |
| 13 | + tags: [ "v*" ] |
| 14 | + |
| 15 | +env: |
| 16 | + GO_VERSION: ~1.19 # Require Go 1.19 and above, but lower than Go 2.0.0 |
| 17 | + |
| 18 | +jobs: |
| 19 | + unit_integration_tests: |
| 20 | + name: unit and integration tests |
| 21 | + runs-on: ubuntu-latest |
| 22 | + container: us.gcr.io/cf-rabbitmq-for-k8s-bunny/rabbitmq-for-kubernetes-ci |
| 23 | + steps: |
| 24 | + - name: Install Go |
| 25 | + uses: actions/setup-go@v3 |
| 26 | + with: |
| 27 | + go-version: ${{ env.GO_VERSION }} |
| 28 | + check-latest: true |
| 29 | + - name: Check out code into the Go module directory |
| 30 | + uses: actions/checkout@v3 |
| 31 | + - name: Unit tests |
| 32 | + run: make unit-tests |
| 33 | + - name: Integration tests |
| 34 | + run: make integration-tests |
| 35 | + |
| 36 | + build_operator: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: unit_integration_tests |
| 39 | + permissions: |
| 40 | + contents: 'write' |
| 41 | + id-token: 'write' |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v3 |
| 45 | + - name: Install Go |
| 46 | + uses: actions/setup-go@v3 |
| 47 | + with: |
| 48 | + go-version: ${{ env.GO_VERSION }} |
| 49 | + check-latest: true |
| 50 | + - name: OCI Metadata |
| 51 | + id: meta |
| 52 | + uses: docker/metadata-action@v4 |
| 53 | + with: |
| 54 | + images: rabbitmqoperator/messaging-topology-operator |
| 55 | + # generate Docker tags based on the following events/attributes |
| 56 | + tags: | |
| 57 | + type=edge |
| 58 | + type=sha |
| 59 | + type=ref,event=pr |
| 60 | + type=semver,pattern={{version}} |
| 61 | + type=semver,pattern={{major}}.{{minor}} |
| 62 | + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} |
| 63 | + - name: Set up QEMU |
| 64 | + uses: docker/setup-qemu-action@v2 |
| 65 | + - name: Set up Docker Buildx |
| 66 | + uses: docker/setup-buildx-action@v2 |
| 67 | + - name: Login to Docker Hub |
| 68 | + if: github.event_name != 'pull_request' |
| 69 | + uses: docker/login-action@v2 |
| 70 | + with: |
| 71 | + # github action secrets are saved in the repo |
| 72 | + # see github documentation on how to manage and access action secrets |
| 73 | + # https://docs.github.com/en/actions/security-guides/encrypted-secrets |
| 74 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 75 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 76 | + - name: Build and push |
| 77 | + uses: docker/build-push-action@v3 |
| 78 | + with: |
| 79 | + context: . |
| 80 | + push: true |
| 81 | + platforms: linux/amd64, linux/arm64 |
| 82 | + tags: ${{ steps.meta.outputs.tags }} |
| 83 | + labels: ${{ steps.meta.outputs.labels }} |
| 84 | + - name: Build manifest |
| 85 | + env: |
| 86 | + RELEASE_VERSION: ${{ steps.meta.outputs.version }} |
| 87 | + run: | |
| 88 | + make install-tools |
| 89 | + pushd config/installation |
| 90 | + kustomize edit set image \ |
| 91 | + rabbitmqoperator/messaging-topology-operator-dev=rabbitmqoperator/messaging-topology-operator:"${RELEASE_VERSION}" |
| 92 | + popd |
| 93 | + pushd config/installation/cert-manager |
| 94 | + kustomize edit set image \ |
| 95 | + rabbitmqoperator/messaging-topology-operator-dev=rabbitmqoperator/messaging-topology-operator:"${RELEASE_VERSION}" |
| 96 | + popd |
| 97 | + make generate-manifests |
| 98 | + - name: Upload operator manifests |
| 99 | + uses: actions/upload-artifact@v3 |
| 100 | + with: |
| 101 | + name: operator-manifests |
| 102 | + path: releases/messaging-topology-operator*.yaml |
| 103 | + retention-days: 2 |
| 104 | + if-no-files-found: error |
| 105 | + - name: Rename manifest for GCS |
| 106 | + run: mv releases/messaging-topology-operator-with-certmanager.yaml messaging-topology-operator-with-certmanager-${{ steps.meta.outputs.version }}.yaml |
| 107 | + - id: 'auth' |
| 108 | + uses: 'google-github-actions/auth@v1' |
| 109 | + with: |
| 110 | + # using workload identity provider to authenticate with GCP |
| 111 | + # workload identity provider configurations can be viewed in GCP console and gcloud cli |
| 112 | + # doc: https://cloud.google.com/blog/products/identity-security/enabling-keyless-authentication-from-github-actions |
| 113 | + workload_identity_provider: ${{ secrets.GCP_IDENTITY_PROVIDER }} |
| 114 | + service_account: ${{ secrets.GCP_SA }} |
| 115 | + - name: Upload manifests to GCS |
| 116 | + uses: 'google-github-actions/upload-cloud-storage@v1' |
| 117 | + with: |
| 118 | + path: messaging-topology-operator-with-certmanager-${{ steps.meta.outputs.version }}.yaml |
| 119 | + destination: operator-manifests-dev |
| 120 | + |
| 121 | + system_tests_gke: |
| 122 | + name: System tests using gke |
| 123 | + runs-on: ubuntu-latest |
| 124 | + container: us.gcr.io/cf-rabbitmq-for-k8s-bunny/rabbitmq-for-kubernetes-ci |
| 125 | + permissions: |
| 126 | + contents: 'write' |
| 127 | + id-token: 'write' |
| 128 | + needs: build_operator |
| 129 | + steps: |
| 130 | + - name: Check out code into the Go module directory |
| 131 | + uses: actions/checkout@v3 |
| 132 | + - uses: actions/setup-go@v3 |
| 133 | + with: |
| 134 | + go-version: ${{ env.GO_VERSION }} |
| 135 | + check-latest: true |
| 136 | + - id: 'auth' |
| 137 | + uses: 'google-github-actions/auth@v1' |
| 138 | + with: |
| 139 | + workload_identity_provider: ${{ secrets.GCP_IDENTITY_PROVIDER }} |
| 140 | + service_account: ${{ secrets.GCP_SA }} |
| 141 | + - id: 'get-credentials' |
| 142 | + uses: 'google-github-actions/get-gke-credentials@v1' |
| 143 | + with: |
| 144 | + cluster_name: messaging-topology-operator-ci |
| 145 | + location: europe-west2-a |
| 146 | + - name: Get operator manifest |
| 147 | + uses: actions/download-artifact@v3 |
| 148 | + with: |
| 149 | + name: operator-manifests |
| 150 | + - name: Install cert-manager and cluster operator |
| 151 | + run: | |
| 152 | + make install-tools |
| 153 | + make cert-manager |
| 154 | + make cluster-operator |
| 155 | + - name: Install operator from build |
| 156 | + run: | |
| 157 | + make destroy |
| 158 | + kubectl apply -f messaging-topology-operator-with-certmanager.yaml |
| 159 | + kubectl --namespace=rabbitmq-system wait --for=condition=Available deployment/messaging-topology-operator |
| 160 | + - name: System tests |
| 161 | + run: | |
| 162 | + make system-tests |
| 163 | +
|
| 164 | + release: |
| 165 | + name: Release to GitHub Releases |
| 166 | + runs-on: ubuntu-latest |
| 167 | + # triggered by git tags, not pushes |
| 168 | + if: startsWith(github.ref, 'refs/tags/v') |
| 169 | + needs: system_tests_gke |
| 170 | + steps: |
| 171 | + - name: Checkout |
| 172 | + uses: actions/checkout@v2 |
| 173 | + - name: Get operator manifest |
| 174 | + uses: actions/download-artifact@v3 |
| 175 | + with: |
| 176 | + name: operator-manifests |
| 177 | + - name: Get release header |
| 178 | + uses: actions/download-artifact@v3 |
| 179 | + with: |
| 180 | + name: release-header |
| 181 | + - name: Release |
| 182 | + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 |
| 183 | + if: startsWith(github.ref, 'refs/tags/') |
| 184 | + with: |
| 185 | + files: | |
| 186 | + messaging-topology-operator.yml |
| 187 | + messaging-topology-operator-with-certmanager.yml |
| 188 | + generate_release_notes: true |
| 189 | + draft: true |
| 190 | + body_path: release-header.md |
| 191 | + fail_on_unmatched_files: true |
| 192 | + |
0 commit comments