Bump actions/checkout from 4 to 5 #971
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-project | |
on: | |
push: | |
pull_request: | |
branches: main | |
release: | |
types: [published] | |
env: | |
REGISTRY_GITHUB: ghcr.io | |
jobs: | |
variables: | |
outputs: | |
ref_name: ${{ steps.var.outputs.ref_name}} | |
image_name: ${{ steps.var.outputs.image_name }} | |
ghcr_image: ${{ steps.var.outputs.ghcr_image }} | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: Setting global variables | |
uses: actions/github-script@v7 | |
id: var | |
with: | |
script: | | |
core.setOutput('ref_name', '${{ github.ref_name }}'.toLowerCase().replaceAll(/[/.]/g, '-').trim('-')); | |
core.setOutput('image_name', '${{ github.repository }}'.toLowerCase()); | |
core.setOutput('ghcr_image', '${{ env.REGISTRY_GITHUB }}/${{ github.repository }}'.toLowerCase()); | |
build-service: | |
runs-on: ubuntu-latest | |
needs: [variables] | |
env: | |
REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
permissions: | |
id-token: write | |
contents: write | |
strategy: | |
matrix: | |
python-version: | |
- "3.11" | |
- "3.12" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache Python packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/pip | |
!~/.cache/pip/log | |
key: ${{ runner.os }}-python-${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-python-${{ matrix.python-version }}-pip- | |
${{ runner.os }}-python-${{ matrix.python-version }}- | |
${{ runner.os }}-python- | |
${{ runner.os }}-pip- | |
- name: Install build package | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Build package | |
run: python -m build | |
- name: Save python artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-artifacts-${{ matrix.python-version }}-${{ env.REF_NAME }} | |
path: | | |
dist | |
- name: Publish package to pypi | |
if: ${{github.event_name == 'release' && matrix.python-version == '3.12'}} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: dist/ | |
- name: Publish assets to github | |
if: ${{github.event_name == 'release' && matrix.python-version == '3.12'}} | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ github.token }} | |
file: dist/* | |
tag: ${{ github.ref }} | |
overwrite: true | |
file_glob: true | |
build-docker: | |
runs-on: ubuntu-latest | |
needs: [variables, build-service] | |
env: | |
REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
IMAGE_NAME: ${{ needs.variables.outputs.image_name }} | |
GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }} | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
arch: [amd64, arm64, arm/v7] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
- name: Install setuptools-scm and tomli | |
run: pip install setuptools-scm[toml]>=8 tomli | |
- name: Generate static version.json | |
run: python freeze_version.py | |
- name: Generate requirements hashFiles | |
run: python generate_requirements.py | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@master | |
with: | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
- name: Log in to the Docker github container registry | |
if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY_GITHUB }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to the Docker container registry | |
if: ${{github.event_name == 'release'}} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Map platform to tag suffix | |
id: archmap | |
run: | | |
case "${{ matrix.arch }}" in | |
amd64) echo "ARCH_TAG=amd64" >> $GITHUB_ENV ;; | |
arm64) echo "ARCH_TAG=arm64" >> $GITHUB_ENV ;; | |
arm/v7) echo "ARCH_TAG=armv7" >> $GITHUB_ENV ;; | |
esac | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.GHCR_IMAGE }} | |
${{ github.event_name == 'release' && env.IMAGE_NAME || '' }} | |
tags: | | |
type=raw,value=latest-${{ env.ARCH_TAG }},enable=${{ github.event_name == 'release' }} | |
type=raw,value=${{ env.REF_NAME }}-${{ env.ARCH_TAG }},enable=${{ github.event_name != 'release' }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
platforms: linux/${{ matrix.arch }} | |
push: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
tags: ${{ steps.meta.outputs.tags }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }} | |
cache-to: type=gha,mode=max,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }} | |
merge-manifest: | |
runs-on: ubuntu-latest | |
needs: [variables, build-docker] | |
env: | |
REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
IMAGE_NAME: ${{ needs.variables.outputs.image_name }} | |
GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }} | |
if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
- name: Log in to the Docker github container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY_GITHUB }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to the Docker container registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.GHCR_IMAGE }} | |
${{ github.event_name == 'release' && env.IMAGE_NAME || '' }} | |
tags: | | |
type=raw,value=latest,enable=${{ github.event_name == 'release' }} | |
type=raw,value=${{ env.REF_NAME }},enable=${{ github.event_name != 'release' }} | |
- name: Create and push multi-arch manifest | |
run: | | |
set -eux | |
if [ "${{ github.event_name }}" == "release" ]; then | |
docker buildx imagetools create \ | |
-t ${{ env.GHCR_IMAGE }}:latest \ | |
${{ env.GHCR_IMAGE }}:latest-amd64 \ | |
${{ env.GHCR_IMAGE }}:latest-arm64 \ | |
${{ env.GHCR_IMAGE }}:latest-armv7 | |
docker buildx imagetools create \ | |
-t ${{ env.IMAGE_NAME }}:latest \ | |
${{ env.IMAGE_NAME }}:latest-amd64 \ | |
${{ env.IMAGE_NAME }}:latest-arm64 \ | |
${{ env.IMAGE_NAME }}:latest-armv7 | |
else | |
docker buildx imagetools create \ | |
-t ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }} \ | |
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-amd64 \ | |
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-arm64 \ | |
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-armv7 | |
fi |