Skip to content

Merge develop into main #69

Merge develop into main

Merge develop into main #69

Workflow file for this run

---
name: CI
on: # yamllint disable-line rule:truthy
push:
branches:
- main
- develop
tags:
- v*.*.*
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
env:
POETRY_VERSION: 1.8.3
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
strategy:
matrix:
python-version:
- '3.10'
- '3.11'
- '3.12'
steps:
- name: Checkout the repository
uses: actions/[email protected]
with:
submodules: recursive
- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Get the precise Python version
run: echo "PYTHON_ID=$( python -VV | sha256sum | awk '{ print $1 }' )" >> "$GITHUB_ENV"
- name: Load the cached Poetry installation
id: cached-poetry
uses: actions/[email protected]
with:
path: ~/.local
key: poetry-${{ env.POETRY_VERSION }}-py_${{ env.PYTHON_ID}}-0
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/[email protected]
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load the cached dependencies
id: cached-deps
uses: actions/[email protected]
with:
path: .venv
key: py${{ matrix.python-version }}-deps-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-deps.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Perform package installation
run: poetry install --no-interaction
- name: Run tests
env:
HS_ENDPOINT: ${{ secrets.HS_ENDPOINT }}
HS_USERNAME: ${{ secrets.HS_USERNAME }}
HS_PASSWORD: ${{ secrets.HS_PASSWORD }}
run: |
sed -i 's|"charisma_protected"|"charisma"|' src/rcapi/config/config.yaml
poetry run pytest
build:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: test
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
submodules: recursive
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]
with:
cosign-release: 'v2.4.0'
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/[email protected]
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.description=RamanChada 2 API service
org.opencontainers.image.licenses=MIT
org.opencontainers.image.title=ramanchada-api
org.opencontainers.image.url=https://github.com/h2020charisma/ramanchada-api/blob/main/README.md
org.opencontainers.image.vendor=IDEAconsult
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/develop' }}
type=raw,value=stable,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/[email protected]
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: github.event_name != 'pull_request'
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}