|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + tags: |
| 11 | + - 'v*' |
| 12 | + pull_request: |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-binaries: |
| 16 | + name: Build binaries |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Set up Go |
| 24 | + uses: actions/setup-go@v3 |
| 25 | + with: |
| 26 | + go-version: '1.19' |
| 27 | + |
| 28 | + - name: Go caches |
| 29 | + uses: actions/cache@v2 |
| 30 | + with: |
| 31 | + path: | |
| 32 | + ~/go/pkg/mod |
| 33 | + key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 34 | + restore-keys: | |
| 35 | + ${{ github.job }}-${{ runner.os }}-go- |
| 36 | +
|
| 37 | + - name: Build |
| 38 | + run: make build |
| 39 | + env: |
| 40 | + BIN_OUTPUT_DIR: /tmp/build-output/ |
| 41 | + |
| 42 | + publish-images: |
| 43 | + name: Build and publish images |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: build-binaries |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout |
| 49 | + uses: actions/checkout@v3 |
| 50 | + |
| 51 | + - name: Set up Go |
| 52 | + uses: actions/setup-go@v3 |
| 53 | + with: |
| 54 | + go-version: '1.19' |
| 55 | + |
| 56 | + - name: Go caches |
| 57 | + uses: actions/cache@v2 |
| 58 | + with: |
| 59 | + path: | |
| 60 | + ~/go/pkg/mod |
| 61 | + key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 62 | + restore-keys: | |
| 63 | + ${{ github.job }}-${{ runner.os }}-go- |
| 64 | +
|
| 65 | + - name: Installing ko |
| 66 | + run: go install github.com/google/[email protected] |
| 67 | + |
| 68 | + - name: Login to GCR |
| 69 | + uses: docker/login-action@v2 |
| 70 | + with: |
| 71 | + registry: gcr.io |
| 72 | + username: _json_key |
| 73 | + password: ${{ secrets.GCLOUD_GCR_SERVICEACCOUNT_KEY }} |
| 74 | + if: github.event_name != 'pull_request' |
| 75 | + |
| 76 | + - name: Set IMAGE_TAG |
| 77 | + id: image-tag |
| 78 | + run: | |
| 79 | + IMAGE_TAG=sha-${GITHUB_SHA:0:7} |
| 80 | + [[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME} |
| 81 | + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + - name: Publish container images |
| 84 | + env: |
| 85 | + KO_DOCKER_REPO: gcr.io/triggermesh/triggermesh/event-sources-bundle |
| 86 | + KOFLAGS: --jobs=4 --platform=linux/amd64,linux/arm64 --push=${{ github.event_name != 'pull_request' }} |
| 87 | + DIST_DIR: /tmp/dist |
| 88 | + run: | |
| 89 | + IMAGE_TAG=${{ steps.image-tag.outputs.IMAGE_TAG }} make release |
| 90 | +
|
| 91 | + - name: Upload artifact |
| 92 | + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') |
| 93 | + uses: actions/upload-artifact@master |
| 94 | + with: |
| 95 | + name: manifests |
| 96 | + path: /tmp/dist |
| 97 | + |
| 98 | + create-release: |
| 99 | + name: Create Release |
| 100 | + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') |
| 101 | + runs-on: ubuntu-latest |
| 102 | + needs: publish-images |
| 103 | + permissions: |
| 104 | + contents: write |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v2 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
| 110 | + |
| 111 | + - name: Download artifact |
| 112 | + uses: actions/download-artifact@master |
| 113 | + with: |
| 114 | + name: manifests |
| 115 | + path: /tmp/dist |
| 116 | + |
| 117 | + - name: Preparing Release Notes |
| 118 | + run: | |
| 119 | + ./hack/release-notes.sh ${GITHUB_REF_NAME} > release-notes.md |
| 120 | +
|
| 121 | + - name: Creating Release |
| 122 | + uses: ncipollo/release-action@v1 |
| 123 | + with: |
| 124 | + bodyFile: "release-notes.md" |
| 125 | + artifacts: "/tmp/dist/*" |
| 126 | + |
| 127 | + trigger-e2e: |
| 128 | + name: Trigger E2E Tests |
| 129 | + needs: publish-images |
| 130 | + runs-on: ubuntu-latest |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Set IMAGE_TAG |
| 134 | + id: image-tag |
| 135 | + run: | |
| 136 | + IMAGE_TAG=sha-${GITHUB_SHA:0:7} |
| 137 | + [[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME} |
| 138 | + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT |
| 139 | +
|
| 140 | + - name: Send dispatch event |
| 141 | + run: | |
| 142 | + curl \ |
| 143 | + -X POST \ |
| 144 | + -H "Accept: application/vnd.github+json" \ |
| 145 | + -H "Authorization: token ${{ secrets.GH_DISPATCH_TOKEN }}" \ |
| 146 | + https://api.github.com/repos/triggermesh/triggermesh-event-sources-bundle/dispatches \ |
| 147 | + -d '{"event_type":"e2e-test","client_payload":{"commit_sha":"'${GITHUB_SHA}'", "image_tag":"'${{ steps.image-tag.outputs.IMAGE_TAG }}'"}}' |
0 commit comments