Files
presidio/.github/workflows/release.yml
2025-10-23 20:52:30 +03:00

157 lines
4.6 KiB
YAML

name: Release
on:
workflow_dispatch:
permissions: read-all
env:
REGISTRY_NAME: ${{ secrets.ACR_NAME }}.azurecr.io
IMAGE_PREFIX: "public/"
jobs:
get-version:
name: Get Version Numbers
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
image-version: ${{ steps.set-image-version.outputs.image-version }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Extract main version
id: set-version
run: |
set -eu
ver=$(grep -m 1 version presidio-analyzer/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
echo "version=$ver" >> $GITHUB_OUTPUT
echo "Main version: $ver"
- name: Extract image-redactor version
id: set-image-version
run: |
set -eu
imageVer=$(grep -m 1 version presidio-image-redactor/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
echo "image-version=$imageVer" >> $GITHUB_OUTPUT
echo "Image-redactor version: $imageVer"
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: get-version
permissions:
contents: write
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ needs.get-version.outputs.version }}" \
--title "Release ${{ needs.get-version.outputs.version }}" \
--notes "" \
--draft \
--latest
publish-to-pypi:
name: Publish ${{ matrix.package.name }} to PyPI
runs-on: ubuntu-latest
needs: get-version
permissions:
id-token: write # Required for trusted publishing to PyPI
strategy:
fail-fast: false
matrix:
package:
- name: "Analyzer"
path: "presidio-analyzer"
- name: "Anonymizer"
path: "presidio-anonymizer"
- name: "Image-Redactor"
path: "presidio-image-redactor"
- name: "Structured"
path: "presidio-structured"
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build wheel package
working-directory: ${{ matrix.package.path }}
run: |
python -m build --wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1.13.0
with:
packages-dir: ${{ matrix.package.path }}/dist/
skip-existing: true
build-and-push-containers:
name: Build and Push Containers
runs-on: ubuntu-latest
needs: get-version
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
image: [presidio-anonymizer, presidio-analyzer, presidio-image-redactor]
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Azure Login using OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log in to Azure Container Registry
run: az acr login --name ${{ secrets.ACR_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push ${{ matrix.image }}
run: |
repo="${{ env.REGISTRY_NAME }}/${{ env.IMAGE_PREFIX }}${{ matrix.image }}"
version_tag="${{ matrix.image == 'presidio-image-redactor' && needs.get-version.outputs.image-version || needs.get-version.outputs.version }}"
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=${repo}:latest \
--cache-to type=inline \
--tag ${repo}:latest \
--tag ${repo}:${version_tag} \
--attest type=sbom \
--attest type=provenance,mode=max \
--push \
./${{ matrix.image }}
env:
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}
IMAGE_PREFIX: ${{ env.IMAGE_PREFIX }}