Skip to content

Drop duplicated code. #68

Drop duplicated code.

Drop duplicated code. #68

Workflow file for this run

name: pull request
on:
pull_request:
branches:
- master
- main
jobs:
setup:
runs-on: ubuntu-latest
name: setup
env:
BUILD_PLATFORMS: "linux/amd64,linux/arm64,linux/ppc64le,linux/s390x"
GO_VERSION: "~1.18"
steps:
- name: Setting Workflow Variables
id: set-variables
run: |
echo "::set-output name=repository_name::$(basename $GITHUB_REPOSITORY)"
echo "::set-output name=bin_dir::$(pwd)/bin"
# Create Distribution Matrix
echo "::set-output name=dist_matrix::$(echo -n "${{ env.BUILD_PLATFORMS }}" | jq -csR '. | split(",")')"
# Set versions based on presence of tag
if [[ "${{ github.ref }}" =~ ^refs/tags/ ]]; then
TAG="${GITHUB_REF/refs\/tags\//}"
echo "::set-output name=tag_event::true"
echo "::set-output name=operator_version::$TAG"
else
echo "::set-output name=tag_event::false"
echo "::set-output name=operator_version::$DEFAULT_OPERATOR_VERSION"
fi
- name: Build Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Set up Go 1.x
uses: actions/setup-go@v1
with:
go-version: ${{ inputs.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v2
- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Go Dependencies
run: go mod download
- name: Download Binaries
env:
OPERATOR_SDK_VERSION: ${{ inputs.OPERATOR_SDK_VERSION }}
run: |
# Create Binary Directory
mkdir -p ${{ steps.set-variables.outputs.bin_dir }}
# Operator SDK
curl -L -o ${{ steps.set-variables.outputs.bin_dir }}/operator-sdk https://github.com/operator-framework/operator-sdk/releases/download/${{ env.OPERATOR_SDK_VERSION }}/operator-sdk_linux_amd64
# Controller-gen
make controller-gen
# Kustomize
make kustomize
- name: Upload Support Binaries
uses: actions/upload-artifact@v2
with:
name: support-binaries
path: ${{ steps.set-variables.outputs.bin_dir }}
outputs:
repository_name: ${{ steps.set-variables.outputs.repository_name }}
bin_dir: ${{ steps.set-variables.outputs.bin_dir }}
go_build: ${{ steps.go-cache-paths.outputs.go-build }}
go_mod: ${{ steps.go-cache-paths.outputs.go-mod }}
tag_event: ${{ steps.set-variables.outputs.tag_event }}
dist_matrix: ${{ steps.set-variables.outputs.dist_matrix }}
build-operator:
runs-on: ubuntu-latest
name: build-operator
needs: ["setup"]
strategy:
matrix:
platform: ${{ fromJson(needs.setup.outputs.dist_matrix) }}
env:
REPOSITORY_NAME: ${{ needs.setup.outputs.repository_name }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v1
with:
go-version: ${{ inputs.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v2
- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ needs.setup.outputs.go_build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
uses: actions/cache@v2
with:
path: ${{ needs.setup.outputs.go_mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Download Support Binaries
uses: actions/download-artifact@v2
with:
name: support-binaries
path: ${{ needs.setup.outputs.bin_dir }}
- name: Prepare Build Step
id: setup-build-step
run: |
# Setup Path
echo "${{ needs.setup.outputs.bin_dir }}" >> $GITHUB_PATH
# Make Binaries Executable
chmod +x ${{ needs.setup.outputs.bin_dir }}/*
# Configure Platform Variables
echo "::set-output name=platform_os::$(echo ${{ matrix.platform }} | cut -d/ -f1)"
echo "::set-output name=platform_arch::$(echo ${{ matrix.platform }} | cut -d/ -f2)"
- name: Download Dependencies
shell: bash
run: |
make generate
make fmt
make vet
- name: build code
shell: bash
env:
VERSION: latest
GOOS: ${{ steps.setup-build-step.outputs.platform_os }}
GOARCH: ${{ steps.setup-build-step.outputs.platform_arch }}
run: make
test-operator:
runs-on: ubuntu-latest
name: test-operator
needs: ["setup"]
env:
REPOSITORY_NAME: ${{ needs.setup.outputs.repository_name }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v1
with:
go-version: ${{ inputs.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v2
- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ needs.setup.outputs.go_build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
uses: actions/cache@v2
with:
path: ${{ needs.setup.outputs.go_mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Download Binaries
uses: actions/download-artifact@v2
with:
name: support-binaries
path: ${{ needs.setup.outputs.bin_dir }}
- name: Prepare Build Step
id: setup-build-step
run: |
# Setup Path
echo "${{ needs.setup.outputs.bin_dir }}" >> $GITHUB_PATH
# Make Binaries Executable
chmod +x ${{ needs.setup.outputs.bin_dir }}/*
- name: Run unit tests
shell: bash
run: make test