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

Setup release process and other improvements #4

Merged
merged 8 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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')
)
)
lampajr marked this conversation as resolved.
Show resolved Hide resolved
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'))
Comment on lines +36 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I would factor out the common condition:

          (github.event.action == 'closed' || github.event.action == 'labeled') && 
           && contains(github.event.label.name, 'backport-squash')

although I doubt that you need the github.event.action check, because I don't think this will run if neither of those is true, per the check at line 21.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the github.event.action check as I am performing two different checks based on that result:

  • github.event.action == 'closed' --> check github.event.pull_request.labels.*.name
  • github.event.action == 'labeled' --> check github.event.label.name

NOTE: github.event.label.name is present if and only if the event is labeled

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see.

But, if github.event.action == 'labeled' is true, then github.event.pull_request.labels.*.name should contain the updated value (right?), so you can check that instead of github.event.label.name, which should let you simplify this to a single condition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, but if I check github.event.pull_request.labels.*.name when adding a label I am actually checking if at least one label with that name exists, which is true even if I am adding a new label and backport already exists on that pul request. This is not what we want as it would trigger the workflow multiple times.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point...but, I think that applies to my previous suggestion (which I shall withdraw 🙂).

In this spot, we've already decided to run the workflow, so the only question is whether to squash or not, and for that I think you can check github.event.pull_request.labels.*.name in either case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment #4 (comment) I don't think that is enough to check backport word. Anyway we are talking about minors so not a big deal

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 }}
lampajr marked this conversation as resolved.
Show resolved Hide resolved
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
Comment on lines +30 to +45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's...suboptimal...to have this duplicated here and in .github/workflows/check-openapi-change.yaml. You should consider refactoring this into a common "reusable workflow".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I agree, but since we are still setting up most of the things I would leave this optimization in a followup PR (I will open an issue to keep track)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with trying to avoid "extra work", but I wouldn't regard using common workflows as an optimization -- rather, it's a savings, because you don't have to "reinvent the wheel", and if something needs updating then you can do it in one place, rather than having to track down all the copies of it.

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
Comment on lines +31 to +51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's that duplicated workflow again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented here #4 (comment)

- 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

# Generate code
src/horreum/raw_client/**
lampajr marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 0 additions & 52 deletions GET_STARTED.md

This file was deleted.

14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ 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"

.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 @@ -62,6 +67,7 @@ tools: kiota ## Install external tools.
generate: tools ## 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} ;\
mkdir -p ${OPENAPI_PATH} ;\
curl -sSfL -o ${OPENAPI_PATH}/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
lampajr marked this conversation as resolved.
Show resolved Hide resolved
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
}
Loading