Skip to content

Commit

Permalink
Merge pull request #4 from lampajr/prepare_package
Browse files Browse the repository at this point in the history
Setup release process and other improvements
  • Loading branch information
stalep authored Mar 27, 2024
2 parents 24e6d42 + 6b774ac commit 5c76e0e
Show file tree
Hide file tree
Showing 25 changed files with 690 additions and 4,864 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/backport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Pull Request Backporting using Git Backporting

on:
pull_request_target:
types:
- closed
- labeled

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NO_SQUASH_OPTION: true

jobs:
backporting:
name: "Backporting"
concurrency:
group: backporting-${{ github.head_ref }}
cancel-in-progress: true
# Only react to merged PRs for security reasons.
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
if: >
github.event.pull_request.merged
&& (
github.event.action == 'closed'
&& (contains(github.event.pull_request.labels.*.name, 'backport')
|| contains(github.event.pull_request.labels.*.name, 'backport-squash'))
|| (
github.event.action == 'labeled'
&& contains(github.event.label.name, 'backport')
)
)
runs-on: ubuntu-latest
steps:
- name: Override no-squash option
if: >
(github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'backport-squash'))
|| (github.event.action == 'labeled' && contains(github.event.label.name, 'backport-squash'))
shell: bash
run: |
echo "NO_SQUASH_OPTION=false" >> $GITHUB_ENV
- name: Backporting
uses: kiegroup/[email protected]
with:
target-branch: 0.12.x
pull-request: ${{ github.event.pull_request.url }}
no-squash: ${{ env.NO_SQUASH_OPTION }}
70 changes: 70 additions & 0 deletions .github/workflows/check-openapi-change.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This workflow will fetch the new openapi from the provided branch of https://github.com/Hyperfoil/Horreum and based on
# that it will re-generate the Horreum raw client and check the build/tests are still working.
# It could be tested running `gh act workflow_dispatch -e ./test/gha_workflows/workflow_dispatch_event_example.json`.
name: Update Horreum auto-generated client

on:
workflow_dispatch:
inputs:
branch:
description: Branch or tag of https://github.com/Hyperfoil/Horreum
required: true
# this event should be triggered by Horreum repo using peter-evans/repository-dispatch@v2
repository_dispatch:
types: [ detected-horreum-openapi-change ]

