Add npm and Python package publishing workflows
This commit is contained in:
1 parent
01401cb1cd
commit
fa2fa4c8fd
3 files changed
+125
-19
No files matched your search
@@ -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
|
||||
@@ -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"/*
|
||||
@@ -59,31 +59,29 @@ SharedCode version has been validated.
|
||||
|
||||
## 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:
|
||||
|
||||
```bash
|
||||
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.
|
||||
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.
|
||||
The Python workflow uses Twine's `--skip-existing` option for the same reason.
|
||||
|
||||
## 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
|
||||
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:
|
||||
|
||||
```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:
|
||||
@@ -148,15 +146,15 @@ The Go module lives under `backend`, so its release tag must use the submodule p
|
||||
For Node services, install the shared package after publishing it:
|
||||
|
||||
```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
|
||||
python -m pip install build
|
||||
python -m build packages/python-backend
|
||||
python -m pip install gabriel20xx-shared-backend==0.1.0
|
||||
python -m pip install \
|
||||
--index-url "https://$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN@repos.gfranz.ch/api/packages/Gabriel20xx/pypi/simple" \
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user