Skip to content

Commit

Permalink
Initial project commit, basic functionality intact.
Browse files Browse the repository at this point in the history
Added:
- All base functionality.
- GitHub Actions to build and publish Python packages and container
  images.
  • Loading branch information
Sidneys1 committed Jun 11, 2024
2 parents cd61450 + 9c2ea06 commit bf47e2e
Show file tree
Hide file tree
Showing 13 changed files with 965 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Global Ownership
* @sidneys1
1 change: 1 addition & 0 deletions .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags: ["v*.*"]
branches: ["main"]
paths: ["/src/**", "/.gitignore", "/Containerfile", "/hatch_build.py", "/pyproject.toml", "/README.md"]
pull_request:

env:
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Publish Releases
name: Python Package CI

on:
release:
Expand All @@ -20,6 +20,17 @@ jobs:
pip install
hatch
--user
- name: Compile CSS from SCSS files
uses: gha-utilities/[email protected]
with:
source: |
./src/memoria/web/www/static/styles.scss
./src/memoria/web/www/templates/settings.scss
./src/memoria/web/www/templates/index.scss
destination: |
./src/memoria/web/www/static/styles.css
./src/memoria/web/www/templates/settings.css
./src/memoria/web/www/templates/index.css
- name: Build a binary wheel and a source tarball
run: python3 -m hatch build
- name: Store the distribution packages
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ src/memoria/web/www/templates/*.css
src/memoria/web/www/templates/*.css.map
src/memoria/web/www/static/*.css
src/memoria/web/www/static/*.css.map

# Misc
TODO.md
get-ff-sync.sh
/data/
/secrets/
47 changes: 47 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Building
========

For instructions on performing a release, see the [Contribution Guide](./CONTRIBUTING.md#performing-a-release).

Python
------

Memoria is built using the Python build system [Hatch][hatch]. To build a wheel or source tarball, you must:

1. Ensure Sass runs against any files in the [templates][templates-folder] and [static][static-folder] web content
folders.

```sh
# For example, using NPX:
npx sass src/memoria/web/www/static/:src/memoria/web/www/static/ \
src/memoria/web/www/templates/:src/memoria/web/www/templates/
```

2. Build the package with `hatch build`:

```sh
hatch build
```

The resulting source archive and wheel will be output in `./dist`.

[hatch]: https://github.com/pypa/hatch
[templates-folder]: ./src/memoria/web/www/templates/
[static-folder]: ./src/memoria/web/www/static/

Containers
----------

The [Containerfile](./Containerfile) builds Memoria entirely, including running Sass:

```sh
podman build -t ghcr.io/sidneys1/memoria .
# Or
podman-compose build memoria
# If using the Docker toolchain you may need to provide the -f parameter:
docker build -f Containerfile -t ghcr.io/sidneys1/memoria .
# Or
docker-compose -f compose.yaml build memoria
```
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Changelog
=========

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

v0.1 - 2024-06-06
-----------------

Initial project commit, basic functionality intact.

### Added

- All base functionality.
- GitHub Actions to build and publish Python packages and container images.

<!--------------------------------------------------------------------------------------------------------------------->

<!--
{version}
---------
General description of this release.
Any additional notes for this release.
### Added
<!~~ List of things that have been added. Be sure to @mention contributors, #tag relevant discussions/issues/PRs. ~~>
- A changelog (@sidneys1).
### Changed
### Deprecated
### Removed
### Fixed
### Security
-->
117 changes: 117 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Contributing
============

General guidelines:
- So far the code has been using [isort] and [yapf] for formatting.
- Comments shouldn't be useless (e.g., describing obvious code).
- Documentation and commit messages[^1] should all be in Markdown.

[isort]: https://github.com/PyCQA/isort
[yapf]: https://github.com/google/yapf
[^1]: The first line should be generally unformatted. Backticks and GitHub references are allowed.

Performing a Release
--------------------

1. Commit the following changes in a pull request to bring the release branch (e.g., `v0.1`) into `main`:
- Ensure the version in [`__about__.py`][version-file] has been updated. This can be done manually or with Hatch.

<details><summary>Updating the version with Hatch</summary>

`hatch version <desired-version>` can be used to set the version automatically. `hatch version <segment>` can be used
to increment the specified [segment][hatch-segments]. Some examples:

```sh
hatch version # Get current version
# 0.1b

hatch version 0.1 # Set version to 0.1
# Old: 0.1b
# New: 0.1

hatch version minor # Increment the minor version.
# Old: 0.1b
# New: 0.2

hatch version major # Increment the major version. `hatch version release` would do the same.
# Old: 0.1b
# New: 1.0
```

</details>

- Update the [Changelog](./CHANGELOG.md) with release notes. You may need to view the commit history since the last
release to identify any changes that were missed.

2. A maintainer will merge the above PR using a signed merge commit:

```sh
# Using "v0.1a" as an example version
git checkout main
git merge --no-ff --sign --edit ${target as specified in PR}
```

An editor will open, enter the changelog section for this release, with [some formatting tweaks][tweaks].

Don't forget to `git push` the merge commit.
3. A maintainer will create a signed and annotated tag with the current release's release notes:

```sh
# Using "v0.1a" as an example version
git tag --gpg-sign v0.1a
```

An editor will open, enter the changelog section for this release, with [some formatting tweaks][tweaks] (same as the
merge commit).

Don't forget to `git push origin refs/tags/v0.1a` (for example).
4. A maintainer will create [a new GitHub release][gh-release] for the tag that was just created. The title will be the
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) version of the release. The release notes will be the same
[tweaked][tweaks] content of the changelog as the merge commit and tag.
If the release is a pre-release (`a`, `b`, or `rc` suffixes) make sure to check the "Set as a pre-release" box.
> [!NOTE]
> The release packages for Memoria are all generated by GitHub Actions. No manual action is required.
[hatch-segments]: https://hatch.pypa.io/dev/version/#supported-segments
[version-file]: ./src/memoria/__about__.py
[tweaks]: #tweaking-the-changelog-for-git-messages
[gh-release]: https://github.com/Sidneys1/Memoria/releases/new
---
Tweaking the Changelog for Git Messages
---------------------------------------
You'll want to exclude the level 2 heading, and convert the level 3 headings to nested lists. You can otherwise keep
Markdown formatting intact.

<details><summary>Example</summary>

As an example example, for this changelog section:

```md
v0.1a
-----
A release!
### Added
- Added a *brand new* [changelog](./CHANGELOG.md).
```

You would enter the following:

```md
A release!
Added:
- Added a *brand new* [changelog](./CHANGELOG.md).
```

</details>
16 changes: 14 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ FROM scratch AS source
COPY pyproject.toml README.md hatch_build.py /
COPY src/ /src/

FROM alpine:latest AS sass
ARG DART_SASS_VERSION=1.77.4
ARG DART_SASS_TAR=dart-sass-${DART_SASS_VERSION}-linux-x64-musl.tar.gz
ARG DART_SASS_URL=https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/${DART_SASS_TAR}
ADD ${DART_SASS_URL} /opt/
RUN cd /opt/ && tar -xzf ${DART_SASS_TAR} && rm ${DART_SASS_TAR}
RUN --mount=type=bind,from=source,target=/memoria,source=/,rw \
mkdir -p /tmp/static && mkdir /tmp/templates \
&& cd /memoria/src/memoria/web/www && /opt/dart-sass/sass static/:/tmp/static/ templates/:/tmp/templates/

FROM python:3.12-alpine
CMD ["uvicorn", "memoria.web:APP", "--host", "0.0.0.0", "--port", "80"]
EXPOSE 80
RUN --mount=type=bind,from=source,target=/memoria,source=/,rw --mount=type=cache,target=/cache --mount=type=tmpfs,target=/temp \
TMPDIR=/temp python -m pip install --cache-dir=/cache /memoria[uvicorn] \
RUN --mount=type=bind,from=source,target=/memoria,source=/,rw --mount=type=bind,from=sass,target=/sass,source=/tmp,ro --mount=type=cache,target=/cache --mount=type=tmpfs,target=/temp \
find /memoria -iname '*.scss' -delete \
&& cp -rt /memoria/src/memoria/web/www /sass/* \
&& TMPDIR=/temp python -m pip install --cache-dir=/cache /memoria[uvicorn] \
&& mkdir /data
Loading

0 comments on commit bf47e2e

Please sign in to comment.