main.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. name: main-ci
  2. on:
  3. push:
  4. branches: [ main ]
  5. tags:
  6. - '*'
  7. pull_request:
  8. branches: [ main ]
  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. test:
  31. name: Test
  32. container:
  33. image: golang:1.15
  34. runs-on: ubuntu-latest
  35. steps:
  36. - name: Check out code into the Go module directory
  37. uses: actions/checkout@v2
  38. - name: Get dependencies
  39. run: |
  40. go get -v -t -d ./...
  41. - name: Add kubebuilder
  42. run: |
  43. 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
  44. tar -xvf kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  45. mv kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64 /usr/local/kubebuilder
  46. - name: Test
  47. run: make test
  48. - name: Coverage
  49. uses: codecov/codecov-action@v1
  50. with:
  51. # token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
  52. file: ./cover.out
  53. # flags: unittests # optional
  54. name: external-secrets
  55. fail_ci_if_error: true
  56. docker:
  57. name: Docker
  58. runs-on: ubuntu-latest
  59. needs: [build, test]
  60. steps:
  61. - name: Prepare
  62. id: prep
  63. run: |
  64. DOCKER_IMAGE=ghcr.io/external-secrets/external-secrets
  65. VERSION=edge
  66. if [[ $GITHUB_REF == refs/tags/* ]]; then
  67. VERSION=${GITHUB_REF#refs/tags/}
  68. elif [[ $GITHUB_REF == refs/heads/* ]]; then
  69. VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
  70. elif [[ $GITHUB_REF == refs/pull/* ]]; then
  71. VERSION=pr-${{ github.event.number }}
  72. fi
  73. TAGS="${DOCKER_IMAGE}:${VERSION}"
  74. if [ "${{ github.event_name }}" = "push" ]; then
  75. TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
  76. fi
  77. PUSH_IMAGE=true
  78. REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
  79. # If this is both a pull request and a fork, then don't push the image
  80. if [[ ${{ github.event_name }} == pull_request ]]; then
  81. if [[ $REPO_FULL_NAME != external-secrets/external-secrets ]]; then
  82. PUSH_IMAGE=false
  83. fi
  84. fi
  85. REPO_URL=https://github.com/${{github.repository}}
  86. echo ::set-output name=version::${VERSION}
  87. echo ::set-output name=tags::${TAGS}
  88. echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
  89. echo ::set-output name=push_image::$PUSH_IMAGE
  90. echo ::set-output name=repo_url::$REPO_URL
  91. - name: Check out the repo
  92. uses: actions/checkout@v2
  93. - name: Set up QEMU
  94. id: qemu
  95. uses: docker/setup-qemu-action@v1
  96. with:
  97. platforms: linux/amd64
  98. - name: Set up Docker Buildx
  99. id: buildx
  100. uses: docker/setup-buildx-action@v1
  101. - name: Login to Github Packages
  102. id: docker-login
  103. uses: docker/login-action@v1
  104. with:
  105. registry: ghcr.io
  106. username: ${{ secrets.GHCR_USERNAME }}
  107. password: ${{ secrets.GHCR_TOKEN }}
  108. if: ${{ steps.prep.outputs.push_image == 'true' }}
  109. - name: Build and push
  110. id: docker_build
  111. uses: docker/build-push-action@v2
  112. with:
  113. context: .
  114. file: ./Dockerfile
  115. builder: ${{ steps.buildx.outputs.name }}
  116. platforms: linux/amd64
  117. tags: ${{ steps.prep.outputs.tags }}
  118. push: ${{ steps.prep.outputs.push_image }}
  119. labels: |
  120. org.opencontainers.image.source=${{ steps.prep.outputs.repo_url }}
  121. org.opencontainers.image.created=${{ steps.prep.outputs.created }}
  122. org.opencontainers.image.revision=${{ github.sha }}
  123. - name: Image digest
  124. run: echo ${{ steps.docker_build.outputs.digest }}