publish.yml•3.15 kB
name: Publish Package
on:
release:
types: [published]
permissions:
contents: read
packages: write
jobs:
deploy-test:
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
- name: Build package with Nix
run: |
nix develop --command build
ls -la dist/
- name: Publish package to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
deploy-prod:
needs: deploy-test
runs-on: ubuntu-latest
# Only deploy to PyPI for non-prerelease versions
if: ${{ !github.event.release.prerelease }}
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
- name: Build package with Nix
run: |
nix develop --command build
ls -la dist/
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
docker:
needs: deploy-test
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
utensils/mcp-nixos
ghcr.io/utensils/mcp-nixos
tags: |
# Latest tag for stable releases
type=raw,value=latest,enable=${{ !github.event.release.prerelease }}
# Version tag from release
type=semver,pattern={{version}}
# Major.minor tag
type=semver,pattern={{major}}.{{minor}}
# Major tag (only for stable releases)
type=semver,pattern={{major}},enable=${{ !github.event.release.prerelease }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64