Skip to content

Commit

Permalink
Merge pull request #24 from AllenInstitute/feature/DT-6858-make-packa…
Browse files Browse the repository at this point in the history
…ge-public

Adding License, docs and placeholder workflows to make package public
  • Loading branch information
rpmcginty authored Dec 5, 2024
2 parents 9085cce + da2a002 commit 1dc2598
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 29 deletions.
150 changes: 126 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,139 @@
name: Create Release
name: Publish to PyPI

on:
# push:
# tags:
# - 'v*'

workflow_dispatch:
inputs:
tag:
description: 'Target Tag for Release'
type: string
part:
description: "Semver part to bump (major, minor, patch)"
type: choice
required: true
force:
description: 'Force Release?'
default: "patch"
options: ["major", "minor", "patch"]
dry-run:
description: "Dry run"
type: boolean
required: false
default: false
required: true
default: true
python-version:
description: "Python version used to build the distribution"
type: choice
required: true
default: "3.11"
options: ["3.9", "3.10", "3.11", "3.12"]

jobs:
create-release:
bump:
name: Bump version
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
outputs:
VERSION: ${{ steps.get-version-and-commit-sha.outputs.VERSION }}
SHORT_VERSION: ${{ steps.get-version-and-commit-sha.outputs.SHORT_VERSION }}
MAJOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MAJOR_VERSION }}
MINOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MINOR_VERSION }}
PATCH_VERSION: ${{ steps.get-version-and-commit-sha.outputs.PATCH_VERSION }}
COMMIT_SHA: ${{ steps.get-version-and-commit-sha.outputs.COMMIT_SHA }}
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ github.event.inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ github.event.inputs.python-version }}
cache: 'pip'
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/configure-org-repo-authorization
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
- name: Get tags
run: git fetch --tags origin
- name: Configure git for github-actions[bot]
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Run Install
run: |
make install-release
shell: bash
- name: Bump version with bumpversion
run: |
source .venv/bin/activate
bump-my-version bump ${{ github.event.inputs.part }}
- name: Commit and push with tags
if: ${{ github.event.inputs.dry-run == 'false' }}
run: |
git push --follow-tags
- name: Get version and commit SHA
id: get-version-and-commit-sha
run: |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
# remove the leading v from tag
version="${latest_tag:1}"
echo "VERSION=$version" >> $GITHUB_OUTPUT
major_version="$(cut -d '.' -f 1 <<< $version)"
echo "MAJOR_VERSION=$major_version" >> $GITHUB_OUTPUT
minor_version="$(cut -d '.' -f 2 <<< $version)"
echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT
patch_version="$(cut -d '.' -f 3 <<< $version)"
echo "PATCH_VERSION=$patch_version" >> $GITHUB_OUTPUT
short_version="$major_version.$minor_version"
echo "SHORT_VERSION=$short_version" >> $GITHUB_OUTPUT
commit_sha=$(git rev-parse $latest_tag)
echo "COMMIT_SHA=$commit_sha" >> $GITHUB_OUTPUT
- name: Show version
run: |
echo VERSION: ${{ steps.get-version-and-commit-sha.outputs.VERSION }}
echo SHORT_VERSION: ${{ steps.get-version-and-commit-sha.outputs.SHORT_VERSION }}
echo MAJOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MAJOR_VERSION }}
echo MINOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MINOR_VERSION }}
echo PATCH_VERSION: ${{ steps.get-version-and-commit-sha.outputs.PATCH_VERSION }}
echo COMMIT_SHA: ${{ steps.get-version-and-commit-sha.outputs.COMMIT_SHA }}
build:
name: Build distribution
runs-on: ubuntu-latest
needs: bump
if: ${{ github.event.inputs.dry-run == 'false' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Create Release with Changelog
id: create_release
uses: softprops/action-gh-release@v1
ref: ${{ needs.bump.outputs.COMMIT_SHA }}
- name: Set up Python ${{ github.event.inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ github.event.inputs.python-version }}
cache: 'pip'
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/configure-org-repo-authorization
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
- name: Run Release
run: |
make dist
shell: bash
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish to PyPI
needs: build
if: ${{ github.event.inputs.dry-run == 'false' }}
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/aibs-informatics-cdk-lib
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
name: Release ${{ github.event.inputs.tag || github.ref_name }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contributing to `aibs-informatics-cdk-lib`

Contributions are welcome and appreciated!

## Types of Contributions

### Reporting Bugs

Report bugs to our [issues page](https://github.com/aibs-informatics-cdk-lib/issues).

If you are reporting a bug, please include:

- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug, in the form of a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example).

### Making Changes

Look through the GitHub issues for bugs, features, and other requests. Most issues will have a label that can help you identify the type of issue.

### Submitting Feedback

The best way to send feedback is to [create an issue](https://github.com/aibs-informatics-cdk-lib/issues/new) on GitHub.

If you are proposing a feature:

- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that while contributions are welcome, developer/maintainer time is limited.
33 changes: 33 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Allen Institute Software License – This software license is the 2-clause BSD
license plus a third clause that prohibits redistribution and use for
commercial purposes without further permission.

Copyright © 2024. Allen Institute. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Redistributions and use for commercial purposes are not permitted without
the Allen Institute’s written permission. For purposes of this license,
commercial purposes are the incorporation of the Allen Institute's software
into anything for which you will charge fees or other compensation or use of
the software to perform a commercial service for a third party. Contact
[email protected] for commercial licensing opportunities.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ $(INSTALL_STAMP): $(PYTHON) $(DEP_FILES)
$(PIP) install -e .[dev];
@touch $(INSTALL_STAMP)

install-release: clean-install-stamp $(PYTHON) $(DEP_FILES) ## Installs package for release
@. $(VENV_BIN)/activate;\
$(PIP) install .[release]

install-force: clean-install-stamp install ## Force install package dependencies

link-packages: ## Link local packages to virtualenv
Expand Down Expand Up @@ -166,6 +170,10 @@ coverage-server: $(INSTALL_STAMP) ## Run coverage server
##@ Release Commands
#####################

dist: install-release ## Build source and wheel package
@. $(VENV_BIN)/activate;\
$(PYTHON) -m build;

reinstall: obliterate install ## Recreate environment and install

pre-build: obliterate ## Removes existing build environment
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# AIBS Informatics CDK Library

[![Build Status](https://github.com/AllenInstitute/aibs-informatics-cdk-lib/actions/workflows/build.yml/badge.svg)](https://github.com/AllenInstitute/aibs-informatics-cdk-lib/actions/workflows/build.yml)

---

## Overview

The AIBS Informatics CDK Library is a collection of AWS Cloud Development Kit (CDK) constructs and utilities designed to facilitate the deployment and management of cloud infrastructure for the Allen Institute for Brain Science. This library includes constructs for managing AWS Batch environments, Elastic File System (EFS) configurations, CloudWatch dashboards, and more. It aims to provide reusable and configurable components to streamline the development and deployment of cloud-based applications and services.

### Modules

- **Batch**: Constructs for setting up and managing AWS Batch environments, including job queues, compute environments, and monitoring.
- **EFS**: Utilities and constructs for configuring and managing Elastic File System (EFS) resources.
- **CloudWatch**: Tools for creating and managing CloudWatch dashboards and alarms.
- **Service Compute**: Constructs for defining compute resources, including Lambda functions and Batch compute environments.
- **State Machine Fragments**: Reusable fragments for AWS Step Functions, including batch job submission and data synchronization.
- **Assets**: Definitions and utilities for managing code assets, including Lambda functions and Docker images.
- **Core**: Base constructs and utilities used across the library, including environment configurations and common IAM policies.

## Contributing

Any and all PRs are welcome. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

## Licensing

This software is licensed under the Allen Institute Software License, which is the 2-clause BSD license plus a third clause that prohibits redistribution and use for commercial purposes without further permission. For more information, please visit [Allen Institute Terms of Use](https://alleninstitute.org/terms-of-use/).
46 changes: 43 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ dynamic = [
"version",
]
dependencies = [
"aibs-informatics-aws-utils @ git+ssh://[email protected]/AllenInstitute/aibs-informatics-aws-utils.git@main",
"aibs-informatics-core @ git+ssh://[email protected]/AllenInstitute/aibs-informatics-core.git@main",
"aibs-informatics-aws-utils",
"aibs-informatics-core",
"aws-cdk-lib~=2.96",
"constructs~=10.0",
"pydantic~=2.0",
]

[project.optional-dependencies]
dev = [
"aibs-informatics-test-resources",
"boto3-stubs[s3,batch]",
"aibs-informatics-test-resources @ git+ssh://[email protected]/AllenInstitute/aibs-informatics-test-resources.git@main",
]

release = [
"build",
"bump-my-version",
"wheel",
]

[tool.setuptools.dynamic]
Expand All @@ -40,6 +46,14 @@ version = {attr = "aibs_informatics_cdk_lib._version.__version__"}
[tool.setuptools.packages.find]
where = ["src"]


[project.urls]
Documentation = "https://.github.io/aibs-informatics-cdk-lib/"
Homepage = "https://github.com/AllenInstitute/aibs-informatics-cdk-lib/"
Issues = "https://github.com/AllenInstitute/aibs-informatics-cdk-lib/issues"
Repository = "https://github.com/AllenInstitute/aibs-informatics-cdk-lib/"


# -----------------------------------------------------------------------------
## Pyright Configurations
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md
Expand Down Expand Up @@ -210,3 +224,29 @@ profile = "black"
src_paths = ["src", "test"]
skip = [".venv", "build", "cdk.out"]

# -----------------------------------------------------------------------------
## bumpversion Configurations
# https://callowayproject.github.io/bump-my-version/
# -----------------------------------------------------------------------------

[tool.bumpversion]
allow_dirty = false
commit = true
commit_args = ""
current_version = "0.0.1"
ignore_missing_version = false
message = "Bump version: {current_version} → {new_version}"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
regex = false
replace = "{new_version}"
search = "{current_version}"
serialize = ["{major}.{minor}.{patch}"]
sign_tags = false
tag = true
tag_message = "Bump version: {current_version} → {new_version}"
tag_name = "v{new_version}"

[[tool.bumpversion.files]]
filename = "src/aibs_informatics_cdk_lib/_version.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
12 changes: 10 additions & 2 deletions src/aibs_informatics_cdk_lib/constructs_/dynamodb/table.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import inspect
from dataclasses import Field
from typing import Optional, Tuple, Type

import aws_cdk as cdk
from aibs_informatics_core.env import EnvBase
from aibs_informatics_core.models.db import DBIndex, DBModel
from aibs_informatics_core.utils.modules import load_type_from_qualified_name
from aws_cdk import aws_dynamodb as dynamodb
from constructs import Construct

Expand Down Expand Up @@ -88,9 +90,15 @@ def get_partition_and_sort_key(

@classmethod
def get_attribute_type(cls, field: Field) -> dynamodb.AttributeType:
if issubclass(field.type, int):
_type = field.type
if isinstance(_type, str):
_type = load_type_from_qualified_name(_type)
if not inspect.isclass(_type):
_type = _type.__class__

if issubclass(_type, int):
return dynamodb.AttributeType.NUMBER
elif issubclass(field.type, bytes):
elif issubclass(_type, bytes):
return dynamodb.AttributeType.BINARY
else:
return dynamodb.AttributeType.STRING
Expand Down

0 comments on commit 1dc2598

Please sign in to comment.