-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e45a2c
commit 2826a6a
Showing
2 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Setup Poetry Virtual Environment | ||
|
||
inputs: | ||
python_version: | ||
required: true | ||
type: string | ||
poetry_version: | ||
required: true | ||
type: string | ||
default: '1.8.3' | ||
poetry_included_groups: | ||
required: false | ||
type: string | ||
poetry_excluded_groups: | ||
required: false | ||
type: string | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Setup and Cache Python ${{ inputs.python_version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python_version }} | ||
|
||
- name: Install poetry | ||
uses: abatilo/actions-poetry@v2 | ||
|
||
- name: Setup a local virtual environment (if no poetry.toml file) | ||
run: | | ||
poetry config virtualenvs.create true --local | ||
poetry config virtualenvs.in-project true --local | ||
- name: Load cached Poetry installation | ||
id: cached-poetry | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.local | ||
key: poetry-${{ runner.os }}-${{ inputs.poetry_version }} | ||
|
||
- name: Install and configure Poetry | ||
if: steps.cached-poetry.outputs.cache-hit != 'true' | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: ${{ inputs.poetry_version }} | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
installer-parallel: true | ||
|
||
- name: Load cached venv | ||
id: cached-venv | ||
uses: actions/cache@v4 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ inputs.python_version }}-${{ hashFiles('poetry.lock') }} | ||
|
||
- if: steps.cached-venv.outputs.cache-hit != 'true' | ||
name: Create Virtual Environment | ||
shell: bash | ||
run: | | ||
echo "Included optional dependency groups ${{ inputs.poetry_included_groups }}" | ||
echo "Excluded optional dependency groups ${{ inputs.poetry_excluded_groups }}" | ||
# --sync: Synchronize the environment with the locked packages and the specified groups. | ||
COMMON_OPTS="--sync" | ||
WITH_OPTS= | ||
WITHOUT_OPTS= | ||
if [ -n "${{ inputs.poetry_included_groups }}" ]; then | ||
WITH_OPTS="--with ${{ inputs.poetry_included_groups }}" | ||
fi | ||
if [ -n "${{ inputs.poetry_excluded_groups }}" ]; then | ||
WITHOUT_OPTS="--without ${{ inputs.poetry_excluded_groups }}" | ||
fi | ||
poetry install $COMMON_OPTS $WITH_OPTS $WITHOUT_OPTS | ||
source $(poetry env info --path)/bin/activate | ||
# Set the path for subsequent steps so that the environment is activated by default | ||
echo PATH=$PATH >> $GITHUB_ENV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Main CI Workflow | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: Why did you trigger the pipeline? | ||
required: False | ||
default: Check if it runs again due to external changes | ||
|
||
|
||
env: | ||
GITHUB_BOT_USERNAME: github-actions[bot] | ||
GITHUB_BOT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | ||
PY_COLORS: 1 | ||
PYTHON_VERSION: '3.11' | ||
PACKAGE_NAME: 'language-transfer' | ||
|
||
|
||
jobs: | ||
code-quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Virtual Environment | ||
uses: ./.github/actions/poetry | ||
with: | ||
python_version: {{ '${{ env.PYTHON_VERSION }}' }} | ||
poetry_included_groups: dev | ||
|
||
- name: Run pre-commit | ||
run: pre-commit run --all-files --verbose --show-diff-on-failure | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
needs: [code-quality] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Virtual Environment | ||
uses: ./.github/actions/poetry | ||
with: | ||
python_version: {{ '${{ env.PYTHON_VERSION }}' }} | ||
poetry_included_groups: dev | ||
- name: Run pytest | ||
run: pytest -vvv | ||
|
||
publish-testpypi: | ||
name: Publish package to TestPyPI | ||
runs-on: ubuntu-latest | ||
needs: [code-quality, tests] | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
concurrency: | ||
group: publish-testpypi | ||
permissions: | ||
id-token: write | ||
environment: | ||
name: testpypi | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
lfs: true | ||
|
||
- name: Setup Virtual Environment | ||
uses: ./.github/actions/poetry | ||
with: | ||
python_version: {{ '${{ env.PYTHON_VERSION }}' }} | ||
poetry_included_groups: dev | ||
|
||
- name: Bump Version and Build Package | ||
run: | | ||
set -x | ||
CURRENT_VERSION=$(bump-my-version show current_version) | ||
BUILD_NUMBER=$GITHUB_RUN_NUMBER | ||
NEW_VERSION=$(echo $CURRENT_VERSION | sed -e "s/-dev[0-9]\+/-dev${BUILD_NUMBER}/g") | ||
bump-my-version bump --no-tag --no-commit --verbose --new-version ${NEW_VERSION} | ||
echo "Version was bumped from ${CURRENT_VERSION} to ${NEW_VERSION}!" | ||
poetry build --format=wheel | ||
# TODO: uncomment once the repository and testpypi are configured | ||
# - name: Publish to TestPyPI | ||
# uses: pypa/gh-action-pypi-publish@release/v1 | ||
# with: | ||
# repository-url: https://test.pypi.org/legacy/ | ||
# print-hash: true | ||
# verbose: true |