| 1 |
# Copyright (C) 2025 Siemens |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: MIT |
| 4 |
|
| 5 |
name: Publish |
| 6 |
|
| 7 |
on: |
| 8 |
push: |
| 9 |
tags: |
| 10 |
- 'v[0-9]+.[0-9]+.[0-9]+' |
| 11 |
|
| 12 |
permissions: |
| 13 |
contents: read |
| 14 |
|
| 15 |
jobs: |
| 16 |
release-build: |
| 17 |
runs-on: ubuntu-24.04 |
| 18 |
|
| 19 |
steps: |
| 20 |
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 21 |
|
| 22 |
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 23 |
with: |
| 24 |
python-version: "3.x" |
| 25 |
|
| 26 |
- name: Build release distributions |
| 27 |
run: | |
| 28 |
python -m pip install build |
| 29 |
python -m build |
| 30 |
|
| 31 |
- name: Upload distributions |
| 32 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 33 |
with: |
| 34 |
name: release-dists |
| 35 |
path: dist/ |
| 36 |
|
| 37 |
pypi-publish: |
| 38 |
runs-on: ubuntu-24.04 |
| 39 |
needs: |
| 40 |
- release-build |
| 41 |
permissions: |
| 42 |
id-token: write |
| 43 |
|
| 44 |
# Run only on the official repository (skip forks) |
| 45 |
if: github.repository == 'siemens/debsbom' |
| 46 |
|
| 47 |
environment: |
| 48 |
name: pypi |
| 49 |
url: https://pypi.org/project/debsbom/${{ github.ref_name }} |
| 50 |
|
| 51 |
steps: |
| 52 |
- name: Retrieve release distributions |
| 53 |
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 |
| 54 |
with: |
| 55 |
name: release-dists |
| 56 |
path: dist/ |
| 57 |
|
| 58 |
- name: Publish release distributions to PyPI |
| 59 |
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e |
| 60 |
|
| 61 |
deploy_containers: |
| 62 |
name: Build and deploy container images |
| 63 |
runs-on: ubuntu-24.04 |
| 64 |
permissions: |
| 65 |
id-token: write |
| 66 |
packages: write |
| 67 |
contents: read |
| 68 |
attestations: write |
| 69 |
steps: |
| 70 |
- name: Check out repo |
| 71 |
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 72 |
- name: Get release |
| 73 |
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 74 |
- name: Set up docker build |
| 75 |
uses: ./.github/actions/docker-init |
| 76 |
with: |
| 77 |
deploy-user: ${{ github.actor }} |
| 78 |
deploy-token: ${{ secrets.GITHUB_TOKEN }} |
| 79 |
- name: Find latest tag |
| 80 |
run: echo "LATEST_TAG=$(git tag | sort --version-sort | tail -n1)" >> $GITHUB_ENV |
| 81 |
- name: Build image |
| 82 |
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 |
| 83 |
id: push |
| 84 |
with: |
| 85 |
context: /home/runner/debsbom-clone |
| 86 |
target: debsbom |
| 87 |
platforms: linux/amd64,linux/arm64 |
| 88 |
build-args: | |
| 89 |
SOURCE_DATE_EPOCH=${{ env.SOURCE_DATE_EPOCH }} |
| 90 |
DEBIAN_TAG=${{ env.DEBIAN_TAG }} |
| 91 |
provenance: false |
| 92 |
outputs: type=registry,rewrite-timestamp=true |
| 93 |
tags: | |
| 94 |
ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }} |
| 95 |
${{ github.ref_name == env.LATEST_TAG && format('ghcr.io/{0}:latest-release', github.repository) || '' }} |
| 96 |
annotations: ${{ env.DOCKER_METADATA_OUTPUT_ANNOTATIONS }} |
| 97 |
- name: Attest image |
| 98 |
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 |
| 99 |
with: |
| 100 |
subject-name: ghcr.io/${{ github.repository }} |
| 101 |
subject-digest: ${{ steps.push.outputs.digest }} |
| 102 |
push-to-registry: true |