main.yml 4.6 KB

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