Author SHA1 Message Date
Gabriel20xx 72a5e289f6 Add npm and Python package publishing workflows
Publish npm packages / Publish shared npm packages (push) Successful in 16s
Publish Python package / Publish shared Python package (push) Failing after 16s
2026-08-06 11:34:52 +02:00
Gabriel20xx 01401cb1cd Make release retry independent of tag script version 2026-08-06 10:59:26 +02:00
Gabriel20xx d3cb76dc32 Add Gitea release trigger for Go package publishing 2026-08-06 10:58:20 +02:00
Gabriel20xx 61b1eda37d Fix Go package output path handling 2026-08-06 10:40:23 +02:00
5 changed files with 142 additions and 24 deletions

No files matched your search

+9 -2
View File
@@ -4,6 +4,9 @@ on:
push: push:
tags: tags:
- 'backend/v*' - 'backend/v*'
release:
types:
- published
jobs: jobs:
publish: publish:
@@ -32,8 +35,12 @@ jobs:
- name: Package Go module - name: Package Go module
env: env:
RELEASE_TAG: ${{ github.ref_name }} RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name }}
run: bash scripts/package-go-module.sh "$RELEASE_TAG" "$RUNNER_TEMP/gitea-go-package" run: |
package_directory='gitea-go-package'
bash scripts/package-go-module.sh "$RELEASE_TAG" "$package_directory"
mkdir -p "$RUNNER_TEMP/gitea-go-package"
cp "$package_directory"/*.zip "$RUNNER_TEMP/gitea-go-package/"
- name: Publish to Gitea Package Registry - name: Publish to Gitea Package Registry
env: env:
+66
View File
@@ -0,0 +1,66 @@
name: Publish npm packages
on:
push:
tags:
- 'v*'
release:
types:
- published
jobs:
publish:
name: Publish shared npm packages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install and build packages
run: |
npm ci
npm run build
- name: Configure Gitea npm registry
env:
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
run: |
set -euo pipefail
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
exit 1
fi
npmrc_path="$RUNNER_TEMP/gitea-npmrc"
umask 077
{
printf '@gabriel20xx:registry=https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/\n'
printf '//repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken=%s\n' "$PACKAGE_REGISTRY_TOKEN"
printf 'always-auth=true\n'
} > "$npmrc_path"
printf 'NPM_CONFIG_USERCONFIG=%s\n' "$npmrc_path" >> "$GITHUB_ENV"
- name: Publish npm packages
env:
NPM_REGISTRY: https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/
run: |
set -euo pipefail
for package in \
@gabriel20xx/design-tokens \
@gabriel20xx/web-ui \
@gabriel20xx/node-backend; do
version="$(npm pkg get version --workspace="$package" | tr -d '"[:space:]')"
if npm view "$package@$version" version --registry="$NPM_REGISTRY" >/dev/null 2>&1; then
echo "$package@$version is already published; skipping."
else
npm publish --workspace="$package" --registry="$NPM_REGISTRY"
fi
done
+42
View File
@@ -0,0 +1,42 @@
name: Publish Python package
on:
push:
tags:
- 'v*'
release:
types:
- published
jobs:
publish:
name: Publish shared Python package
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build and publish package
env:
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
TWINE_REPOSITORY_URL: https://repos.gfranz.ch/api/packages/Gabriel20xx/pypi
run: |
set -euo pipefail
if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then
echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2
exit 1
fi
python -m pip install --disable-pip-version-check --no-cache-dir build twine
package_directory="$RUNNER_TEMP/gitea-pypi-package"
python -m build packages/python-backend --outdir "$package_directory"
TWINE_USERNAME="$PACKAGE_REGISTRY_USERNAME" \
TWINE_PASSWORD="$PACKAGE_REGISTRY_TOKEN" \
python -m twine upload --non-interactive --skip-existing "$package_directory"/*
+18 -20
View File
@@ -59,31 +59,29 @@ SharedCode version has been validated.
## Publish the individual packages ## Publish the individual packages
The package names use the `@gabriel20xx` npm scope. That scope must belong to the npm account used to publish. If a different scope is preferred, replace the scope consistently in both package manifests and imports before publishing. The package names use the `@gabriel20xx` npm scope. The `publish-npm.yml` and
`publish-python.yml` Gitea workflows publish the packages when a `v*` tag is pushed or a
matching Gitea release is published. Configure `PACKAGE_REGISTRY_USERNAME` and
`PACKAGE_REGISTRY_TOKEN` as user Actions secrets before publishing.
Publish the tokens first because `web-ui` depends on them: The npm workflow publishes `design-tokens` first because `web-ui` depends on it. It also
skips an npm version that is already present, so retrying a partially completed release is safe.
```bash The Python workflow uses Twine's `--skip-existing` option for the same reason.
npm login
npm publish --workspace=@gabriel20xx/design-tokens --access public
npm publish --workspace=@gabriel20xx/web-ui --access public
npm publish --workspace=@gabriel20xx/node-backend --access public
```
For a private registry, configure that registry and omit `--access public` if the registry does not use npm's public scoped-package rules.
## Install individual packages from a registry ## Install individual packages from a registry
From a project's frontend directory, install the published UI package: From a project's frontend directory, install the published UI package from Gitea:
```bash ```bash
npm install @gabriel20xx/web-ui@^0.1.0 npm config set @gabriel20xx:registry https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/
npm config set //repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken "$PACKAGE_REGISTRY_TOKEN"
npm install @gabriel20xx/web-ui@0.1.0
``` ```
The design-token package is installed transitively. Install it directly only when an application needs to reference its theme file itself: The design-token package is installed transitively. Install it directly only when an application needs to reference its theme file itself:
```bash ```bash
npm install @gabriel20xx/design-tokens@^0.1.0 npm install @gabriel20xx/design-tokens@0.1.0
``` ```
Import the shared stylesheet once from the application's global stylesheet, before project-specific overrides: Import the shared stylesheet once from the application's global stylesheet, before project-specific overrides:
@@ -143,20 +141,20 @@ Use `auth.SchemaOptions{SingleUser: false, APITokens: true}` for a multi-user se
For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")`. The package does not contain application tables, so migrations remain versioned with the service that owns those tables. For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")`. The package does not contain application tables, so migrations remain versioned with the service that owns those tables.
The Go module lives under `backend`, so its release tag must use the submodule prefix (`backend/v0.1.0`). The consuming `go.mod` uses the normal module version (`v0.1.0`). To publish a release, push a tag such as `backend/v0.1.0`; the Gitea workflow packages the module and uploads it to the private registry. Never reuse an existing package version. The Go module lives under `backend`, so its release tag must use the submodule prefix (`backend/v0.1.0`). The consuming `go.mod` uses the normal module version (`v0.1.0`). To publish a release, push a tag such as `backend/v0.1.0`; the Gitea workflow packages the module and uploads it to the private registry. The workflow also listens for Gitea's `release.published` event, so a release can be published from the Gitea Releases page to manually retry a failed upload for an existing tag. Never reuse a package version that was already uploaded successfully.
For Node services, install the shared package after publishing it: For Node services, install the shared package after publishing it:
```bash ```bash
npm install @gabriel20xx/node-backend@^0.1.0 npm install @gabriel20xx/node-backend@0.1.0
``` ```
For Python services, build and publish the wheel to the Python package index used by the projects, then install it normally: For Python services, configure the Gitea index and install the published wheel:
```bash ```bash
python -m pip install build python -m pip install \
python -m build packages/python-backend --index-url "https://$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN@repos.gfranz.ch/api/packages/Gabriel20xx/pypi/simple" \
python -m pip install gabriel20xx-shared-backend==0.1.0 gabriel20xx-shared-backend==0.1.0
``` ```
The Node and Python packages intentionally expose the same infrastructure concepts but use their native database drivers. This is the safe way to share behavior across the polyglot services; a Go package cannot be imported by the Python or Node applications. The Node and Python packages intentionally expose the same infrastructure concepts but use their native database drivers. This is the safe way to share behavior across the polyglot services; a Go package cannot be imported by the Python or Node applications.
+7 -2
View File
@@ -33,8 +33,13 @@ git archive --format=tar "$release_tag" "$module_directory" \
test -f "$module_root/go.mod" test -f "$module_root/go.mod"
grep -Fxq "module $module_path" "$module_root/go.mod" grep -Fxq "module $module_path" "$module_root/go.mod"
mkdir -p "$repository_root/$output_directory" if [[ "$output_directory" = /* ]]; then
zip_file="$repository_root/$output_directory/${module_path//\//_}@${version}.zip" output_path="$output_directory"
else
output_path="$repository_root/$output_directory"
fi
mkdir -p "$output_path"
zip_file="$output_path/${module_path//\//_}@${version}.zip"
rm -f "$zip_file" rm -f "$zip_file"
( (