From afc1c17f6e788b18b64fe0411c914d1aa42fc2e4 Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Thu, 5 Sep 2024 17:41:50 -0500 Subject: [PATCH] Add GitHub workflow for releases (#58) Adds a new GitHub workflow for releases that will: - Upload the CRDs and default CR manifest - Build and push the docker image Closes https://linear.app/prefect/issue/PLA-220/design-release-process Closes #18 --- .github/release.yaml | 28 +++++++++ .github/workflows/docker.yaml | 17 ------ .github/workflows/release.yaml | 102 +++++++++++++++++++++++++++++++++ .github/workflows/tests.yaml | 26 --------- .mise.toml | 2 + .pre-commit-config.yaml | 26 +++++++++ .yamllint | 12 ++++ 7 files changed, 170 insertions(+), 43 deletions(-) create mode 100644 .github/release.yaml delete mode 100644 .github/workflows/docker.yaml create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/tests.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint diff --git a/.github/release.yaml b/.github/release.yaml new file mode 100644 index 0000000..e3a27c5 --- /dev/null +++ b/.github/release.yaml @@ -0,0 +1,28 @@ +# .github/release.yml + +changelog: + exclude: + labels: + - maintenance + categories: + - title: Breaking Changes + labels: + - breaking + - title: Dependency Updates + labels: + - dependencies + - title: Documentation + labels: + - docs + - title: Enhancements + labels: + - enhancement + - title: Exciting New Features 🎉 + labels: + - feature + - title: Fixes + labels: + - fix + - title: Uncategorized + labels: + - "*" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml deleted file mode 100644 index 4fd5f3e..0000000 --- a/.github/workflows/docker.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: Docker image - -on: - pull_request: - push: - branches: - - main - -jobs: - docker-build: - runs-on: ubuntu-latest - steps: - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: false - tags: prefect-operator:latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2e5a3cf --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,102 @@ +# Prefect Operator release workflow. +name: Release + +"on": + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + +permissions: {} + +jobs: + unit-tests: + name: Unit tests + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install tool dependencies + uses: jdx/mise-action@v2 + + - name: Build + run: make build + + - name: Test + run: make test + + build-and-upload-manifests: + needs: unit-tests + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install tool dependencies + uses: jdx/mise-action@v2 + + - name: Build manifests + run: | + (cd config/manager && kustomize edit set image controller=prefecthq/prefect-operator:${{ github.ref_name }}) + kustomize build config/crd > prefect-crds.yaml + kustomize build config/default > prefect.yaml + + - name: Upload release assets + if: github.ref_type == 'tag' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.ref_name }} prefect-crds.yaml prefect.yaml + + build-and-push-docker-image: + needs: unit-tests + runs-on: ubuntu-latest + # The GitHub environments are created by Terraform and map to Docker Hub repositories: + # - dev: https://hub.docker.com/r/prefecthq/prefect-operator-dev + # - prod: https://hub.docker.com/r/prefecthq/prefect-operator + # The environment will be 'prod' if the GitHub event is a release. Otherwise, it will be 'dev'. + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + # These credentials are managed in Terraform. Depending on the 'environment' value above, + # these will either be the credentials for 'dev' or 'prod'. + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker image metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: prefecthq/prefect-operator${{ github.event_name == 'pull_request' && '-dev' }} + tags: | + type=ref,event=pr + type=ref,event=branch + type=semver,pattern={{version}} + labels: | + org.opencontainers.image.title=prefect-operator + org.opencontainers.image.description=Prefect Operator image + org.opencontainers.image.vendor=Prefect + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml deleted file mode 100644 index 3c2ae25..0000000 --- a/.github/workflows/tests.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Unit tests -on: - pull_request: - push: - branches: - - main - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - unit-tests: - name: Unit tests - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: jdx/mise-action@v2 - - name: Build - run: make build - - name: Test - run: make test diff --git a/.mise.toml b/.mise.toml index 6e89f3a..c8bb7e4 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,4 +1,5 @@ [tools] +actionlint = '1.7.1' ginkgo = '2.19.0' golang = '1.21' golangci-lint = '1.57.2' @@ -6,3 +7,4 @@ kube-controller-tools = '0.14.0' kubectl = '1.31' kustomize = '5.3.0' setup-envtest = '0.17.0' +yamllint = '1.35.1' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..89b3b46 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +--- +fail_fast: false + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + args: + - --allow-multiple-documents + - id: detect-private-key + - id: no-commit-to-branch + - id: trailing-whitespace + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.28.0 + hooks: + - id: yamllint + args: + - --strict + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.1 + hooks: + - id: actionlint diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..20ba0e7 --- /dev/null +++ b/.yamllint @@ -0,0 +1,12 @@ +--- +extends: default + +ignore: | + config/ + +rules: + comments: + min-spaces-from-content: 1 + comments-indentation: disable + document-start: disable + line-length: disable