name: Operator Release on: push env: GITHUB_TOKEN: ${{ secrets.CR_PAT }} REGISTRY: ghcr.io GO_VERSION: '1.15' DOCKER_IMAGE_NAME: ${{ github.repository }}-operator BACKUP_IMAGE_NAME: ${{ github.repository }}-crbackup jobs: container: runs-on: ubuntu-18.04 name: Build ${{ matrix.goos }}-${{ matrix.goarch }} strategy: matrix: goos: [ 'linux', 'darwin', 'windows' ] goarch: [ 'amd64' ] steps: - name: Source checkout uses: actions/checkout@v2 - name: Set output id: branch run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/} - name: Semantic Release id: semantic uses: cycjimmy/semantic-release-action@v2 with: dry_run: true semantic_version: 17.0.4 - name: Set version id: version run: | if ${{ steps.semantic.outputs.new_release_published == 'true' }}; then echo ::set-output name=version::${{ steps.semantic.outputs.new_release_version }} else echo ::set-output name=version::${{ steps.branch.outputs.short_ref }} fi - name: Check outputs run: | echo ${{ steps.branch.outputs.short_ref }} echo ${{ steps.version.outputs.version }} - name: Generate Short SHA Container Tag id: vars run: echo "::set-output name=sha_short::SHA-$(git rev-parse --short=12 HEAD)" - name: Cache Docker layers uses: actions/cache@v2 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-op-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx-op- - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ github.actor }} password: ${{ secrets.CR_PAT }} registry: ${{ env.REGISTRY }} - uses: docker/build-push-action@v2 name: onlybuild with: context: . file: ./build/operator/Dockerfile platforms: linux/amd64 tags: ${{ env.REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }},${{ env.REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ steps.branch.outputs.short_ref }} push: false cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,mode=max,dest=/tmp/.buildx-cache outputs: type=local,dest=/tmp/operator build-args: | OS=${{ matrix.goos }} ARCH=${{ matrix.goarch }} VERSION=${{ steps.version.outputs.version }} - uses: actions/upload-artifact@v2 with: name: zitadelctl-${{ matrix.goos }}-${{ matrix.goarch }} path: /tmp/operator/zitadelctl - uses: docker/build-push-action@v2 if: ${{ matrix.goos == 'linux' && matrix.goarch == 'amd64' }} name: buildandpush with: context: . file: ./build/operator/Dockerfile platforms: linux/amd64 tags: ${{ env.REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }},${{ env.REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ steps.branch.outputs.short_ref }} push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,mode=max,dest=/tmp/.buildx-cache build-args: | OS=${{ matrix.goos }} ARCH=${{ matrix.goarch }} VERSION=${{ steps.version.outputs.version }} - uses: docker/build-push-action@v2 if: ${{ matrix.goos == 'linux' && matrix.goarch == 'amd64' }} name: buildandpushcrbackup with: context: . file: ./build/cr-backup/Dockerfile platforms: linux/amd64 tags: ${{ env.REGISTRY }}/${{ env.BACKUP_IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }},${{ env.REGISTRY }}/${{ env.BACKUP_IMAGE_NAME }}:${{ steps.branch.outputs.short_ref }} push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,mode=max,dest=/tmp/.buildx-cache release: runs-on: ubuntu-18.04 needs: [ container ] env: DOCKER_USERNAME: ${{ github.actor }} DOCKER_PASSWORD: ${{ secrets.CR_PAT }} steps: - name: Source checkout uses: actions/checkout@v2 - name: Generate Short SHA Container Tag id: vars run: echo "::set-output name=sha_short::SHA-$(git rev-parse --short=12 HEAD)" - name: Check output run: echo ${{ steps.vars.outputs.sha_short }} - name: Docker Login run: docker login $REGISTRY -u $GITHUB_ACTOR -p $GITHUB_TOKEN - name: Docker Pull short-sha run: docker pull $REGISTRY/$DOCKER_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} - name: Docker Pull short-sha run: docker pull $REGISTRY/$BACKUP_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} - name: Download binaries uses: actions/download-artifact@v2 with: path: .artifacts - name: Semantic Release id: semantic uses: cycjimmy/semantic-release-action@v2 with: dry_run: false semantic_version: 17.0.4 - name: Do something when a new release published if: steps.semantic.outputs.new_release_published == 'true' run: | echo ${{ steps.semantic.outputs.new_release_version }} echo ${{ steps.semantic.outputs.new_release_major_version }} echo ${{ steps.semantic.outputs.new_release_minor_version }} echo ${{ steps.semantic.outputs.new_release_patch_version }} - name: Docker Tag Version run: | docker tag $REGISTRY/$DOCKER_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} $REGISTRY/$DOCKER_IMAGE_NAME:${{ steps.semantic.outputs.new_release_version }} docker tag $REGISTRY/$BACKUP_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} $REGISTRY/$BACKUP_IMAGE_NAME:${{ steps.semantic.outputs.new_release_version }} if: steps.semantic.outputs.new_release_published == 'true' - name: Docker Tag Latest run: | docker tag $REGISTRY/$DOCKER_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} $REGISTRY/$DOCKER_IMAGE_NAME:latest docker tag $REGISTRY/$BACKUP_IMAGE_NAME:${{ steps.vars.outputs.sha_short }} $REGISTRY/$BACKUP_IMAGE_NAME:latest if: steps.semantic.outputs.new_release_published == 'true' - name: Docker Push Version run: | docker push $REGISTRY/$DOCKER_IMAGE_NAME:${{ steps.semantic.outputs.new_release_version }} docker push $REGISTRY/$BACKUP_IMAGE_NAME:${{ steps.semantic.outputs.new_release_version }} if: steps.semantic.outputs.new_release_published == 'true' - name: Docker Push Latest run: | docker push $REGISTRY/$DOCKER_IMAGE_NAME:latest docker push $REGISTRY/$BACKUP_IMAGE_NAME:latest if: steps.semantic.outputs.new_release_published == 'true'