Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorganize github actions #340

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: actionlint

on:
pull_request:
branches: [main]
paths:
- ".github/workflows/*"

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: actionlint
run: |
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
./actionlint -color
shell: bash
91 changes: 0 additions & 91 deletions .github/workflows/e2e.yml

This file was deleted.

26 changes: 14 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ jobs:
- name: Update kustomization
run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF:10} make update-version-to-install

- name: Set env
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Set output
id: set-output
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> "$GITHUB_OUTPUT"

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "chore: bump version to ${{ env.RELEASE_VERSION }} in install/kustomization.yaml"
title: "chore: bump version to ${{ steps.set-output.outputs.RELEASE_VERSION }} in install/kustomization.yaml"
body: |
# Why
- New version [${{ env.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.RELEASE_VERSION }}) was released.
- New version [${{ steps.set-output.outputs.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.set-output.outputs.RELEASE_VERSION }}) was released.
# What
- Update kustomization for installation

Expand All @@ -77,23 +78,24 @@ jobs:
ref: main
repository: nakamasato/helm-charts

- name: Set env
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Set output
id: set-output
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> "$GITHUB_OUTPUT"

- name: Update app version
run: |
yq e -i ".version = \"${RELEASE_VERSION}\"" charts/mysql-operator/Chart.yaml
yq e -i ".appVersion = \"${RELEASE_VERSION}\"" charts/mysql-operator/Chart.yaml
yq e -i ".controllerManager.manager.image.tag = \"${RELEASE_VERSION}\"" charts/mysql-operator/values.yaml
yq e -i ".version = \"${{ steps.set-output.outputs.RELEASE_VERSION }}\"" charts/mysql-operator/Chart.yaml
yq e -i ".appVersion = \"${{ steps.set-output.outputs.RELEASE_VERSION }}\"" charts/mysql-operator/Chart.yaml
yq e -i ".controllerManager.manager.image.tag = \"${{ steps.set-output.outputs.RELEASE_VERSION }}\"" charts/mysql-operator/values.yaml

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.PAT_TO_UPDATE_HELM_CHARTS_REPO }} # when expired, need to update in https://github.com/settings/tokens
title: "chore: bump mysql-operator version to ${{ env.RELEASE_VERSION }}"
title: "chore: bump mysql-operator version to ${{ steps.set-output.outputs.RELEASE_VERSION }}"
branch: bump-mysql-operator-chart
body: |
# Why
- New version [${{ env.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.RELEASE_VERSION }}) was released.
- New version [${{ steps.set-output.outputs.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.set-output.outputs.RELEASE_VERSION }}) was released.
# What
- bump mysql-operator chart version to [${{ env.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.RELEASE_VERSION }})
- bump mysql-operator chart version to [${{ steps.set-output.outputs.RELEASE_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.set-output.outputs.RELEASE_VERSION }})
149 changes: 144 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,74 @@ name: test

on:
pull_request:
paths:
- '**.go'
- 'go.*'
- .github/workflows/test.yml
push:
branches:
- main

jobs:
path-filter:
outputs:
go: ${{steps.changes.outputs.go}}
e2e: ${{steps.changes.outputs.e2e}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
go:
- '**.go'
- 'go.*'
- .github/workflows/test.yml
e2e:
- Dockerfile
- .github/workflows/test.yml
- config/crd/**
- tests/e2e/**
- internal/**
- '**.go'
- 'go.*'
- kuttl-test.yaml
- skaffold.yaml

status-check:
runs-on: ubuntu-latest
needs:
- lint
- test
- e2e-kuttl
- e2e-ginkgo
permissions: {}
if: failure()
steps:
- run: exit 1

lint:
needs: path-filter
if: needs.path-filter.outputs.go == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: golangci-lint command line arguments.
args: --timeout=3m # --issues-exit-code=0

test:
needs: path-filter
if: needs.path-filter.outputs.go == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
Expand All @@ -19,11 +78,91 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: true

- run: |
make test
cat cover.out >> coverage.txt

- name: codecov
uses: codecov/codecov-action@v4

e2e-kuttl:
needs: path-filter
if: needs.path-filter.outputs.e2e == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: true

# https://krew.sigs.k8s.io/docs/user-guide/setup/install/
- name: krew - install
run: |
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
)

# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#adding-a-system-path
- name: krew - set PATH
run: echo "${KREW_ROOT:-$HOME/.krew}/bin:$PATH" >> "$GITHUB_PATH"

# https://kuttl.dev/docs/cli.html#setup-the-kuttl-kubectl-plugin
- name: kuttl - install
run: |
kubectl krew install kuttl
kubectl kuttl -v

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build with gha
uses: docker/build-push-action@v5
with:
context: .
push: false # a shorthand for --output=type=registry if set to true
load: true # a shorthand for --output=type=docker if set to true
tags: mysql-operator:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: kuttl test
run: make kuttl

e2e-ginkgo:
needs: path-filter
if: needs.path-filter.outputs.e2e == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: true

- name: install skaffold # TODO: #69 Enable to install skaffold in e2e
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/

- name: create kind cluster
working-directory: e2e
run: kind create cluster --name mysql-operator-e2e --kubeconfig kubeconfig --config kind-config.yml --wait 30s

- name: skaffold run
working-directory: e2e
run: skaffold run --kubeconfig kubeconfig

- name: e2e-with-ginkgo
run: make e2e-with-ginkgo
Loading