main.yml 4.6 KB

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