Skip to content

Commit

Permalink
Unify common infrastructure (#30)
Browse files Browse the repository at this point in the history
* use `hatch` as build system
* added `.codegen.json` for releasing
* added github actions
* fixed `make fmt` warnings
  • Loading branch information
nfx authored Sep 11, 2024
1 parent 12467d5 commit 3dd9ca9
Show file tree
Hide file tree
Showing 33 changed files with 1,261 additions and 398 deletions.
14 changes: 14 additions & 0 deletions .codegen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": {
"src/databricks/labs/pytester/__about__.py": "__version__ = \"$VERSION\""
},
"toolchain": {
"required": ["python3", "hatch"],
"pre_setup": ["hatch env create"],
"prepend_path": ".venv/bin",
"acceptance_path": "tests/integration",
"test": [
"pytest -n 4 --cov src --cov-report=xml --timeout 30 tests/unit --durations 20"
]
}
}
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST -->
## Changes
<!-- Summary of your changes that are easy to understand. Add screenshots when necessary -->

### Linked issues
<!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword -->

Resolves #..

### Tests
<!-- How is this tested? Please see the checklist below and also describe any other relevant tests -->

- [ ] manually tested
- [ ] added unit tests
- [ ] added integration tests
- [ ] verified on staging environment (screenshot attached)
55 changes: 55 additions & 0 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: acceptance

on:
pull_request:
types: [ opened, synchronize, ready_for_review ]
merge_group:
types: [ checks_requested ]
push:
branches:
- main

permissions:
id-token: write
contents: read
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
integration:
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
environment: account-admin
runs-on: larger
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Python
uses: actions/setup-python@v5
with:
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
python-version: '3.10'

- name: Install hatch
run: pip install hatch==1.9.4

- name: Fetch relevant branches
run: |
git fetch origin $GITHUB_BASE_REF:$GITHUB_BASE_REF
git fetch origin $GITHUB_HEAD_REF:$GITHUB_HEAD_REF
- name: Run integration tests
uses: databrickslabs/sandbox/acceptance@acceptance/v0.2.2
with:
vault_uri: ${{ secrets.VAULT_URI }}
timeout: 55m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
47 changes: 47 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: nightly

on:
workflow_dispatch:
schedule:
- cron: '0 5 * * *'

permissions:
id-token: write
issues: write
contents: read
pull-requests: read

concurrency:
group: single-acceptance-job-per-repo

jobs:
integration:
environment: account-admin
runs-on: larger
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Python
uses: actions/setup-python@v5
with:
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
python-version: '3.10'

- name: Install hatch
run: pip install hatch==1.9.4

- name: Run nightly tests
uses: databrickslabs/sandbox/acceptance@acceptance/v0.2.2
with:
vault_uri: ${{ secrets.VAULT_URI }}
timeout: 55m
create_issues: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
TEST_NIGHTLY: true
32 changes: 32 additions & 0 deletions .github/workflows/no-cheat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: no-cheat

on:
pull_request:
types: [opened, synchronize]
merge_group:
types: [checks_requested]
push:
# required for merge queue to work. jobs.integration.if will mark it as skipped
branches:
- main

jobs:
no-pylint-disable:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Verify no additional disabled lint in the new code
run: |
git fetch origin $GITHUB_BASE_REF:$GITHUB_BASE_REF
git diff $GITHUB_BASE_REF...$(git branch --show-current) >> diff_data.txt
python tests/unit/no_cheat.py diff_data.txt >> cheats.txt
COUNT=$(cat cheats.txt | wc -c)
if [ ${COUNT} -gt 1 ]; then
cat cheats.txt
exit 1
fi
75 changes: 75 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: build

on:
pull_request:
types: [opened, synchronize]
merge_group:
types: [checks_requested]
push:
# Always run on push to main. The build cache can only be reused
# if it was saved by a run from the repository's default branch.
# The run result will be identical to that from the merge queue
# because the commit is identical, yet we need to perform it to
# seed the build cache.
branches:
- main

env:
HATCH_VERSION: 1.9.4

jobs:
ci:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pyVersion: [ '3.10', '3.11', '3.12' ]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Python
uses: actions/setup-python@v5
with:
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
python-version: ${{ matrix.pyVersion }}

- name: Install hatch
run: pip install hatch==$HATCH_VERSION

