main.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. name: CI
  2. on:
  3. push:
  4. branches: [ master ]
  5. tags:
  6. - '*'
  7. pull_request:
  8. branches: [ master ]
  9. env:
  10. KUBEBUILDER_VERSION: 2.3.1
  11. jobs:
  12. build:
  13. name: Build
  14. container:
  15. image: golang:1.15
  16. runs-on: ubuntu-latest
  17. steps:
  18. - name: Check out code into the Go module directory
  19. uses: actions/checkout@v2
  20. - name: Get dependencies
  21. run: |
  22. go get -v -t -d ./...
  23. - name: Add kubebuilder
  24. run: |
  25. curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${{env.KUBEBUILDER_VERSION}}/kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz > kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  26. tar -xvf kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  27. mv kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64 /usr/local/kubebuilder
  28. - name: Vet and Build
  29. run: make manager
  30. - name: Test
  31. run: make test
  32. - name: Coverage
  33. uses: codecov/codecov-action@v1
  34. with:
  35. # token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
  36. file: ./cover.out
  37. # flags: unittests # optional
  38. name: externalsecret-operator
  39. fail_ci_if_error: true
  40. docker:
  41. name: Docker
  42. runs-on: ubuntu-latest
  43. needs: build
  44. steps:
  45. - name: Prepare
  46. id: prep
  47. run: |
  48. DOCKER_IMAGE=ghcr.io/external-secrets/external-secrets
  49. VERSION=edge
  50. if [[ $GITHUB_REF == refs/tags/* ]]; then
  51. VERSION=${GITHUB_REF#refs/tags/}
  52. elif [[ $GITHUB_REF == refs/heads/* ]]; then
  53. VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
  54. elif [[ $GITHUB_REF == refs/pull/* ]]; then
  55. VERSION=pr-${{ github.event.number }}
  56. fi
  57. TAGS="${DOCKER_IMAGE}:${VERSION}"
  58. if [ "${{ github.event_name }}" = "push" ]; then
  59. TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
  60. fi
  61. PUSH_IMAGE=true
  62. REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
  63. # If this is both a pull request and a fork, then don't push the image
  64. if [[ ${{ github.event_name }} == pull_request ]]; then
  65. if [[ $REPO_FULL_NAME != external-secrets/xternal-secrets ]]; then
  66. PUSH_IMAGE=false
  67. fi
  68. fi
  69. echo ::set-output name=version::${VERSION}
  70. echo ::set-output name=tags::${TAGS}
  71. echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
  72. echo ::set-output name=push_image::$PUSH_IMAGE
  73. - name: Check out the repo
  74. uses: actions/checkout@v2
  75. - name: Set up QEMU
  76. id: qemu
  77. uses: docker/setup-qemu-action@v1
  78. with:
  79. platforms: all
  80. - name: Set up Docker Buildx
  81. id: buildx
  82. uses: docker/setup-buildx-action@v1
  83. - name: Login to Github Packages
  84. id: docker-login
  85. uses: docker/login-action@v1
  86. with:
  87. registry: docker.pkg.github.com
  88. username: external-secrets
  89. password: ${{ secrets.GITHUB_TOKEN }}
  90. if: ${{ steps.prep.outputs.push_image == 'true' }}
  91. - name: Build and push
  92. id: docker_build
  93. uses: docker/build-push-action@v2
  94. with:
  95. context: .
  96. file: ./Dockerfile
  97. builder: ${{ steps.buildx.outputs.name }}
  98. platforms: linux/amd64,linux/arm/v7,linux/arm64
  99. tags: ${{ steps.prep.outputs.tags }}
  100. push: ${{ steps.prep.outputs.push_image }}
  101. labels: |
  102. org.opencontainers.image.source=${{ github.event.repository.clone_url }}
  103. org.opencontainers.image.created=${{ steps.prep.outputs.created }}
  104. org.opencontainers.image.revision=${{ github.sha }}
  105. - name: Image digest
  106. run: echo ${{ steps.docker_build.outputs.digest }}