Skip to content

Merge pull request #33 from triggermesh/fix/debug-e2e-action #34

Merge pull request #33 from triggermesh/fix/debug-e2e-action

Merge pull request #33 from triggermesh/fix/debug-e2e-action #34

name: Build and Release
on:
workflow_dispatch:
branches:
- main
push:
branches:
- main
tags:
- 'v*'
pull_request:
jobs:
build-binaries:
name: Build binaries
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Go caches
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ github.job }}-${{ runner.os }}-go-
- name: Build
run: make build
env:
BIN_OUTPUT_DIR: /tmp/build-output/
publish-images:
name: Build and publish images
runs-on: ubuntu-latest
needs: build-binaries
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Go caches
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ github.job }}-${{ runner.os }}-go-
- name: Installing ko
run: go install github.com/google/[email protected]
- name: Login to GCR
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCLOUD_GCR_SERVICEACCOUNT_KEY }}
if: github.event_name != 'pull_request'
- name: Set IMAGE_TAG
id: image-tag
run: |
IMAGE_TAG=sha-${GITHUB_SHA:0:7}
[[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME}
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${IMAGE_TAG}"
- name: Publish container images
env:
KO_DOCKER_REPO: gcr.io/triggermesh/event-sources-bundle
KOFLAGS: --jobs=4 --platform=linux/amd64,linux/arm64 --push=${{ github.event_name != 'pull_request' }}
DIST_DIR: /tmp/dist
run: |
IMAGE_TAG=${{ steps.image-tag.outputs.IMAGE_TAG }} make release
echo "generated images with tag ${{steps.image-tag.outputs.IMAGE_TAG}}"
- name: Upload artifact
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: actions/upload-artifact@master
with:
name: manifests
path: /tmp/dist
create-release:
name: Create Release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: publish-images
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@master
with:
name: manifests
path: /tmp/dist
- name: Preparing Release Notes
run: |
./hack/release-notes.sh ${GITHUB_REF_NAME} > release-notes.md
- name: Creating Release
uses: ncipollo/release-action@v1
with:
bodyFile: "release-notes.md"
artifacts: "/tmp/dist/*"
trigger-e2e:
name: Trigger E2E Tests
needs: publish-images
runs-on: ubuntu-latest
steps:
- name: Set IMAGE_TAG
id: image-tag
run: |
IMAGE_TAG=sha-${GITHUB_SHA:0:7}
[[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME}
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Send dispatch event
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GH_DISPATCH_TOKEN }}" \
https://api.github.com/repos/triggermesh/triggermesh-event-sources-bundle/dispatches \
-d '{"event_type":"e2e-test","client_payload":{"commit_sha":"'${GITHUB_SHA}'", "image_tag":"'${{ steps.image-tag.outputs.IMAGE_TAG }}'"}}'