Skip to content

ops: don't run actions on draft PRs #56

ops: don't run actions on draft PRs

ops: don't run actions on draft PRs #56

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/checkout@v4.1.7
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v5.2.0
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/cache@v4.0.2
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/install-poetry@v1.4.1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load the cached dependencies
id: cached-deps
uses: actions/cache@v4.0.2
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/checkout@v4.1.7
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/cosign-installer@v3.6.0
with:
cosign-release: 'v2.4.0'
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3.6.1
# 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/login-action@v3.3.0
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/metadata-action@v5.5.1
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/build-push-action@v6.7.0
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}