From 514a021c5f4b810c93e28bfe35e5561a35befea2 Mon Sep 17 00:00:00 2001 From: eoinfennessy Date: Sat, 23 Mar 2024 19:43:00 +0000 Subject: [PATCH] Add GitHub Actions Workflows --- .github/workflows/build-and-publish.yaml | 57 ++++++++++++++++++++++++ .github/workflows/test-pr.yaml | 18 ++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/build-and-publish.yaml create mode 100644 .github/workflows/test-pr.yaml diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml new file mode 100644 index 0000000..ddc734c --- /dev/null +++ b/.github/workflows/build-and-publish.yaml @@ -0,0 +1,57 @@ +name: Build and Publish Controller Image + +on: + push: + branches: + - main + - "release-*" + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +env: + MAIN_BRANCH_NAME: main + +jobs: + build: + name: Build and Publish Controller Image + runs-on: ubuntu-latest + outputs: + sha_short: ${{ steps.vars.outputs.sha_short }} + controller_image: ${{ steps.vars.outputs.base_image }}:${{ steps.vars.outputs.sha_short }} + steps: + - uses: actions/checkout@v4 + + - name: Calculate vars + id: vars + run: | + echo "sha_short=$(echo ${{ github.sha }} | cut -b -7)" >> $GITHUB_OUTPUT + echo "base_image=${{ vars.IMG_REGISTRY_HOST }}/${{ vars.IMG_REGISTRY_ORG }}/${{ vars.IMG_REGISTRY_REPO }}" >> $GITHUB_OUTPUT + + - name: Add image tags + id: add-tags + run: echo "IMG_TAGS=${{ steps.vars.outputs.base_image }}:${{ steps.vars.outputs.sha_short }},${{ steps.vars.outputs.base_image }}:${{ github.ref_name }}" >> $GITHUB_ENV + + - name: Add latest tag + if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }} + id: add-latest-tag + run: echo "IMG_TAGS=${{ steps.vars.outputs.base_image }}:latest,${{ env.IMG_TAGS }}" >> $GITHUB_ENV + + - name: Login to image registry + uses: docker/login-action@v3 + id: registry-login + with: + registry: ${{ vars.IMG_REGISTRY_HOST }} + username: ${{ secrets.IMG_REGISTRY_USERNAME }} + password: ${{ secrets.IMG_REGISTRY_TOKEN }} + + - name: Build and push Controller Image + id: build-and-push + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ env.IMG_TAGS }} + + - name: Print Image URL + run: | + echo "Image pushed to ${{ env.IMG_TAGS }}" + echo "Image digest: ${{ steps.build-and-push.outputs.digest }}" \ No newline at end of file diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml new file mode 100644 index 0000000..ff8ad5d --- /dev/null +++ b/.github/workflows/test-pr.yaml @@ -0,0 +1,18 @@ +name: Run Tests on PRs + +on: + pull_request: + branches: + - main + +jobs: + test: + name: Run All Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: v1.20 + - name: Run Tests + run: make test \ No newline at end of file