Skip to content

Commit

Permalink
More consolidation through custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pgm committed Jan 9, 2025
1 parent b3eabcd commit 39a88f3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
23 changes: 23 additions & 0 deletions .github/actions/prepare-breadbox-client/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
- name: "Create client from spec"
working-directory: "./breadbox-client-generator"
run: |
poetry install
poetry run ./generate.sh
- name: "peek at poetry cachedir"
run: "ls -l ${{ steps.poetry-cachedir.outputs.POETRY_CACHEDIR }}/*"
31 changes: 31 additions & 0 deletions .github/actions/prepare-breadbox/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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"'

- name: "Check out"
uses: actions/checkout@v3
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0

- 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"
13 changes: 7 additions & 6 deletions .github/workflows/build_breadbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ 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: 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: "run pyright breadbox_facade"

build-docker:
runs-on: ubuntu-latest
steps:
Expand Down
38 changes: 2 additions & 36 deletions .github/workflows/publish_breadbox_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,15 @@ jobs:
publish-breadbox-client:
runs-on: ubuntu-latest
steps:
- name: "Compute poetry cache dir"
id: "poetry-cachedir"
run: 'echo POETRY_CACHEDIR="$HOME/.cache/pypoetry" >> "$GITHUB_OUTPUT"'
- 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: "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.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: "Export the OpenAPI spec"
working-directory: "./breadbox"
run: |
poetry install
poetry run ./bb export-api-spec ../breadbox-client/latest-breadbox-api.json
- name: "Create client from spec"
working-directory: "./breadbox-client-generator"
run: |
poetry install
poetry run ./generate.sh
- name: "peek at poetry cachedir"
run: "ls -l ${{ steps.poetry-cachedir.outputs.POETRY_CACHEDIR }}/*"

- name: "Set up authentication for publishing breadbox client"
working-directory: "./breadbox-client"
run: |
Expand Down

0 comments on commit 39a88f3

Please sign in to comment.