jobs:
check-openapi-change:
name: check-openapi-change ${{ github.event.client_payload.branch }}
runs-on: ubuntu-latest
env:
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
strategy:
fail-fast: false
matrix:
python: [ "3.9", "3.10", "3.11" ]
steps:
- name: Fetch Horreum branch
id: fetch-horreum-branch
run: |
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "horreum_branch=${{ github.event.client_payload.branch }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "horreum_branch=${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
else
echo "Unknown event: ${{ github.event_name }}"
exit 1
fi
- name: Fetch client branch
id: fetch-client-branch
run: |
if [ "${{ steps.fetch-horreum-branch.outputs.horreum_branch }}" = "master" ]; then
echo "horreum_client_branch=main" >> $GITHUB_OUTPUT
else
echo "horreum_client_branch=${{ steps.fetch-horreum-branch.outputs.horreum_branch }}" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
with:
ref: ${{ steps.fetch-client-branch.outputs.horreum_client_branch }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
run: make HORREUM_BRANCH=${{ steps.fetch-horreum-branch.outputs.horreum_branch }} generate
- name: Test horreum
run: nox --python=${{ matrix.python }} -s tests
26 changes: 19 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# This workflow will run the full CI for the Horreum python library including the build and the tests execution
# This is going to be triggered on every pull request as well as on main branch.
# TODO: trigger tests once implemented
# This is going to be triggered on every pull request as well as on all stable branches (e.g., main and 0.12.x).
name: Python client ci

on:
push:
branches:
- main
- 0.12.x
pull_request:

jobs:
test:
name: ${{ matrix.session }} ${{ matrix.python }}
name: test/${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -27,7 +27,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install development dependencies
run: pip install -r dev-requirements.txt
- name: Build python library
run: poetry build
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
run: make generate
- name: Test horreum
run: nox --python=${{ matrix.python }} -s tests
54 changes: 0 additions & 54 deletions .github/workflows/generate-client.yaml

This file was deleted.

42 changes: 30 additions & 12 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# This workflow will build the python distribution and it will publish to Pypi
# This is going to be triggered on on every tag `v*`, e.g., `v0.13`.
# TODO: trigger tests once implemented, to ensure everything is working before publishing
# This workflow will build the python distribution, and it will publish to Pypi
# This is going to be triggered on every tag `v*`, e.g., `v0.13`.
name: Publish Horreum library

on:
push:
tags:
- v*
workflow_dispatch:

jobs:
test:
name: ${{ matrix.session }} ${{ matrix.python }}
publish:
name: Publish horreum package
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
env:
FORCE_COLOR: "1"
PY_VERSION: "3.10"
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install development dependencies
run: pip install -r dev-requirements.txt
- name: Check version coherence
run: |
PROJECT_VERSION=$(poetry version | cut -d' ' -f2)
Expand All @@ -31,8 +28,29 @@ jobs:
echo "::error title='$GIT_TAG tag does not match project version'::"
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VERSION }}
- name: Upgrade pip
run: |
pip install --constraint=./dev-constraints.txt pip
pip --version
- name: Install poetry
run: |
pip install --constraint=./dev-constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
- name: Generate horreum client
# HORREUM_BRANCH must be properly set to the Horreum branch you want to fetch the openapi
run: make generate
- name: Test horreum
run: nox --python=${{ env.PY_VERSION }} -s tests
- name: Build python library
run: make generate && poetry build --ansi
run: poetry build --ansi
- name: Publish package on PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ bin/

# Kiota
**/.kiota.log

# Openapi
openapi/openapi.yaml

# Generated code
src/horreum/raw_client/**
52 changes: 0 additions & 52 deletions GET_STARTED.md

This file was deleted.

23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ KIOTA_VERSION ?= "v1.12.0"
HORREUM_BRANCH ?= "master"
HORREUM_OPENAPI_PATH ?= "https://raw.githubusercontent.com/Hyperfoil/Horreum/${HORREUM_BRANCH}/docs/site/content/en/openapi/openapi.yaml"
GENERATED_CLIENT_PATH = "${PROJECT_PATH}/src/horreum/raw_client"
OPENAPI_PATH = "${PROJECT_PATH}/openapi"
OPENAPI_SPEC = "${OPENAPI_PATH}/openapi.yaml"

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.PHONY: clean-bin
clean-bin: ## Clean external tools
@rm -rf ${PROJECT_BIN}

.PHONY: clean
clean: ## Clean external tools and output dirs
@rm -rf ${PROJECT_BIN} ${PROJECT_DIST} ${GENERATED_CLIENT_PATH}/api ${GENERATED_CLIENT_PATH}/models ${GENERATED_CLIENT_PATH}/horreum_raw_client.py ${GENERATED_CLIENT_PATH}/kiota-lock.json
clean: ## Clean output directories
@rm -rf ${PROJECT_DIST} ${GENERATED_CLIENT_PATH} ${OPENAPI_PATH}

.PHONY: kiota
kiota: ${PROJECT_BIN}/kiota ## Install kiota tool under ${PROJECT_PATH}/bin
Expand All @@ -58,10 +64,17 @@ ${PROJECT_BIN}/kiota:
.PHONY: tools
tools: kiota ## Install external tools.

${OPENAPI_SPEC}:
@{\
set -e ;\
mkdir -p ${OPENAPI_PATH} ;\
echo "fetching openapi spec from ${HORREUM_OPENAPI_PATH}" ;\
curl -sSfL -o ${OPENAPI_SPEC} ${HORREUM_OPENAPI_PATH} ;\
}

.PHONY: generate
generate: tools ## Generate the Horreum client
generate: tools ${OPENAPI_SPEC} ## Generate the Horreum client
@{\
set -e ;\
curl -sSfL -o ${PROJECT_PATH}/openapi/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${PROJECT_PATH}/openapi/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
}
Loading

0 comments on commit 5c76e0e

Please sign in to comment.