|
| 1 | +# workflow to release assets as part of the release |
| 2 | +name: Upload Release Asset |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | +env: |
| 8 | + REGISTRY: ghcr.io |
| 9 | + IMAGE_NAME: ${{ github.repository }} |
| 10 | +jobs: |
| 11 | + manager-image: |
| 12 | + name: Build and push manager image |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + |
| 17 | + - uses: ./.github/actions/setup-go |
| 18 | + - name: Set up QEMU |
| 19 | + uses: docker/setup-qemu-action@v1 |
| 20 | + - name: Set up Docker Buildx |
| 21 | + uses: docker/setup-buildx-action@v1 |
| 22 | + - name: Cache Docker layers |
| 23 | + uses: actions/cache@v2 |
| 24 | + with: |
| 25 | + path: /tmp/.buildx-cache |
| 26 | + key: ${{ runner.os }}-buildx-manager-${{ github.sha }} |
| 27 | + restore-keys: | |
| 28 | + ${{ runner.os }}-buildx-manager- |
| 29 | + ${{ runner.os }}-buildx- |
| 30 | + - name: Docker manager metadata |
| 31 | + id: meta |
| 32 | + uses: docker/metadata-action@v3 |
| 33 | + with: |
| 34 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 35 | + flavor: latest=false |
| 36 | + tags: type=ref,event=tag |
| 37 | + - name: Log in to the Container registry |
| 38 | + uses: docker/login-action@v1 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + - name: Setup Env |
| 44 | + run: | |
| 45 | + DOCKER_BUILD_LDFLAGS="$(hack/version.sh)" |
| 46 | + echo 'DOCKER_BUILD_LDFLAGS<<EOF' >> $GITHUB_ENV |
| 47 | + echo $DOCKER_BUILD_LDFLAGS >> $GITHUB_ENV |
| 48 | + echo 'EOF' >> $GITHUB_ENV |
| 49 | + - name: Build and push manager image |
| 50 | + uses: docker/build-push-action@v2 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + push: true |
| 54 | + build-args: | |
| 55 | + LDFLAGS=${{ env.DOCKER_BUILD_LDFLAGS }} |
| 56 | + tags: ${{ steps.meta.outputs.tags }} |
| 57 | + labels: ${{ steps.meta.outputs.labels }} |
| 58 | + platforms: linux/amd64,linux/arm64 |
| 59 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 60 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 61 | + - name: Move cache |
| 62 | + # Temp fix |
| 63 | + # https://github.com/docker/build-push-action/issues/252 |
| 64 | + # https://github.com/moby/buildkit/issues/1896 |
| 65 | + run: | |
| 66 | + rm -rf /tmp/.buildx-cache |
| 67 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 68 | + release: |
| 69 | + name: Release |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: |
| 72 | + - manager-image |
| 73 | + steps: |
| 74 | + - name: Checkout code |
| 75 | + |
| 76 | + - uses: ./.github/actions/setup-go |
| 77 | + - uses: actions/cache@v2 |
| 78 | + with: |
| 79 | + path: hack/tools/bin |
| 80 | + key: ${{ runner.os }}-tools-bin-release-${{ hashFiles('Makefile') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-tools-bin-release- |
| 83 | + ${{ runner.os }}-tools-bin- |
| 84 | + - name: Docker manager metadata |
| 85 | + id: meta |
| 86 | + uses: docker/metadata-action@v3 |
| 87 | + with: |
| 88 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 89 | + flavor: latest=false |
| 90 | + tags: type=ref,event=tag |
| 91 | + - name: manifest |
| 92 | + run: make release |
| 93 | + env: |
| 94 | + TAG: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} |
| 95 | + - name: Generate Release Notes |
| 96 | + run: | |
| 97 | + release_notes=$(gh api repos/{owner}/{repo}/releases/generate-notes -F tag_name=${{ github.ref }} --jq .body) |
| 98 | + echo 'RELEASE_NOTES<<EOF' >> $GITHUB_ENV |
| 99 | + echo "${release_notes}" >> $GITHUB_ENV |
| 100 | + echo 'EOF' >> $GITHUB_ENV |
| 101 | + env: |
| 102 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + OWNER: ${{ github.repository_owner }} |
| 104 | + REPO: ${{ github.event.repository.name }} |
| 105 | + - name: Create Release |
| 106 | + id: create_release |
| 107 | + uses: actions/create-release@v1 |
| 108 | + env: |
| 109 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + with: |
| 111 | + tag_name: ${{ github.ref }} |
| 112 | + release_name: Release ${{ github.ref }} |
| 113 | + body: ${{ env.RELEASE_NOTES }} |
| 114 | + draft: false |
| 115 | + prerelease: false |
0 commit comments