diff --git a/.github/workflows/common/common_pytest.yml b/.github/workflows/common/common_pytest.yml new file mode 100644 index 0000000..a38c881 --- /dev/null +++ b/.github/workflows/common/common_pytest.yml @@ -0,0 +1,39 @@ +# A common CI workflow that runs pytest on all actively supported Python versions. +# +# Assumptions: +# +# 1. The repo works with the below-specified version of Poetry. +# 2. The repo can be tested with pytest. +# 3. All Python versions named below are enabled for testing. + +name: Python Pytest Check (MeltanoLabs) + +on: [push] + +jobs: + pytest: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + strategy: + fail-fast: false + matrix: + python-version: [3.7, 3.8, 3.9, 3.10] + + steps: + - uses: actions/checkout@v3 + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.3.2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'poetry' + - name: Install dependencies + run: | + poetry install + - name: Test with pytest + run: poetry run pytest + diff --git a/.github/workflows/common/common_python_tox_lint.yml b/.github/workflows/common/common_python_tox_lint.yml new file mode 100644 index 0000000..8e19574 --- /dev/null +++ b/.github/workflows/common/common_python_tox_lint.yml @@ -0,0 +1,37 @@ +# A common CI workflow to run linting as defined in tox.ini +# +# Assumptions: +# +# 1. The repo has a tox.ini file, which defines a 'lint' command. +# 2. The lint operation will be run on the below-named python version. + +name: Python Lint Checks from Tox (MeltanoLabs) + +on: [push] + +jobs: + linting: + + runs-on: ubuntu-latest + strategy: + matrix: + # Only lint using the primary version used for dev + python-version: [3.10] + + steps: + - uses: actions/checkout@v3 + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.3.2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'poetry' + - name: Install dependencies + run: | + poetry install + - name: Run lint command from tox.ini + run: | + poetry run tox -e lint diff --git a/.github/workflows/common/common_release_workflow.yml b/.github/workflows/common/common_release_workflow.yml new file mode 100644 index 0000000..c5bdef9 --- /dev/null +++ b/.github/workflows/common/common_release_workflow.yml @@ -0,0 +1,61 @@ +name: Publish GitHub Release to PyPI (MeltanoLabs) + +# This workflow executes upon the publishing of a release in GitHub. This does not run on draft releases. +# +# Assumptions: +# +# 1. The repo is a python project which can be deployed using the Python version below noted in `python-version: __`. +# 2. The `pyproject.toml` file should declare `version = 0.0.0` in deference of dynamic versioning. +# 3. The release title should be in the semvar format (`vX.Y.Z`) +# 4. The repo secrets should declare (or have access to) the following env vars / secrets: +# 1. TEST_PYPI_TOKEN - A token to use for test publish. +# 2. PYPI_TOKEN - A token to use for actual publish. +# +# Other notes: +# +# - Unless you block the hotkey, you browser will likely interpret "Ctrl+Enter" as "Publish" and not "Save Draft", +# even if you are editing an existing draft. +# - The text copy of Release Notes can freely be edited after publish, with no impact on the publish process and without +# risk of accidentally republishing. +# - PyPI will only accept each semvar increment once, but failures to publish can be freely retried, and you can yank +# and release a patch on top if needed. + +on: + release: + types: [published] + +jobs: + build_deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install poetry + - name: Build package + run: | + poetry self add "poetry-dynamic-versioning[plugin]" + poetry config repositories.testpypi https://test.pypi.org/legacy/ + poetry dynamic-versioning --no-cache + poetry build + - name: Upload wheel to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: dist/*.whl + tag: ${{ github.ref }} + overwrite: true + file_glob: true + - name: Deploy to PyPI + run: | + poetry publish -r testpypi -u "__token__" -p "${{ secrets.TEST_PYPI_TOKEN }}" + poetry publish -u "__token__" -p "${{ secrets.PYPI_TOKEN }}" diff --git a/README.md b/README.md index 337cff0..d7e71da 100644 --- a/README.md +++ b/README.md @@ -148,3 +148,18 @@ Check out all the [published connectors](https://hub.meltano.com/singer/maintain | [target-yaml](https://github.com/MeltanoLabs/target-yaml) | Prerelease (Beta) | 🔭 Looking For Maintainers! 🔭 | [Link](https://hub.meltano.com/targets/yaml--meltanolabs) | | [target-snowflake](https://github.com/MeltanoLabs/target-snowflake) | Prerelease (Beta) | [Meltano](https://github.com/meltano) - Maintainer | - | | [target-jsonl-blob](https://github.com/MeltanoLabs/target-jsonl-blob) | Prerelease (Beta) | [Edgar Ramírez](https://github.com/edgarrmondragon) - Maintainer | - | + +## Common CI Workflows + +MeltanoLabs taps and targets can share workflows via the GitHub [Required Workflows](https://github.blog/2023-01-10-introducing-required-workflows-and-configuration-variables-to-github-actions/#:~:text=Required%20workflows%20allows%20DevOps%20teams,impossible%20task%20in%20large%20organizations.) feature. + +Repositories are "opted in" to shared workflows via the [Add Required Workflows](https://github.com/organizations/MeltanoLabs/settings/actions/required_workflows/new) GitHub web UI. + +When eligible for this behavior, and when the repo is opted-in by a MeltanoLabs administrator, common CI workflows may include (but are not necessarily limited to): + +1. Automated CI testing on currently-supported Python versions. +1. Automated verification of Semantic PR logic. +1. Release management using dynamic versioning. +1. Automated Release Notes drafting using Semantic PRs. + +For a full list of common workflows, see the `.github/workflows` directory within this repo. Each workflow should be self-documenting, including assumptions and behavior notes.