Skip to content

Commit

Permalink
feat(breadbox): Improvements to breadbox client publishing (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgm authored Jan 13, 2025
1 parent ba4ea17 commit 08b8d46
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 880 deletions.
27 changes: 0 additions & 27 deletions .github/actions/generate-breadbox-client/action.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/actions/prepare-breadbox-client/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# A re-usable github action which generates the breadbox client
name: "prepare-breadbox-client"
description: "Auto-generate the breadbox client"
runs:
using: "composite"
steps:
- name: Prepare breadbox client
uses: ./.github/actions/prepare-breadbox # checks out and installs poetry

- name: "Export the OpenAPI spec"
working-directory: "./breadbox"
run: |
poetry install
poetry run ./bb export-api-spec ../breadbox-client/latest-breadbox-api.json
shell: bash

- name: "Create client from spec"
working-directory: "./breadbox-client-generator"
run: |
poetry install
poetry run ./generate.sh
shell: bash
26 changes: 26 additions & 0 deletions .github/actions/prepare-breadbox/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# A re-usable github action which does the initial checkout and sets up poetry with caching for breadbox
name: "prepare-breadbox"
description: "Checks out and prepares poetry (with caching)"
runs:
using: "composite"
steps:
- name: "Compute poetry cache dir"
id: "poetry-cachedir"
run: 'echo POETRY_CACHEDIR="$HOME/.cache/pypoetry" >> "$GITHUB_OUTPUT"'
shell: bash

- name: "Install and configure Poetry"
uses: snok/install-poetry@v1
with:
version: 1.8.2
virtualenvs-create: true

- name: "Set up poetry cache"
uses: actions/cache@v2
id: cached-poetry-dependencies
with:
path: "${{ steps.poetry-cachedir.outputs.POETRY_CACHEDIR }}"
key: "breadbox-venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('breadbox*/**/poetry.lock') }}"
# - name: "peek at poetry cachedir (for debugging)"
# run: "ls -l ${{ steps.poetry-cachedir.outputs.POETRY_CACHEDIR }}/* || true"
# shell: bash
17 changes: 17 additions & 0 deletions .github/actions/publish-breadbox-client/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "publish-breadbox-client"
description: "Publishes breadbox client to google artifact service"
runs:
using: "composite"
steps:
- name: "Set up authentication for publishing breadbox client"
working-directory: "./breadbox-client"
run: |
poetry self add keyrings.google-artifactregistry-auth
poetry config repositories.public-python https://us-central1-python.pkg.dev/cds-artifacts/public-python/
shell: bash

- name: "Publish new breadbox client version to Artifact Registry"
working-directory: "./breadbox-client"
run: |
poetry publish --build --repository public-python
shell: bash
63 changes: 23 additions & 40 deletions .github/workflows/build_breadbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,23 @@ jobs:
# We want to use the rules defined in breadbox/pyproject.toml
- name: Check PR title
run: poetry run cz check -m '${{ github.event.pull_request.title }}'

pyright-breadbox-client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Generate breadbox client
uses: ./.github/actions/generate-breadbox-client # defined as a re-usable action
- name: check that the breadbox client passes pyright
- name: "Check out"
uses: actions/checkout@v3
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0

- name: Prepare breadbox client
uses: ./.github/actions/prepare-breadbox-client # checks out and generates breadbox client code

- name: Check that the breadbox client passes pyright
working-directory: ./breadbox-client
run: |
poetry install && poetry run pyright breadbox_facade
run: "poetry install && poetry run pyright breadbox_facade"

build-docker:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -185,43 +192,19 @@ jobs:
if: ${{ (needs.bump-versions.outputs.current_version != needs.bump-versions.outputs.bumped_version) && (github.ref_name == 'master') }}
runs-on: ubuntu-latest
steps:
- name: Check out
- name: "Check out"
uses: actions/checkout@v3
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
- run: |
git pull origin HEAD:master
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
# See instructions here: https://github.com/google-github-actions/auth?tab=readme-ov-file#service-account-key-json
credentials_json: ${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up cache
uses: actions/cache@v2
id: cached-poetry-dependencies
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Generate breadbox client
uses: ./.github/actions/generate-breadbox-client # defined as a re-usable action
# the above does a checkout which deletes the credential file, so we need to execute authenticate to google cloud after it
- name: Authenticate to Google Cloud

- name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@v2
with:
# See instructions here: https://github.com/google-github-actions/auth?tab=readme-ov-file#service-account-key-json
credentials_json: ${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}
- name: Set up for publishing breadbox client
working-directory: ./breadbox-client
run: |
poetry self add keyrings.google-artifactregistry-auth
poetry config repositories.public-python https://us-central1-python.pkg.dev/cds-artifacts/public-python/
- name: Publish new breadbox client version to Artifact Registry
working-directory: ./breadbox-client
run: poetry publish --build --repository public-python
credentials_json: "${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}"

- name: Prepare breadbox client
uses: ./.github/actions/prepare-breadbox-client # checks out and generates breadbox client code

- name: Publish breadbox client
uses: ./.github/actions/publish-breadbox-client
50 changes: 11 additions & 39 deletions .github/workflows/publish_breadbox_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,24 @@ name: Publish breadbox client

on:
workflow_dispatch:
inputs:
tag:
description: "The tag/branch to checkout"
required: true
default: "master"

jobs:
publish-breadbox-client:
runs-on: ubuntu-latest
steps:
- name: Check out
- name: "Check out"
uses: actions/checkout@v3
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
- run: |
git pull origin HEAD:${{ inputs.tag }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
# See instructions here: https://github.com/google-github-actions/auth?tab=readme-ov-file#service-account-key-json
credentials_json: ${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up cache
uses: actions/cache@v2
id: cached-poetry-dependencies
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Generate breadbox client
uses: ./.github/actions/generate-breadbox-client # defined as a re-usable action
# the above does a checkout which deletes the credential file, so we need to execute authenticate to google cloud after it
- name: Authenticate to Google Cloud

- name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@v2
with:
# See instructions here: https://github.com/google-github-actions/auth?tab=readme-ov-file#service-account-key-json
credentials_json: ${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}
- name: Set up for publishing breadbox client
working-directory: ./breadbox-client
run: |
poetry self add keyrings.google-artifactregistry-auth
poetry config repositories.public-python https://us-central1-python.pkg.dev/cds-artifacts/public-python/
- name: Publish new breadbox client version to Artifact Registry
working-directory: ./breadbox-client
run: poetry publish --build --repository public-python
credentials_json: "${{ secrets.DEPMAP_ARTIFACTS_SVC_ACCT }}"

- name: Prepare breadbox client
uses: ./.github/actions/prepare-breadbox-client # checks out and generates breadbox client code

- name: Publish breadbox client
uses: ./.github/actions/publish-breadbox-client
11 changes: 11 additions & 0 deletions breadbox-client-generator/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -ex

openapi-python-client \
generate \
--meta=none \
--output-path ../breadbox-client/breadbox_client \
--path ../breadbox-client/latest-breadbox-api.json \
--overwrite

1 change: 1 addition & 0 deletions breadbox-client-generator/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "breadbox_client_generator"}]
package-mode = false

[tool.poetry.dependencies]
python = "^3.9"
Expand Down
Loading

0 comments on commit 08b8d46

Please sign in to comment.