- name: Run unit tests
run: hatch run test

- name: Publish test coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Python
uses: actions/setup-python@v5
with:
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
python-version: 3.10.x

- name: Install hatch
run: pip install hatch==$HATCH_VERSION

- name: Reformat code
run: make fmt

- name: Fail on differences
run: |
# Exit with status code 1 if there are differences (i.e. unformatted files)
git diff --exit-code
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest
environment: release
permissions:
# Used to authenticate to PyPI via OIDC and sign the release's artifacts with sigstore-python.
id-token: write
# Used to attach signing artifacts to the published release.
contents: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
python-version: '3.10'

- name: Build wheels
run: |
pip install hatch==1.9.4
hatch build
- name: Draft release
uses: softprops/action-gh-release@v2
with:
files: |
dist/databricks_*.whl
dist/databricks_*.tar.gz
- uses: pypa/gh-action-pypi-publish@release/v1
name: Publish package distributions to PyPI

- name: Sign artifacts with Sigstore
uses: sigstore/[email protected]
with:
inputs: |
dist/databricks_*.whl
dist/databricks_*.tar.gz
release-signing-artifacts: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
.pytest_cache
*.egg-info
tests/**/build
.coverage
coverage.xml
pytester.iml
69 changes: 69 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Databricks License
Copyright (2023) Databricks, Inc.

Definitions.

Agreement: The agreement between Databricks, Inc., and you governing
the use of the Databricks Services, as that term is defined in
the Master Cloud Services Agreement (MCSA) located at
www.databricks.com/legal/mcsa.

Licensed Materials: The source code, object code, data, and/or other
works to which this license applies.

Scope of Use. You may not use the Licensed Materials except in
connection with your use of the Databricks Services pursuant to
the Agreement. Your use of the Licensed Materials must comply at all
times with any restrictions applicable to the Databricks Services,
generally, and must be used in accordance with any applicable
documentation. You may view, use, copy, modify, publish, and/or
distribute the Licensed Materials solely for the purposes of using
the Licensed Materials within or connecting to the Databricks Services.
If you do not agree to these terms, you may not view, use, copy,
modify, publish, and/or distribute the Licensed Materials.

Redistribution. You may redistribute and sublicense the Licensed
Materials so long as all use is in compliance with these terms.
In addition:

- You must give any other recipients a copy of this License;
- You must cause any modified files to carry prominent notices
stating that you changed the files;
- You must retain, in any derivative works that you distribute,
all copyright, patent, trademark, and attribution notices,
excluding those notices that do not pertain to any part of
the derivative works; and
- If a "NOTICE" text file is provided as part of its
distribution, then any derivative works that you distribute
must include a readable copy of the attribution notices
contained within such NOTICE file, excluding those notices
that do not pertain to any part of the derivative works.

You may add your own copyright statement to your modifications and may
provide additional license terms and conditions for use, reproduction,
or distribution of your modifications, or for any such derivative works
as a whole, provided your use, reproduction, and distribution of
the Licensed Materials otherwise complies with the conditions stated
in this License.

Termination. This license terminates automatically upon your breach of
these terms or upon the termination of your Agreement. Additionally,
Databricks may terminate this license at any time on notice. Upon
termination, you must permanently delete the Licensed Materials and
all copies thereof.

DISCLAIMER; LIMITATION OF LIABILITY.

THE LICENSED MATERIALS ARE PROVIDED “AS-IS” AND WITH ALL FAULTS.
DATABRICKS, ON BEHALF OF ITSELF AND ITS LICENSORS, SPECIFICALLY
DISCLAIMS ALL WARRANTIES RELATING TO THE LICENSED MATERIALS, EXPRESS
AND IMPLIED, INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES,
CONDITIONS AND OTHER TERMS OF MERCHANTABILITY, SATISFACTORY QUALITY OR
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. DATABRICKS AND
ITS LICENSORS TOTAL AGGREGATE LIABILITY RELATING TO OR ARISING OUT OF
YOUR USE OF OR DATABRICKS’ PROVISIONING OF THE LICENSED MATERIALS SHALL
BE LIMITED TO ONE THOUSAND ($1,000) DOLLARS. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS OR
THE USE OR OTHER DEALINGS IN THE LICENSED MATERIALS.
Loading

0 comments on commit 3dd9ca9

Please sign in to comment.